z-buffer not drawing objects in the right order


I’ve got a problem concerning the drawing of multiple objects together. When I draw them they do not utilise the z-buffer and therefore objects behind are drawn on top of objects in from. How can I get rid of this? Do I have to manually figure out when the objects are to be drawn?



With ‘standard’ not transparent objects there’s no need to sort them if using zbuffer.
Make sure that you use the right depth func.

Are you using Linux and Glut? I noticed that with that combination, I needed to add GLUT_DEPTH to the list of options for glutInitDisplayMode()

If that’s not the problem, be sure you have depth test enabled with glEnable(GL_DEPTH_TEST);

You will also want to be sure that you clear out the depth buffer when you clear the scene by doing glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Hope that helps…

Try using glEnable(GL_DEPTH_FUNC) like the above post states. Then set your depth buffer function to glDepthFunc(GL_LESS)
This will tell the z-buffer test function not to draw a face if its z coordinate is less than the current value.
Hope this helps

A correction; In the above post, glEnable(GL_DEPTH_FUNC) should be glEnable(GL_DEPTH_TEST)
oops hehe