trouble with hidden surface removal

I have tried enabling the depth buffer and it doesn’t work. I’ve tried enabling GL_CULL, and it won’t compile. I want to be able to change perspective and not see stuff that I shouldn’t be able to see. Any suggestions?

When you say that you enable the depth buffer and it doesn’t work, are you getting an error, or it doesn’t seem to do anything. If it doesn’t seem to do anything make sure you are calling glClear with GL_DEPTH_BUFFER_BIT ored in before each rendering pass. As for the issue with GL_CULL try enabling GL_CULL_FACE and then calling glCullFace with parameter set to the face(s) to be culled.

But first try the glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) and any other buffer bits you need to clear at the start of each scene.

void Display(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
glPolygonMode(GL_FRONT, GL_FILL);

glColor4f(1.0f, 1.0f, 1.0f);

RenderMyPolygonsPlease();

glutSwapBuffer();
}

The depth buffer doesn’t seem to be doing anything. I tried clearing the depth buffer bit and it doesn’t work. I also tried oliii’s approach and it didn’t work, either. I can still see right through the wall…
Thanks, though.

If you’re using Linux, you might not have a depth buffer by default. If you are creating your window using glut, be sure to include GLUT_DEPTH as one of the options in glutInitDisplayMode.

[This message has been edited by Deiussum (edited 03-13-2003).]

Well, I can assure you the z-buffer DOES work, so it must be something in your code that breaks it.

Why dont you post the source code instead of letting us guessing what may be wrong?

Hi,

Just a wild guess, you set your near clip plane to 0. This makes the far/near ratio infinitely large, which destroys the depth buffer precision. If this is the case, just make your znear 0.1 or some other small (but not too small) positive value.

-Ilkka