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.
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?
glColor3f(rc,gc,bc);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity(); // ← bad bad matrix!
glOrtho(0,800,0,600,-1,1);
glMatrixMode(GL_MODELVIEW);
//glRasterPos2f(x,y); // ← If left in, no text visible, if not, text moves off screen
glPushAttrib(GL_LIST_BIT);
glListBase(base - 32);
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.
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.
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.
/2D OVERLAY STUFF
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,1,0,1); //coordinates are 0,0 to 1,1 in 2D
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0f,1.0f,1.0f); //color for text
glRasterPos2f(0.02f,0.95f); //text position ( top leftish )
glPrint("vPosition.x=%7.2f);
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.