View Full Version : glReadPixels

07-08-2001, 10:13 PM

I would like to get the depth information of the central pixel of my window so that I can make some smart rotations around the object which is in the middle of my screen.
I try doing it with:

GLfloat pixel[1];
glReadPixels (windowXSize/2,windowYSize/2,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,pixel);

but this doesn't work. The value of pixel doesn't change except when the object is very very close. I checked that GL_DEPTH_SCALE is 1 and GL_DEPTH_BIAS is 0.
What do I do wrong?
Thanks for your help http://www.opengl.org/discussion_boards/ubb/smile.gif

07-09-2001, 12:02 AM
i guess u use a perspective projection
probably u made the mistake to set the near clipping plane very close (e.g. 0.0001) and the far clipping plane quite far (e.g. 1000)
the depth values are NOT mapped linear between near and far (on the other hand in an ortho projection they are) so u use up 99% of the precision in the first few depth units (0.0001 - 5 or so)
for the remaining deph values (5 - 1000) there are only 1% of precision, so they almost get mapped on the same value (which will also lead to z-fighting)
moving your near clipping plane further away will help

hope that helps (;

07-09-2001, 12:23 AM
I would never have come by myself on that idea, it helped a lot. Thanks

07-11-2001, 10:40 PM
Do you maybe know in what way the depth values are mapped in a perspective view???
Is it a logarithmic function?
Thanks (^_^)

07-12-2001, 12:12 AM

07-12-2001, 03:53 AM
here u are:
far ist 100
y-axis: used up precision
x-axis: z-value
the legend shows the near-values of the different graphs

the Excel-sheet (sorry for the m$-crap) the shot was taken from:
http://www.uni-karlsruhe.de/~za2279/misc/Z-Buffer.xls (http://lehrer1.rz.uni-karlsruhe.de/~za2279/misc/Z-Buffer.xls)

[This message has been edited by Tron (edited 07-12-2001).]

07-12-2001, 05:39 PM
It's working!!! http://www.opengl.org/discussion_boards/ubb/smile.gif