View Full Version : glClearDepth
08-27-2012, 07:51 AM
I am new to OpenGL, and I am using Qt Creator as an IDE. I am wondering what the glClearDepth() function does. I do not quite understand the description on the documentary, but when I change my code "glClearDepth(1.0)" to "glClearDepth(0.0)", the polygon widget I have no longer appears. Could someone explain this function to me in simple words?
08-27-2012, 08:12 AM
glClearDepth sets the depth value in the depth buffer when the depth buffer is cleared similar to how glClearColor sets the clear color for the color buffer. When you put glClearDepth(1.0), it means that when the next glClear call is given (i.e. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);) the depth buffer will be filled with value 1. Now the incoming pixels depth value will be compared to 1. If you do not modify the depth function (glDepthFunc(...)) which defaults to GL_LESS), the incoming value will be passed when the depth is < 1. Now when you change the clear depth to 0, it is already the lowest value and thus no fragment is <0 hence no pixel is written.
1) if using glClearDepth(1) change the depth func. to GL_LESS (glDepthFunc(GL_LESS)) this will render the nearest fragment to the viewer to screen.
2) if using glClearDepth(0) change the depth func to GL_GREATER (glDepthFunc(GL_GREATER)) this will render the furthest fragment from the viewer to screen.
So it all depends on what you want to achieve.
08-27-2012, 08:34 AM
Cool, so the higher up the pixel is, the higher the depth value? Is a depth of 1 at the top of the screen and 0 at the bottom?
08-27-2012, 08:54 AM
Ehm, why do you expect the depth at a fragment to change based only on the pixel it's projected to? The values of the depth buffer are a result of rendering, not a function of pixel position.
08-27-2012, 08:58 AM
I was referring to mobeen saying:
Now the incoming pixels depth value will be compared to 1.
08-27-2012, 10:32 AM
In reality, the actual depth values won't be 1.0 when you call glClear. http://www.opengl.org/wiki/Common_Mistakes#Depth_Buffer_Precision
Unless if you have a floating point format depth buffer.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.