order of objects in scene

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?

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.

thanks a lot. glEnable(GL_DEPTH_TEST) fixed it.

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.