How to determine actual screen coordinates for vertex?

I am implementing a tooltip feature in my Windows-based OpenGL application. Basically, I want to display come context information when the mouse is moved over one of my OpenGL objects.

My problem is: my OpenGL objects are drawn using calls to vertex3Df, where the coordinates are in world (x,y,z) coordinates. In order to show the tooltip, I need to know what those coordinates map to on the screen.

Is there a conversion function I can call, which, given a vertex3D and whatever tranformation matrices are currently in use, will give me the on-screen x-y location to which that point is mapped?


Vinay Prabhakar

Yepp, have a look at gluProject. You pass the point you want to project, the modelview- and the projection matrix, the viewport size, and it return the screen coordinate for you.

Ive looked at glUnproject.

Does it return pixel co-ordinates ie. integers? If so why are the winx, winy parameters returned floating point values?

int gluProject(
GLdouble objx,
GLdouble objy,
GLdouble objz,
const GLdouble modelMatrix[16],
const GLdouble projMatrix[16],
const GLint viewport[4],
GLdouble *winx,
GLdouble *winy,
GLdouble *winz

Relating to my previous post I am wanting to find screen pixel co-ordinates.

I am rendering my opengl scene into a 640 * 480 window. I am looping through each pixel and trying to get 3D co-ords using gluUnproject.

For some other pixels I am doing the opposite. ie I want the pixel co-ord from gluProject.

Are “windows co-ords” as described in the documenation for these 2 functions different from pixel co-ordinates? If so does anyone have a function that will translate windows co-ords to pixel co-ords (and vice versa)?