Getting Coordinates of points on Sphere

I’m trying to calculate the real world coordinates of a point on a sphere with texture map, from the coordinates of a mouse click.

I have experimented with gluUnproject but I seem to be getting nonsense for output!
I’m not really sure how to use glDepthRange() to get the z coordinates - I’ve tried using glReadPixel to get this but I always seem to get the same value wherever I click the mouse.

Any help would be greatly appreciated!

[This message has been edited by gevans2000 (edited 11-19-2002).]

As far as I remember equeation is as follows: x^2+y^2+z^2=R^2 so if you have x,y & of course you know R then it’s just the math you need

real world as in screen coords? If you want screen coords use gluunproject, if you want the x,y,z then use gluproject with the mouse x, y.

I have used gluUnpoject and I’m getting the z value from glReadPixels. This always seems to give the same value though. I’ve read somewhere that if the near clip frame is to close to the camera position then glReadpixels can be inaccurate - any ideas how close it means. At the moment my sphere has radius 1.0 and my camera is at (0.0,0.0,3.0) with the near clip frame 1.0 away from the camera. Is this too close? Could this cause the z value read from glReadPixels to always be the same (very small) number?