PDA

View Full Version : order of objects in scene



Hystaspes
09-06-2010, 09:29 AM
hey guys,

when i create and place object "A" for example at (0.0, 0.0, 0.0) and "B" at (0.0, 0.0, -10.0) the second object (B) "appears" to be in front of the first object (A) when the camera is at (0.0,0.0,+50.0) looking at -Z which is wrong because A is in front of B; but when the camera is looking from (+50.0,0.0,0.0) to -X, "A" is correctly located in front of "B".

when i change the order of creating A and B (with same coordinates as above), everything appears the way it should be but i know it shouldnt be like this. any ideas what could have gone wrong in my initialization?? is there anything that i should enable or disable?

NeXEkho
09-06-2010, 09:30 AM
Are you using glEnable( GL_DEPTH_TEST ); and are you sure you've asked for a depth buffer when initialising your context? Both are required to sort the objects correctly.

Hystaspes
09-06-2010, 10:07 AM
thanks a lot. glEnable(GL_DEPTH_TEST) fixed it.

BionicBytes
09-07-2010, 05:34 AM
remember to also set glDepthFunc to a value which makes sense for you. Usually you can use GL_LESS or GL_LEQUAL. The exact choice depends upon what you're trying to achieve.