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 (xOrigin, relative to the OpenGL window), viewport (yOrigin), viewport (width) and viewport (height).
- double modelview;
- double projection;
- int viewport;
- double screenX, screenY, screenZ;
- glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
- glGetDoublev(GL_PROJECTION_MATRIX, projection);
- glGetIntegerv(GL_VIEWPORT, viewport);
- //you'll probably want to put this inside a loop, to get all the model's points
- gluProject(modelPointX, modelPointY, modelPointZ,
- modelview, projection, viewport,
- &screenX, &screenY, &screenZ);
You need to login to post a comment.