Highlight foreground text

I am trying to display some lines in the foreground in an OpenGL / GLUT application on MacOSX 10.7.2.

I am currently using this code to draw some lines in the foreground, and it works great.

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 also like to draw some text. In the previous function, I added this piece of code to the line where I put 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, "c" will appear.
I already called glDisable(GL_TEXTURE_2D) and nothing has changed.

Can someone help me understand my mistake?

Decision:

It turned out that the solution turns off lighting using glDisable(GL_LIGHTING) , reinstalling it after rendering the text.

I would like to emphasize that the text is always displayed in one dimension regardless of the parameters of the glOrtho call.

+4
source share
1 answer

Nothing specific, but a few things to try if you haven't done it yet:

What is the color set before calling glutBitmapCharacter ()? If the drawing color is set to something that does not appear on the background, it may just look as if nothing is being drawn.

Have you tried calling glDisable (GL_TEXTURE) in addition to glDisable (GL_TEXTURE_2D)?

Are there other things, such as lighting, that you allow elsewhere in your code, and then don't turn them off before the text will affect things? When I encountered such errors in the past, it looks like they are often associated with something in an OpenGL state that is in a state that I did not expect, often because I made some changes to the state elsewhere and forgot to cancel This. I would recommend that you systematically comment on the various OpenGL calls in your code, even if they don't seem directly related, and see if characters appear. If they do, you will know what state change you need to make / undo.

+2
source

Source: https://habr.com/ru/post/1398488/


All Articles