Drawing 2D Rect behind GUI element? [resolved]

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
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Drawing 2D Rect behind GUI element? [resolved]

Post by shurijo »

Maybe I just missed it or I haven't had enough to eat today, but I can't get a 2d rectange to draw before the GUI draws. Below is my device->run() code.

If I move the draw2dRectangle to before env->drawAll() then it doesn't draw at all. I'm thinking that the GUI env clears the display then draws, so it is drawing, but I just can't see it. When I draw it after env->drawAll, then it covers my items.

Works - draws box in front/on top of GUI items

Code: Select all

driver->beginScene(true, true, irr::video::SColor(0,0,0,0));
env->drawAll();
driver->draw2DRectangle(irr::video::SColor(225,209,199,73), irr::core::rect<irr::s32>(20,175,250,450));
driver->endScene();
Doesn't Work (switching drawAll and draw2dRectangle)

Code: Select all

driver->beginScene(true, true, irr::video::SColor(0,0,0,0));
driver->draw2DRectangle(irr::video::SColor(225,209,199,73), irr::core::rect<irr::s32>(20,175,250,450));
env->drawAll();
driver->endScene();
Last edited by shurijo on Sun Feb 29, 2004 10:55 pm, edited 1 time in total.
Chev
Posts: 37
Joined: Wed Nov 19, 2003 6:15 am

Post by Chev »

The only idea I have is putting a scenemanager->drawAll(); before your env->drawAll();
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

Chev wrote:The only idea I have is putting a scenemanager->drawAll(); before your env->drawAll();
Tried inserting the smgr->drawAll() and the 2D Rect didn't draw anywhere.

Code: Select all

			
driver->beginScene(true, true, irr::video::SColor(0,0,0,0));
driver->draw2DRectangle(irr::video::SColor(125,209,199,73), irr::core::rect<irr::s32>(20,175,250,450));
device->getSceneManager()->drawAll();
env->drawAll();
driver->endScene();
Also tried ...

Code: Select all

			
driver->beginScene(true, true, irr::video::SColor(0,0,0,0));
device->getSceneManager()->drawAll();
driver->draw2DRectangle(irr::video::SColor(125,209,199,73), irr::core::rect<irr::s32>(20,175,250,450));
env->drawAll();
driver->endScene();
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

I also just experimented with IGUIElement::bringToFront(), but I couldn't get that to work either.
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

okay i'm not quite sure what you are trying to do here, is the rectangle covered by the gui items, or are you trying to create some sort of background?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

I'm trying to put the rectange behind the GUI items.

Imagine there are two 2d rectangles on screen. A blue one and a red one. Then I want to put a few GUI elements on top of each rectangle (having the rectangle behind the GUI item).
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

shurijo wrote:I'm trying to put the rectange behind the GUI items.

Imagine there are two 2d rectangles on screen. A blue one and a red one. Then I want to put a few GUI elements on top of each rectangle (having the rectangle behind the GUI item).
you could billboard a simple texture.. that would have the effect of drawing a box behind the gui elements.
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

Status update (for future people that search for forums). I figured it out...

First, I draw my background image, then my rectangles, then my GUI environment. And it works! :o

Code: Select all

driver->beginScene(true, true, irr::video::SColor(0,0,0,0));
driver->draw2DImage(imgBackground, irr::core::position2d<irr::s32>(0,0) );
driver->draw2DRectangle(irr::video::SColor(255,209,199,73), irr::core::rect<irr::s32>(20,175,250,450));
env->drawAll();
driver->endScene();
My problem was that my background image was a GUIImage, so it was getting drawn over the rectangles on the env->drawAll() event...
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

great work, i should mention here for future people that guiImage should no be used for backgrounds. In Fact draw2Dimage is a superior command for almost any use. GUIImages existed before the draw2Dimage was added to the engine (i think it was 0.4 or 0.42) so in a way i guess draw2Dimage replaces GUIImage.
Post Reply