How to set text color in OpenGl

I am new to openGL and wanted to set the text color, tried the glColor3f function, but it changes the drawing color, since I only want to change the text color, what should I do?

+4
source share
2 answers

You can push the current color onto the attribute stack, change the color, draw text, and then place the stack to restore the original color:

glPushAttrib(GL_CURRENT_BIT); glColor3f(...); // Draw your text glPopAttrib(); // This sets the colour back to its original value 
+4
source

glColor3f is the right call, but you should know that a color is a global state, so setting it up will do everything that is painted in that color until you change it again. So do something like this:

 glColor3f(your text color) draw text glColor3f(your normal color (white maybe)) 
+2
source

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


All Articles