I am trying to determine the location on a sphere where the mouse is clicked (in world coordinates).

I am able to get the mouse X and Y (of course), but I am having a lot of trouble getting the screen Z value.

I am trying to determine the z-value of a pixel using glReadPixels(…GL_DEPTH_COMPONENT…), but the only return value I get (for ANY x,y) is 1.0.

Here is my code (MFC):

```
GLdouble modelView[16];
GLdouble projection[16];
GLint viewport[4];
GLdouble sx, sy, sz;
glGetDoublev (GL_MODELVIEW_MATRIX, modelView);
glGetDoublev (GL_PROJECTION_MATRIX, projection);
glGetIntegerv(GL_VIEWPORT, viewport);
CRect rect;
CMapView: [img]http://www.opengl.org/discussion_boards/ubb/tongue.gif[/img]MapView->GetClientRect(&rect);
GLdouble x = mouse_x;
GLdouble y = rect.Height() - mouse_y;
GLfloat pixel = 0;
glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT, &pixel);
gluUnProject(x, y, z, modelView, projection, viewport, &sx, &sy, &sz);
```

Thanks for any help!