How can I reverse a GLTranslate. Example:
if glTranslate is called before rendering text to the screen, how can I figure out the position of that text if glTranslate weren't used?
The text is rendered to the screen like this:
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, 7681)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, 34168)
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, 768)
glColor4ub(0, 0, 0, 255)
glTranslatef(330, 190, 0)
glCallList(3)
That code above renders text on the screen. I want to figure out the position of that text in 2D with the current Modelview and Projection view.
I just want to figure out how to Untranslate it or figure out how the translation is applied. I tried:
bool WTS(GLfloat &X, GLfloat &Y, Vector3D World)
{
GLint VP[4];
GLdouble S[3];
GLdouble MV[16];
GLdouble PM[16];
glGetIntegerv(GL_VIEWPORT, VP);
glGetDoublev(GL_MODELVIEW_MATRIX, MV);
glGetDoublev(GL_PROJECTION_MATRIX, PM);
if(gluProject(World.X, World.Y, World.Z, MV, PV, ViewPort, &S[0], &S[1], &S[2]) == GL_TRUE)
{
X = S[0];
Y = VP[3] - S[1];
return true;
}
return false;
}
and then drawing my copy text at the X, Y returned. Instead it renders at a different position rather than on top of the text that used glTranslatef.
How can I get the correct X, Y?