glOrtho: How can I MOVE my text

I used Nehe’s method of drawing text: a display list with all characters, then calling the characters in list with a char array.
Problem is that all my text I print is in the bottom of the screen and printed right behind the previous text.

My code that handles the drawing:

glListBase(base - 32);

  glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);


As you see I have tried to use translatef to move the text about, but it doesn’t work. Obviously I’m missing something simple.


Show us what’s inside the display list.

Name of the list is “base”, here I assemble the characters.

HFONT font;
HFONT oldfont;

base = glGenLists(96);

font = CreateFont( -size,

oldfont = (HFONT)SelectObject(hDC, font);
wglUseFontBitmaps(hDC, 32, 96, base);
SelectObject(hDC, oldfont);

I think you have to use glRasterPos* commands to control the output position rather than glTranslatef.

Yes, I’ve used glRasterPos and it seems to work. A few things though…

1: x axis is flipped. Is the ortho effected by the rotation? I have rotated my camera 180 degrees, so it seems to be logical.

2: I thought to be smart and reloaded the identity matrix to see where the x flip came from… yeh, right, no text appears AT ALL…
When i take out the rasterpos my text moves off the screen: it starts in the bottom of the screen and then quickly moves to the right. I mean, WTF?



glLoadIdentity(); // <- bad bad matrix!
//glRasterPos2f(x,y); // <- If left in, no text visible, if not, text moves off screen
glListBase(base - 32);

  glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);


[This message has been edited by Structural (edited 01-10-2003).]

RasterPos will be affected by the current modelview matrix.

The code fragment above has a mismatch with the number of PushMatrix and PopMatrix commands - does this occur in the program, or have you missed a pop off the cut/paste. Also remember that PopMatrix will pop the current matrix - you push the projection, but pop the modelview.

[This message has been edited by T (edited 01-10-2003).]

oi… hadden’t seen that, that was indeed a bug. But anyway, I took the MatrixMode out but the text keep running off the screen.
When I put in a glMatrixMode(GL_MODELVIEW) line in the end to match the pushes, followed by another pop there isn’t any change also…

I copy-pasted NEHE’s DISPLAY code from his lesson17 (texture mapped fonts) that also used the otho view, but the same things happens, while his demo works ok.

Any ideas of what the hell is going on?

If using RasterPos results in nothing visible, then that suggests that the position you are giving it is not visible. Beware that if you place the rasterpos off the left of the screen, nothing will get drawn even if you think some of the text should be visible (if rasterpos is not visible nothing gets drawn at all).

Without using RasterPos you say the text moves. I think the rasterpos will get updated when you have drawn the text to be at the end of the text, thus repeated drawing may make the text move to the right. Just a thought.

I have tried many reasonable values that should lie in my raster, but nothing… Even values between 0 and 1…

When I leave out the loadIdentity it works fine. I do see text without the loadidentity, but as soon as I put in the loadidentity it’s gone…

Could it have something to do with the last two parameters of glOrtho: the far and near clipping plane? I have tried this with different values too (originally -1 and 1) (no result ofcourse).

What is it you are trying to do? Place text just using 2D pixel coordinates or place text within a 3D scene.

I’m guessing that you are trying to place text by specifying its 2D pixel coords. In this case your projection matrix should be set with ortho (like you are doing) and your modelview matrix should be identity.

If you are using 2D commands then z will be assumed zero and it should be within the range in your ortho command.

Why do you rotate the camera 180degrees?

Originally posted by T:
[b]What is it you are trying to do? Place text just using 2D pixel coordinates or place text within a 3D scene.

Why do you rotate the camera 180degrees?[/b]

To the first point: I simply want to place some text with 2D coords. Nothing fancy really (exept that it’s the first time I try this).

To the second point: I’m making my first game to learn things like reflections: pong3D (no comments please), and I chose for that setup in the first place. I chose that the camera should look down to the positive Z.

Here’s how I do it to get the text overlayed on the scene.

gluOrtho2D(0,1,0,1); //coordinates are 0,0 to 1,1 in 2D
glColor3f(1.0f,1.0f,1.0f); //color for text
glRasterPos2f(0.02f,0.95f); //text position ( top leftish )

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
draw blah blah
rotate blah blah
translate blah blah

You rock!
Both of you

It works now with the gluOrtho2D (and with glORtho too now) and I have a slight idea of what went wrong.

What eXor did (I think) in his example code is reset the GL_PROJECTION and GL_MODELVIEW both to the origin (swith to the one, load origin, to other, load origin). I missed the part where I set the projection to the origin.

But what’s beyond me is whether the projection and modelview matrix are actually two seperate matrices? I thought there was one view matrix, and that it was overwritten if you switched.

I have to note this down:

  1. switch to projection matrix
  2. reset to origin
  3. switch to modelview matrix
  4. reset to origin

Am I correct in this?

The projection and modelview matrices are separate matrices.

Its more like:

  1. switch to projection
  2. reset to identity
  3. load a projection matrix (ortho or perspective)
  4. switch to modelview
  5. reset to identity
  6. do stuff

Oh, and remember that any matrix command always operates on the matrix you last “activated” (i.e. used in glMatrixMode).

ortho mode is 2D There is no depth ( z axis ) that’s why the text doesn’t move.

Well it looks like its moving because when you move forward it’s still there.

You can’t outrun it

Thanks people, I’m finally beginning to understand this ortho stuff, though I still have a long way to go.