GUIEnvironment addImage() quesion.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

GUIEnvironment addImage() quesion.

Post by neil_123 »

Hi,

I wanted to display an image using GUIEnvironment, so basically what I did was,

- Created a texture

- called gui_env->addImage() function.

This works perfectly.

But my question is, this method always draws the whole image/texture, is there any way I can draw only selected rectangular region from the source image (SDL anyone?).

Here is the code I used,

Code: Select all



//
//
// g++ -I/home/laeeq/irrl/irrlicht-1.7.1/include -L/home/laeeq/irrl/irrlicht-1.7.1/lib/Linux  gui_2.cc  -lIrrlicht -lGL -lXxf86vm -lXext -lX11
//
//


#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


int main()
{
	IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600));

	if (device == 0)
        {
          printf("%s:%u Unable to create device\n", __FILE__, __LINE__);
          return 1;
	}
	else
          printf("%s:%u Device created\n", __FILE__, __LINE__);
	

	IVideoDriver* driver = device->getVideoDriver();
	IGUIEnvironment* env = device->getGUIEnvironment();

	
	// ITexture* images = driver->getTexture("/home/laeeq/irrl/irrlicht-1.7.1/media/fireball.bmp");
	// ITexture* images = driver->getTexture("/home/laeeq/multi_media/frames/pwr_2.bmp");
	ITexture* images = driver->getTexture("/home/laeeq/multi_media/frames/non_pwr_2.bmp");

	env->addImage(images, position2d<int>(10,10));
	
	while(device->run() && driver)
	{
		if (device->isWindowActive())
		{
			driver->beginScene(true, true, video::SColor(255,120,102,136));

		        env->drawAll();
				
			driver->endScene();
		}
	}

	device->drop();

	return 0;
}


Best regrards.
Metalero
Posts: 14
Joined: Tue Sep 07, 2010 4:02 pm

Post by Metalero »

You should use driver->draw2DImage() instead, it has 3 (or 4) overloads, and one of them alows you to set the src rect, and the dst rect (and you can add a per vertex color)
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

Post by neil_123 »

Well, in fact I started with driver->draw2DImage(), but I realized that this function lacks "persistance". It was suggested to me that I should use

gui->addImage() function instead.

Please see

http://irrlicht.sourceforge.net/phpBB2 ... ighlight=

Looks like I have come to a full circle.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

For GUI elements, you just have to call addSomething once, before the render loop. Then, each call to env->drawAll() will render the element (if visible). For drawSomething methods, you have to call those each time *inside* the render loop. If you don't call the method, it won't be visible in that frame. So both methods can lead to persistent rendering, it simply works differently.
neil_123
Posts: 67
Joined: Wed Apr 07, 2010 8:50 pm

Post by neil_123 »

hybrid, you hit the nail right on the head.

That's exactly my question, I want draw a portion of an image(or texture) without having to draw it again & again inside the render loop.

gui->addImage() has this capability, but it does not allow a portion of the image to be displayed, it displays the whole image.

so,

want persistance: whole image gets displayed.

want to display only a part of the image: non-persistant, display it over & over again inside the render loop.


What to do in order to persistantly display only a part of the image.
Brainsaw
Posts: 1183
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

Maybe create your own GUIElement?
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, maybe I misunderstood your intention for this. But GUI elements are also rendered in each frame. You want have any advantage regarding this from a GUI element.
Post Reply