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 7 of 7

Thread: Warning : Readpixel depth component value

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2003
    Location
    Belgium
    Posts
    7

    Warning : Readpixel depth component value

    Something I just noticed :

    // Gives INCORRECT Z value
    GLdouble l_dZ;
    glReadPixels(a_iX, l_iY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &l_dZ);

    // Gives CORRECT Z value
    GLfloat l_fZ;
    glReadPixels(a_iX, l_iY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &l_fZ);

    So always use GLfloat for reading the depth buffer if you want correct values.

  2. #2
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Warning : Readpixel depth component value

    That should be pretty obvious. Of course you can't pass a pointer to a double and tell it to pass a float and expect to get a correct result.

  3. #3
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Warning : Readpixel depth component value

    Exactly, try specifying a GL_DOUBLE for a double type not a GL_FLOAT. That pointer is a void so there's no concept of intrinsic type other than what you specify in the type token, like GL_FLOAT. That type is the destination type not the source type, OpenGL already knows the source type. There is no function overloading here, OpenGL is a C interface, not C++ and it matters in this respect.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2003
    Location
    Belgium
    Posts
    7

    Re: Warning : Readpixel depth component value

    I just wanted to emphasise this problem.
    This mistake is made in several examples I found on the web.

    This could save some people a lot of debugging / posting time.

    NOTE : GL_DOUBLE is an invalid enumerant for the glReadPixels function, for reading the Z buffer only GL_FLOAT is valid !

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2003
    Location
    Belgium
    Posts
    7

    Re: Warning : Readpixel depth component value

    Ofcourse it would be cool to have a 64bit Z buffer !

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Warning : Readpixel depth component value

    If everything was in 64 float, then it would make sense, but the graphics card does a significant number of operations in 32 bit float, and the rest is integer or bytes.
    ------------------------------
    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);

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Sep 2000
    Location
    California
    Posts
    550

    Re: Warning : Readpixel depth component value

    Whoa, a 64bit Z buffer would ROCK!

Posting Permissions

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