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?
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);
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.
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.
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.
When using GL_DEPTH_TEST,
glClear(GL_DEPTH_BUFFER_BIT) has to be called before rendering so that the depth buffer is initialized correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With