Search code examples
c++opengltextcolorsglut

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 as i only want to change the text color what should i do?


Solution

  • You could push the current colour onto the attribute stack, change the colour, draw the text, and then pop the stack to restore the original colour:

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