Depth Testing

Started by
2 comments, last by Kurioes 19 years, 5 months ago
Hey all, I'm trying to get depth testing for a very simple OpenGL program working (it simply draws a figure on the window using cubes of different colours). The code works fine without the z-buffer enabled (the figure is drawn correctly), but as soon as I call glEnable(GL_DEPTH_TEST) I simply get a black screen. I've set up my pixel format (i'm using the standard windows api to create my window) so that it has 32bits for the depth buffer : PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_TYPE_RGBA, 32, 0,0,0,0,0,0, 0, 0, 0, 0,0,0,0, 32, 0, 0, PFD_MAIN_PLANE, 0, 0,0,0}; And every time my rendering function executes, I call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); To clear the screen and the depth buffer. Any idea why I would be getting the black screen when I enable depth testing (which I want to enable so that I can animate my figure). The orientation of the polygons shouldn't matter, should it?
Advertisement
You can change whether the orientation matters or not. you could try glDisable-ing GL_CULL_FACE. You can change the winding mode by calling glCullFace with GL_FRONT, GL_BACK or GL_FRONT_AND_BACK as a parameter.

Did you call glDepthFunc(GL_LEQUAL)?

If you set up a stencil buffer try clearing the stencil buffer as well and check the stencil test function (glStencilFunc).

... did any of those do it?

EDIT: I don't think you've set up the stencil buffer, after looking at the pixel format part, so you can just ignore what I said about that. You might also want to check if your far clipping plane isn't too close.
Quote:Original post by Kurioes
Did you call glDepthFunc(GL_LEQUAL)?


Fantastic!! That did the trick, thank you very much :)
Glad I could help!

This topic is closed to new replies.

Advertisement