Reputation: 24770
I have a depth buffer and am rendering a cone on the screen. It works, but then I realized I had forgotten the standard enabling of depth testing, and when I turned it on, now nothing appears at all.
I only have this one object, a cone, in my scene, so nothing else is in front of it.
The depth buffer is setup fine:
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER,
m_depthRenderbuffer);
The I bind the render buffer:
glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffer);
Then I render the cone:
(My experiments with this messy cone are the subject of another question I shall ask shortly).
But, as soon as I add this next line after creating the depth buffer and binding the render buffer:
glEnable(GL_DEPTH_TEST)
...then my cone magically disappears. There is nothing, not even a little dot, on the screen.
Why would that be?
Upvotes: 3
Views: 3060
Reputation: 1
I've faced the same issue and the reason was that glDepthMask
was set to GL_FALSE
before calling glClear(GL_DEPTH_BUFFER_BIT)
.
So in addition to the above comments/answers just make sure that glDepthMask
is set to GL_TRUE
before clearing the depth buffer.
Upvotes: 0
Reputation: 31
As fuzzyTew brought up in the comments (Apr 26, 2017), some people may have the issue where the near clipping distance was set to 0. I set this to 0.01 * cam_distance and everything was just dandy.
[...] My near clipping distance was set to 0. Turns out it needs to be positive. – fuzzyTew Apr 26 '17 at 20:25
Upvotes: 2
Reputation: 5919
When using GL_DEPTH_TEST,
glClear(GL_DEPTH_BUFFER_BIT) has to be called before rendering so that the depth buffer is initialized correctly.
Upvotes: 10