gluUnproject()

I was just wondering how the gluUnproject() functions works. I want to use gluUnproject() to convert 2D screen coords to 3D world coords. So I basicly have only 2 coordinates, whilst gluUnproject requires 3.

Can somebody help me on this?
Thanx!

–> Tize

Yeah, wondering the same thing !

–> Divide

Remember that OpenGL, when projecting 3D world coordinates into 2D screen coordinates, retains the third coordinate (the z value). This allows OpenGL to do depth testing. Therefore when taking a screen point an un-projecting it back into the world, OpenGL needs to know how far away from the camera the point is (the third coordinate).

Without the third coordinate to define depth in the screen, a 2D point alone corresponds to an infinite number of points in 3D.

Hope this helps.

Yep, and you get the third coordinate from the depth buffer (use glReadPixels on the x,y position)

Kilam.