I am trying to render some strings in the foreground in a OpenGL/GLUT application under MacOSX 10.7.2.
At the moment I am using this code to draw a few lines in the foreground and it works fine.
void drawForeground() { int width = 10; int height = 10; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-1, width, -1, height, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glDepthMask(GL_FALSE); glBegin(GL_LINES); //Draw the lines glEnd(); /*********************/ glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glDepthMask(GL_TRUE); } Now I would like to draw also some text. In the previous function I added this piece of code in the line where I put the asterisks:
glRasterPos2d(2,2); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, 'c'); but it didn't work. If I use the same two lines outside the drawForeground method the 'c' appears.
I already called glDisable(GL_TEXTURE_2D) and nothing changed.
May someone help me understanding my error?
Solution:
It turned out the solution to be disabling lighting using glDisable(GL_LIGHTING), reenabling it after rendering the text.
I would like to underline that the text is rendered always at the same dimension, independently from the parameters of the glOrtho call.
glOrtho()seems odd to me. Normally, I'd think you'd want it to beglOrtho(0, pixelWidth, 0, pixelHeight, -1, 1);. As it is, you're saying that your world is 11 x 11 units. It's possible that the letter is being drawn off the edge of the screen, depending on whether that(2,2)is where the baseline, ascenders or descenders go.glOrthobehave, in this case, as an implicit scaling. However, even changing it as you suggested (and usingglRasterPos2d(width/2.0,height/2.0);) , I am still unable to see any letter. Even scaling it up and down seems to have no effect.glOrtho()does - implicit scaling. It just seemed odd to try to draw an 18 point character to an 11x11 area. Other than that, what you have looks reasonable. Are there any OpenGL errors along the way?