Get screen coordinates of a transformed point

I’d need to access the screen coordinates of a 3d point after the MODELVIEW and PROJECTION transformations… is it possible?

My problem is that I have several text strings to display and they ar attached to 3d points, I am using font bitmaps.
The problem is that different text strings are often justapposed so I’d like to compute a bounding box for each string to avoid the annoying justaposition… any suggestion?

If you want to calculate the object to screen coordinates in your program, you can use gluProject, which does exactly that.

Thanks! Sorry for the silly question but I am a beginner.
So I should do something like


GLdouble model_view[16];
glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

GLdouble projection[16];
glGetDoublev(GL_PROJECTION_MATRIX, projection);

GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

GLdouble pos3D_x, pos3D_y, pos3D_z;
gluProject(objX, objY, objZ,
	model_view, projection, viewport,
	&winX, &winY, &winZ);

Anyway what is the meaning of winZ? Since screen is flat I would expect winZ be always zero or null and have just winX and winY values

Screen depth, as stored in depth buffer, is winZ, in [0;1] range.
You may not need it, but it can be useful.

Ok thanks!

My problem now is the following…

To speed up and avoid data transfer to the graphic card memory at every frame I used a Display List where I call glRasterPos3d to attach every text string to its 3D point and then glCallLists to call the nested Display Lists for the bitmap fonts.

Then the MODELVIEW matrix can change but the Display List stays unchanged.

When I call the Display List I should be able to call gluProject to see where the text strings are going on the screen, compute the bounding box, and in case they overlap, move some of them in order to avoid the justapposition.

Yet this seems incompatible with Display Lists… or I am wrong?

Any advice is welcome!

Thanks again

If you’re using nested display lists for individual strings, you can call gluProject and gluUnproject just fine outside of them, but you’re not going to be able to use them inside another display list since the display list basically ignores the call. If you’re moving stuff around dynamically anyway, a display won’t help either way since you’re changing it.