Pixel coordinates with gluPerspective

When using glOrtho2D( ), my mouse handler would return an int x, y position of the mouse click.

I could then set the pixel at that point to a particular color, etc.

I am trying 3D drawing now, with the following:

glViewport (0, 0, 500, 500);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
gluPerspective(65.0, (GLfloat) 500/ (GLfloat) 500, 1.0, 20.0);
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

Now, when i click the window with my mouse, I still get integer coordinates - but they can no longer be displayed on the window.

The problem is that the scaling has changed, so that plotting (0,0,0) is at the center of the window, and (1,0,0) is about an inch to the right of the origin - instead of just one pixel to the right.

Is there any way at all to use mouse coordinates with the perspective projection functions?

Thanks
chetty

Okay … found the answer … gluUnProject( )

Now I need to make it work in my program (!)

Thanks to past posters who ran into the same issue :slight_smile: