glReadPixels

Hello,

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

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 (;

I would never have come by myself on that idea, it helped a lot. Thanks

Tron,
Do you maybe know in what way the depth values are mapped in a perspective view???
Is it a logarithmic function?
Thanks (^_^)

http://web2.airmail.net/sjbaker1/love_your_z_buffer.html

here u are:

explanation:
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

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

It’s working!!!