Advertisement

Nehe Lesson 13 glPrint()

Started by August 28, 2003 08:49 AM
7 comments, last by Chrisz 21 years, 6 months ago
Hi everyone! I use some code from Nehe´s Lesson 13. This is the codesection where i call the functions: int drawMenue() { ... glTranslatef(0.0f,0.0f,-2.0f); //Textoutput glColor3f(1.0f, 0.0f, 0.0f); //no effect... glRasterPos2f(0.8f, 0.5f); glPrint("x - %7.2f", xpos); ... } It´s written in a subfunction, which is called in DrawGLScene(). int DrawGLScene(GLvoid) { ... glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if(menu) { drawMenue(); return TRUE; } ... So far, the text ist written and everything seems ok. Except, that the glColor call doesn´t effect the color of the text at all. It is alway print in black. Are there some Environmentvariables or something else which may affect the textcolor? Thanks in advance for help! Chris [edited by - Chrisz on August 28, 2003 9:50:46 AM]
Make sure you have disabled lighting. If you have OpenGL lighting enabled then it will ignore the text colour and use the current material and normal to shade your text.

Hope that helps!

Jason
Advertisement
Thanks for your reply!

I´m trying to bring several elements from the first 15 lessons together, but lighting was never enabled to this point. To be sure, i added the line "glDisable(GL_LIGHTING);" to InitGL(), but the problem still remains.

Hoping for further ideas...
Chris

[edited by - Chrisz on August 28, 2003 10:20:00 AM]
Shure that menu is true? Have you tried to change the background color (glClearColor(blah)) to another value to see if it is printed at all?
The world isn't unpredictable. It's CHAOTIC.
Hi again!

Just for the records

...
glTranslatef(0.0f,0.0f,-2.0f);

glDisable(GL_TEXTURE_2D); // <----

glColor3f(0.8f, 0.0f, 0.0f);

glRasterPos2f(0.8f, 0.75f);
glPrint("x - %7.2f", xpos);

glRasterPos2f(0.8f, 0.71f);
glPrint("y - %7.2f", ypos);

glRasterPos2f(0.8f, 0.67f);
glPrint("z - %7.2f", zpos);

glEnable(GL_TEXTURE_2D); // <----
...

Disable Texturmapping did it...

Greetings
Chris
@ "Intamin AG"

Thanks for your reply!

Yeah, the whole menue thing did work. I drawed a Quad with a nice texture as background, so the call of drawMenue() was verified.

I don´t know what exaclty openGL does, when printing text while texturing enabled. glBindTexture() was still "active" from drawing the background. I am still new to openGL and didn´t think that textures have an effect without calling glTexCoord2f().

Greetings
Chris
Advertisement
Well, texturing is ALWAYS active and used when enabled, so as you can see, there''s your problem.
The world isn't unpredictable. It's CHAOTIC.
A good thing to remember is that OpenGL is a state machine. Once something is set, it will remain set until you change it. So in this case, texturing was enabled and since you didn't disable it, it was enabled during text drawing aswell. As for the texture cooridnate, that is a state aswell. If you don't set a new texture coordinate, the last texture coordinate will be used.

Another example is the call to glColor3f in the code you posted. You call it once before the first glPrint, and since you don't change it, the same color is used for all three calls to glPrint.

[edited by - Brother Bob on August 28, 2003 11:32:56 AM]
Hi!

Thank you both for your explanations! I have to keep the state machine architecture in mind.

This topic is closed to new replies.

Advertisement