View Full Version : z-buffer not drawing objects in the right order

04-23-2001, 08:51 AM

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?



04-23-2001, 09:30 AM
With 'standard' not transparent objects there's no need to sort them if using zbuffer.
Make sure that you use the right depth func.

04-23-2001, 12:21 PM
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...

04-23-2001, 11:11 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

04-23-2001, 11:13 PM
A correction; In the above post, glEnable(GL_DEPTH_FUNC) should be glEnable(GL_DEPTH_TEST)
oops hehe