still got trouble with that darn text

Started by
8 comments, last by Kiroke 22 years, 1 month ago
Hi!! I've tried Nehe tut 13 and it worked fine on my computer... Now, i got problems when i try to move my text on the screen using glRasterPos2f(); Here is my code glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glColor3f(1.0f, 0.0f, 0.0f); glRasterPos2f(0.0f, 0.0f); glPrint("You are dead"); glRasterPos2f(0.0f, 0.0f); glPrint("Press any key to continue"); Whenever i try to change a parameter of glRasterPos2f() by only 0.001, the text stop displaying on the screen. Thats kinda strange... Tell me if you got a clue whats going on! thx kiroke Edited by - kiroke on February 19, 2002 11:02:14 AM Edited by - kiroke on February 19, 2002 8:34:43 PM
Kirokewww.geocities.com/kiroke2
Advertisement
if I remember correctly glRasterPos() is affected by the current modelview matrix - ie. by glTranslate() commands. Try glTranslating into the screen a bit then try moving your text around

------------------------------
Baldur K
Yes OpenGL clips the raster position according to modelview and projection matrices.

If you want a pixel-aligned text, you gotta do something like :

GLint matrix_mode;
glGetIntegerv(GL_MATRIX_MODE, matrix_mode);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, (GLdouble)screen_width, 0.0, (GLdouble)screen_height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
/* draw the text here */
glRasterPos2i(text_pos_x, text_pos_y); // in screen coordinates, (0,0) is the lower-left corner of the window
glPrint(whatever_the_text);
/* end of drawing text */
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(matrix_mode);

If you don''t want pixel-aligned text, but ratio-aligned (eg in percentage of the screen), then delete the ''glOrtho'' command and the Raster Position will therefore have to range between the lower-left corner (-1,-1) and the upper-right corner (+1,+1).

Remember that if the vertex projects out of the viewing frustum, then the raster position will be set as invalid and bitmap commands (such as display lists called into glPrint) will be ignored by OpenGL.
now thx for that big post... :-)

I tried it and it worked with a couple of modifications... I understand what as going on now

thx alot!

Kiroke
Kirokewww.geocities.com/kiroke2
DOH!

I think i still got a problem here... i beg for your infinite knowledge once again :-)

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glColor3f(0.0, 1.0, 1.0);

glRasterPos2f(-0.55, 0.0);
glPrint("Kiroke''s PONG !!!");

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();


glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);

The thing I''m doing is that i disable all the annoying things, then i push the actual matrix so i dont modify it. I use loadIdentity( which i didnt understood utility in your sample code) then i switch to modelview. At the end i pop the 2 matrix...so things should be as before i think. I enable lighting and stuff then render my scene(which is not here...)

The problem is that the text is showing but the scene after never come up... I know that the code behind(its a little game) runs perfectly but i cant figure out why it doesnt get on screen.

Kiroke
Kirokewww.geocities.com/kiroke2
You''re sure, that your current matrix mode is projection, when entering your code ?

Try that:

glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);

glMatrixMode(GL_PROJECTION); <<<<---- insert that here

glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
well yeah I''m sure...but I''ve putted it anyway and it doesnt work. Thx for your help though
Kirokewww.geocities.com/kiroke2
Yann L is right, but has 50% of the answer
here is the other 50% :
put glMatrixMode(GL_MODELVIEW) *after* the code that displays the text.

...
glPrint("Kiroke''s PONG !!!");

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

glEnable(GL_LIGHTING);
...

In fact, that''s why in my sample code I got the matrix mode (via glGetIntegerv(GL_MATRIX_MODE, &matrix_mode)) and then I restored it (via glMatrixMode(matrix_mode))

I''m 99.99% sure that it''ll help
btw, you have to load identities in order to reset the matrices.
if the projection matrix and modelview matrices are identities, then the viewing frustum is defined by an orthographic projection which is a simple cube whose coordinates lie between (-1,-1,-1) and (+1,+1,+1).

In other words, reset both matrices to have a simple coordinate system.

I''d love explaining all the math stuff that is behind, but I don''t really have the time.
I''d recommend reading OpenGL specifications which explains that very well. You can find those specification at http://www.opengl.org
IT''S WORKING! I''ve read about theses matrix things (in the open GL game programming book) and I think i now understand theses things...

I really thx you all for your support

Kiroke
Kirokewww.geocities.com/kiroke2

This topic is closed to new replies.

Advertisement