Advertisement

OpenGL Text

Started by January 26, 2001 09:37 AM
3 comments, last by Running_Wolf 23 years, 9 months ago
I am trying to use the tutorial about bitmapped fonts to put the FPS of my application at the bottom of the screen. But the text won''t stay at the bottom. As you move around the world the text moves also. Sometimes you can''t even see it. When the text moves it moves somewhere betweent the center of the screen and the side. Or you just can''t see it.
L.I.G. == Life Is Good
You must set the projection matrix to glOrtho2D first, draw the text, then back to 3D. This should fix it.
Advertisement
You are not obligated to set the projection matrix like this. I was faced with the same problem with my 3d engine which uses code based on NeHe's tuts for printing text.

I will post my code here so you may see your error and point to you what my error was.

unsigned int fps = frame_counter.GetFrameCount();
glLoadIdentity();
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glDisable(GL_TEXTURE_2D);
glRasterPos3f(-0.2665f, 0.195f, -0.5f);
gl.Print("FPS : %7i", fps);
glEnable(GL_TEXTURE_2D);
frame_counter.FrameFinished();

At first I had the very same problem as you did, but after I added a glLoadIdentity everything was fixed. Another error you can make with this is not to use the glTranslate3f command but rather glRasterPos3f. The thing most likely to happen is that there is glTranslatef somewhere that interferes with your position, your text is positioned right, but maybe you specify that the your view should be adjusted on the y axis, to compensate for camera direction. This throws off the text. There must not be a glTranslate command between the glLoadIdentity and the print command. But there must be a glRasterpos. One more thing maybe you need to set the projections matrix like this or something because I have some trouble rendering text above -0.5f on the z axis. But maybe this has something to do with view frustrum culling.

If you need any more help reply to this message. If you suceed with the change of projection matrix could you post some pseudo-code or code, im not familiar with changing the projection matrix.


*** EDIT : In case somebody's wondering you must disable the gl_texture2d to render things like text, lines, etc. accuratly. But you must put it back on again to have access to texture mapping.


WHO DO THEY
THINK THEY'RE
FOOLING : YOU ?



GARAL website

Edited by - Bleakcabal on January 26, 2001 1:06:53 PM
WHO DO THEYTHINK THEY'REFOOLING : YOU ?
position your text first before any transformations
eg :if u use my camera class..

glLoadIdentity()
// trnslate scale n position text
cglFont.print("Hello World!");
// do all other transformations
cglCamera.placeCamera();
RealityMonster: I had been doing that for quite a while, but have recently run into a problem when disabling Depth testing for a skybox after. Im currently looking for a better way to position text on the screen.

- Wav

This topic is closed to new replies.

Advertisement