3D to 2D

Hi,

Is it possible to get the 2D coordonate on screen where un point (x,y,z) will be draw ?

Thanks ^^

multiplying the point by the modelview and projection matrices should work

that’s a bit complicated :wink:

the function is

GLdouble objX, objY, objZ;
GLdouble mm[16], pm[16];
GLint vp[4];
GLdouble winX, winY, winZ;

glGetDoublev(GL_MODELVIEW_MATRIX, mm);
glGetDoublev(GL_PROJECTION_MATRIX, pm);
glGetIntegerv(GL_VIEWPORT, vp);

gluProject(objX, objY, objZ, mm, pm, vp, &winX, &winY, &winZ);

objX/objY/objZ are the real world coordinates, model/proj/view are the current modelview/projection/viewport matrices, you get the window coordinates back in winX/winY/winZ. winZ is a normalized z-buffer value. concerning winY- for opengl, winY = 0 is at the bottom of the window, but for X11 (and i think windows as well) winY = 0 is at the top of the window. you have to consider that when you get window events.