map 3d point to 2d screen coordinates manually


i wrote a function to map 3d(x,y,z) points to 2d screen coordinates manually by 'glGet’ting the modelview,projection matrices (by import ing TransformVertices() in DirectX VB sample to OpenGL)but does not work correct.
Do you have one?

Thanks in advance for your interest.

// Perspective to window coords
v’ = ModelViewM * v3d (eye-space transform)
v’ = ProjM * v’ (clip-space transform)
v’.xy = v’.xy/v’.w (perspective divide)
v’.x = (v’.x + 1)*windowWidth/2 (window transform)
v’.y = (v’.y + 1)*windowHeight/2
v2d = v’.xy