Get 2D Coord From 3D

How can I calculate the screencoord form a 3D point using glGetFloatv(GL_PROJECTION_MATRIX, ProjectionMatrix) , glGetFloatv(GL_MODELVIEW_MATRIX, ModelviewMatrix) , glGetFloatv(GL_VIEWPORT, ModelviewMatrix) and using aspect ratio?

I know that I need to multiply ProjectionMatrix * ModelviewMatrix * Point, but I dont know how to involve the viewport and the aspect ratio. Thanks

Oops, that last one should be “glGetIntegerv( GL_VIEWPORT, viewport )”.

I know that I need to multiply ProjectionMatrix * ModelviewMatrix * Point, but I dont know how to involve the viewport and the aspect ratio. Thanks

Simple:


#include <GL/glu.h>

gluProject( x, y, z,
            modelview, projection, viewport,
            &x, &y, &z );

What this is doing isn’t rocket science. Check out the Mesa3D source for details. Code up your own if you want. Just takes (x,y,z,1) multiplies by modelview, then projection, then viewport transform.

Thx for your reply. If i do that the z coord must be 0 if verything works fine. But have an other question how does the glu function work can you give me a function which does not use any other functions that i can the how the calculation work!