How to get the depth value on the other side

I rendered a model from the viewpoint of the light. The depth buffer contains many 1.0s except the places where my model lies. It is understandable, because the depth of the background is infinite, thus should be 1.

Now, I want to get the depth value of the points on the other side. I inserted the following statement in my code


glDepthFunc(GL_GREATER);

This time, the value in the depth buffer are all 1.0.

My explanation for this is that if OpenGL renders the background first, then the depth buffer will be filled with 1.0, obviously, all the points in the model has a depth value that is less than 1.0, so they cannot pass the depth test.

Am I right? How to get the depth value on the invisible side?

Try glClearDepth(0.0); glDepthFunc(GL_GREATER), clear and render models.

Simple, render the back faces into the depth buffer. Done.

This method works fine for me. Thank you very much.

Do you mean using


glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);

No. That’s culling the back faces. Rendering the back faces means culling the front faces.