Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: glClearDepth

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    3

    glClearDepth

    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?

    Thanks,
    Flurite

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    800
    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.
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    3
    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?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    3
    I was referring to mobeen saying:

    Now the incoming pixels depth value will be compared to 1.

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    In reality, the actual depth values won't be 1.0 when you call glClear. http://www.opengl.org/wiki/Common_Mi...ffer_Precision

    Unless if you have a floating point format depth buffer.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •