Reputation: 23485
Ok so I'm hooking into a game to retrieve data from it and use it. I got as far as hooking text (via CallLists).
The game uses:
glNewlist()
glBegin(GL_QUADS)
glVertex2i(....); //Stored the location of each char in the bitmap above..
glTexCoords2f(....); //Not sure what this is..
glEnd()
glEndList()
glCallList(876); //Represents a single character in the above bitmap.
glLoadIdentity(); //Resets the matrix.
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTranslatef(336, 196, 0); //Places it on screen somehow! :S? This is what I need to know.
glColor4ub(0, 0, 0, 255); //Colours the text.
LoadIdentity(); //Resets the matrix and does the next character.
glCallList(877); //Next char.
To render text to the screen. Is there a way I can figure out the coords of the text on the screen? I have access to all functions via Detours.
I'm not sure what the glTranslate did. How can I get the X and Y of the text?
I've used this to project the coords from glTranslate but it still projects it wrong. What do I pass to my WorldVector? It is just a struct with X, Y, Z. I've passed it the glTranslate coords but that doesn't work.
bool WorldToScreen(GLfloat &X, GLfloat &Y, Vector3D World, GLdouble* ModelViewMatrix, GLdouble* ProjectionMatrix)
{
GLint ViewPort[4];
GLdouble Screen[3];
glGetIntegerv(GL_VIEWPORT, ViewPort);
if(gluProject(World.X, World.Y, World.Z, ModelViewMatrix, ProjectionMatrix, ViewPort, &Screen[0], &Screen[1], &Screen[2]) == GL_TRUE)
{
X = Screen[0];
Y = ViewPort[3] - Screen[1];
return true;
}
return false;
}
Upvotes: 0
Views: 457
Reputation: 322
Here is an example of translating and calling your list in orthographic
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(336.0f, 196.0f, 0.0f);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f); //Red
glCallList(877); //Or whatever list you wish to call
At this point, you may want to have the width of the next character to write, and simply translate value to put your text directly to the right of it,
By the way, there is a great free to use library called FreeType 2 , Blizzard uses it for there games, as well as myself, the former of which gives it good credibility.
If I am still not answering your question be sure to let me know
Upvotes: 1
Reputation: 322
That really depends, if you are drawing your text in orthographic mode, whatever you pass into glTranslatef is the actual screen coordinate, where if you are in perspective mode, you will have to pass them through the transformation pipeline to get the screen coordinates, I believe the function for doing this would be in the GLU library called gluProject, where gluUnProject would bring screen coordinates to world space
translate to world position
translate to view position
divide by W (Copy of Z) to get projection coordinates
ScreenX = Px * ScreenWidth/2 + ScreenWidth/2
ScreenY = -Py * ScreenWidth/2 + ScreenWidth/2
Upvotes: 1