Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: glReadPixels

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    Longueuil, Qc, Canada
    Posts
    5

    glReadPixels

    Hi everyone!!!

    I use glReadPixel(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z) and this function always return 1.0???

    Does anybody know why???

    Thanks a lot!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: glReadPixels

    The function returns 1, or the array is filled with 1's? It would seem very odd for the function to return 1 as it has a void return type.
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    Longueuil, Qc, Canada
    Posts
    5

    Re: glReadPixels

    After the execution of glReadPixels, z contains the value 1??? He's not supposed to return a value into 0 and 1?


    Originally posted by Deiussum:
    The function returns 1, or the array is filled with 1's? It would seem very odd for the function to return 1 as it has a void return type.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: glReadPixels

    From MSDN:
    GL_DEPTH_COMPONENT
    Depth values are read from the depth buffer. Each component is converted to floating point such that the minimum depth value maps to 0.0 and the maximum value maps to 1.0. Each component is then multiplied by GL_DEPTH_SCALE, added to GL_DEPTH_BIAS, and finally clamped to the range [0,1].
    GL_RED

    So yes, it is supposed to get set between 0 and 1. You are probably reading from a location that the depth was cleared and never had anything drawn to it to make it change the depth value.

    If I remember right, the x,y components of that are read where (0,0) is the lower left, not the upper left so you may be getting confused by that.
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: glReadPixels

    try this glClearDepth( 0.44 );
    now do your readpixels , if u get 0.44 then youre reading a pixel that hasnt had depth info written into it, ie no polygon is under the point

  6. #6
    Junior Member Newbie
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    15

    Re: glReadPixels

    Originally posted by Dagana:
    I use glReadPixel(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z) and this function always return 1.0???
    ReadPixel is doing what it is supposed to. You are reading from the screen position (x,y,1=z) so you havt to get 1 for depth always.

    Chris
    yes

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Feb 2000
    Location
    France
    Posts
    1,118

    Re: glReadPixels

    DaViper, there is no z in glReadPixels...

    Code :
    void glReadPixels(
      GLint x,         
      GLint y,         
      GLsizei width,   
      GLsizei height,  
      GLenum format,   
      GLenum type,     
      GLvoid *pixels   
    );
    If there was one, there would be no point to having such a function... It would be something like:

    Code :
    float GetZ(float X,float Y,float Z)
    {
     
      return(Z);
     
    }
    Anyway, it'd be worth trying zed's suggestion and see what happens !

    Regards.

    Eric

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: glReadPixels

    A common problem is that people forgets that OpenGL's Y-axis does not equal the window's Y-axis. OpenGL's Y-axis has it's zero in the bottom and grows upwards.

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    Longueuil, Qc, Canada
    Posts
    5

    Re: glReadPixels

    Your right Zed, I get 0.44! Why??? Maybe is because I draw only Points. My image is a mass of approximatively 250 000 points.

    I need this information because I want the user to be able to crop the image, maybe anyone got another solution?

    Originally posted by zed:
    try this glClearDepth( 0.44 );
    now do your readpixels , if u get 0.44 then youre reading a pixel that hasnt had depth info written into it, ie no polygon is under the point

  10. #10
    Intern Newbie
    Join Date
    Jul 2001
    Location
    France
    Posts
    31

    Re: glReadPixels

    I assure that I don't take you for a dummy but are you sure your depth buffer is enabled when you are drawing your scene ? (glEnable(GL_DEPTH)) And Are you sure your clear it at the beginning of each new frame ?
    Sebb

Posting Permissions

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