Finding pixel value from point given in 3D

Hi,
I’m new to this group and this may have been asked and answered many times.

Given a point (x,y,z) in space, how can you determine what it’s pixel value will be on the screen in opengl? That is, is there a function that will somehow return its pixel position?

Thanks,
Bob

  

GLdouble   x, y, z;
GLdouble   mm[16], pm[16];
GLint      vp[4];
GLdouble   wx, wy, wz;

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

gluProject(x, y, z, mm, pm, vp, &wx, &wy, &wz) 

first you get the current modelview-/projection-/viewport-matrices, then you use gluProject with the real coordinates (x, y, z). the window coordinates are returned in (wx, wy, wz).

ATTENTION: for opengl, window coordinates wx=0, wy=0 are the BOTTOM left corner of the window, NOT the top left.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.