how to get z coordinate from the screen

Let’s say I’m rendering a model on the screen using z-buffer,
is there a way I can get the z coordinate of a given pixel (x,y) on the screen ?

Look for documentation on glUnproject(…) in the GLU documentation. Also do a search on this forum for ‘gluUnproject’. There have been numerous discussions about that here.

You can get the depth buffer value with an appropriate call to glReadPixels. Then you can use that z-value, together with the screen x and y to call gluUnproject.

Hi,

Take a look at this it might help: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/009293.html

Basically use glReadPixels with GL_DEPTH_COMPONENT. Just remember the depth buffer values aren’t linear! I’ve never used gluUnproject but you can do it as in the above post. Don’t know which would be quicker though.

[This message has been edited by thelamberto (edited 07-30-2002).]