Sign in to follow this  

GL Font Position

This topic is 4750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
When drawing text on screen use the ortho mode, just like drawing sprites.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this