Advertisement

GL Font Position

Started by December 13, 2004 02:56 PM
6 comments, last by Enigma 19 years, 11 months ago
Is it possible to move around a 3d world and still have the font in a certain position in the screen? Every time I transate or rotate the screen, the text either moves to the left, right up or down.
DrawScene

Resetmatrix

Drawfont
Advertisement
I probably shouldn't post an answer to this question as my forays into 3d programming have been *ahem* less than fruitful, but there's gotta be a way to draw an overlay on what you're rendering..or maybe make a texture that's transparent except for the text that spins with the camera?

Someone who knows what the hell is really up will likely come to your rescue =) But if any of what I posted helps your thinking, I am very very glad.
When drawing text on screen use the ortho mode, just like drawing sprites.
I could use ortho, but it look that realistic as gluLookAt. I wanted create a 3d world and move around it, and on the left of the screen I wanted to display the current location of the screen, is that possible with gluLookAt ?
You can use more than one type of projective transform per frame no problem. Do this and it will work:

1) Render 3d scene normally

2) Set current modelview matrix to identity

3) Setup an ortho projection (usually ppl limit the z values to -1 to 1)

4) Draw 2d stuff (like font) with depth test set to always pass

And that's all there is to it. You will always see the font rendered exactly like you want it no matter what direction your 3d scene is looking. That's thanks to setting the modelview matrix to identity.


-SirKnight
Advertisement
How would I do that, some thing like this?

int DrawGLScene(GLvoid){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();        glColor3f(...);        gluLookAt ( ...); //Render Screen               glLoadIdentity();        glOrtho(...);        glColor3f(...);        glRasterPos2f(...);        glPrint("OpenGL Text");	return TRUE;}
Close, but glOrtho must be called on the projection matrix, not the modelview matrix. You want something more like:
int DrawGLScene(GLvoid){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();        glColor3f(...);        gluLookAt ( ...); //Render Screen               glMatrixMode(GL_PROJECTION);        glPushMatrix(); // save 3d projection matrix        glLoadIdentity();        glOrtho(...);        glMatrixMode(GL_MODELVIEW);        glLoadIdentity();        glColor3f(...);        glRasterPos2f(...);// uncomment following line if you want your text to always appear on top of any models etc. you display.//        glDisable(GL_DEPTH_TEST);        glPrint("OpenGL Text");// uncomment this line too to reenable the depth test for the next iteration of the rendering loop//        glEnable(GL_DEPTH_TEST);        glMatrixMode(GL_PROJECTION);        glPopMatrix(); // restore 3d projection matrix for next iteration of the rendering loop        glMatrixMode(GL_MODELVIEW);	return TRUE;}


Enigma

This topic is closed to new replies.

Advertisement