View Full Version : how to get z coordinate from the screen

07-29-2002, 08:19 AM
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 ?

07-29-2002, 09:03 AM
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.

07-29-2002, 08:50 PM
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.

07-30-2002, 01:03 AM

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).]