In OpenGL, I display a simple model. When I enable the depth buffer,
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
If the other answer does not work, Try what user886079 mentioned in a comment
If the above doesn't work, check your near plane in the gluPerspective, glFrustum, or glOrtho function. Depth buffering doesn't seem to work if it is set to 0.
I had tried almost everything but could not solve the overlapping issue. I had put the near value 0.0f. I changed it to 0.01f and the results now are how it needed to be.
Did you make sure you clear the depth buffer?
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
^^^^^^^^^^^^^^^^^^^
If the following answers above do not work try the following:
GL_CULL_FACE
enabled check the winding order of your model's vertices. (LH)
vs (RH)
. GL_DEPTH_TEST
is enabled; then check the planes to your frustum against your model view projection matrix along with the camera's position & view direction.GL_BLEND
is enabled; check the rendering order of your objects in comparison to the z-buffer
.