Posted By

waldir on 10/23/10



Versions (?)

gluProject command sequence

 / Published in: C++


This is the full sequence of commands needed to make a gluProject call to get the 2D projections of 3D points with the current scene parameters (projection, transformations, etc). Note that the coordinates are given in pixels relative to the viewport's location, not the computer screen!

If you need for further processing, you can access the viewport's dimensions by fetching viewport[0] (xOrigin, relative to the OpenGL window), viewport[1] (yOrigin), viewport[2] (width) and viewport[3] (height).

  1. double modelview[16];
  2. double projection[16];
  3. int viewport[4];
  4. double screenX, screenY, screenZ;
  6. glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
  7. glGetDoublev(GL_PROJECTION_MATRIX, projection);
  8. glGetIntegerv(GL_VIEWPORT, viewport);
  10. //you'll probably want to put this inside a loop, to get all the model's points
  11. gluProject(modelPointX, modelPointY, modelPointZ,
  12. modelview, projection, viewport,
  13. &screenX, &screenY, &screenZ);

Report this snippet  

You need to login to post a comment.