PDA

View Full Version : glReadPixels



Mr.Freeze
07-08-2001, 09:13 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

Tron
07-08-2001, 11:02 PM
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 (;

Mr.Freeze
07-08-2001, 11:23 PM
I would never have come by myself on that idea, it helped a lot. Thanks

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

harsman
07-11-2001, 11:12 PM
http://web2.airmail.net/sjbaker1/love_your_z_buffer.html

Tron
07-12-2001, 02:53 AM
here u are:
http://lehrer1.rz.uni-karlsruhe.de/~za2279/misc/zbuffer.png
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 (http://lehrer1.rz.uni-karlsruhe.de/~za2279/misc/Z-Buffer.xls)

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

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