Enabling depth test doesn't cause anything

I have a depth buffer and am making a cone on the screen. It works, but then I realized that I had forgotten the standard inclusion of depth testing, and when I turned it on, now nothing appears at all.

I have only one object, a cone, on my stage, so there’s nothing else in front of it.

Depth buffer is configured normally:

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderbuffer); 

I bind the render buffer:

 glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffer); 

Then I put out the cone:

enter image description here

(My experiments with this dirty cone are the subject of another question that I will ask in the near future).

But, as soon as I add the following line after creating the depth buffer and binding the visualization buffer:

glEnable(GL_DEPTH_TEST)

... then my cone magically disappears. There is nothing on the screen, not even a small dot.

Why should it be?

+4
source share
1 answer

When using GL_DEPTH_TEST ,

glClear (GL_DEPTH_BUFFER_BIT) must be called before rendering so that the depth buffer is initialized correctly.

+7
source

All Articles