GUI objects seemingly z-ordered at random

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
dart_theg
Posts: 68
Joined: Sun Dec 29, 2024 3:13 am

GUI objects seemingly z-ordered at random

Post by dart_theg »

I am creating simple GUI objects for a simple HUD, but I find that sometimes objects order themselves out of order of creation instead of in the order I created them in, with some appearing on top of ones I created after them. This seems to just happen whenever it wants. Is there a concrete fix to this? I'm on Irrlicht 1.8.5.
CuteAlien
Admin
Posts: 9971
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GUI objects seemingly z-ordered at random

Post by CuteAlien »

Main order is parents drawn before children (so children are on top). And children should be drawn in the order in which they are added (so last one added ends up on top). There are functions like bringToFront/sendToBack to change it, but unless you call those the order of creating is the drawing order. If that is not the case then there is something suspicous going on. I mean you can look at "virtual void draw()" function in IGUIElement.h - it's pretty trivial - just looping over the children.

edit: Maybe you draw custom ui elements? Those need to have IGUIElement::draw(); as last line for this to work
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
dart_theg
Posts: 68
Joined: Sun Dec 29, 2024 3:13 am

Re: GUI objects seemingly z-ordered at random

Post by dart_theg »

Hm. I'm just using the basic Irrlicht elements, I have a button created after I create an Image and sometimes the button appears behind the Image and vice versa.
CuteAlien
Admin
Posts: 9971
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: GUI objects seemingly z-ordered at random

Post by CuteAlien »

Please show an example then. I'm pretty certain this is a bug in your code. All Irrlicht does is go over the list in a simple loop. And that list isn't re-ordered anywhere. Edit: Maybe you do set a custom 2d material? In that case you have be careful not to change the ZBuffer, ZWriteEnable flags.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply