Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling depth test causes nothing at all to appear

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:

enter image description here

(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?

like image 796
johnbakers Avatar asked Mar 11 '13 07:03

johnbakers


People also ask

How do I enable depth testing in OpenGL?

If a fragment shader would write to its depth value, early depth testing is impossible; OpenGL won't be able to figure out the depth value beforehand. Depth testing is disabled by default so to enable depth testing we need to enable it with the GL_DEPTH_TEST option: glEnable (GL_DEPTH_TEST);

Why depth test after fragment shader?

The Depth Test is a per-sample processing operation performed after the Fragment Shader (and sometimes before). The Fragment's output depth value may be tested against the depth of the sample being written to. If the test fails, the fragment is discarded.

What is depth buffer in OpenGL?

A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in 3D space from a particular perspective. Depth buffers are an aid to rendering a scene to ensure that the correct polygons properly occlude other polygons.

What is depthtest?

Depth Testing is a testing technique in which feature of a product is tested in full detail. Each of the feature is tested exhaustively during the integration phase and the defects are logged, are captured across all parameters, functional and non functional.


1 Answers

When using GL_DEPTH_TEST,

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

like image 175
D-rk Avatar answered Sep 27 '22 20:09

D-rk