How to Set text color in OpenGl

放肆的年华 提交于 2020-01-04 04:31:06

问题


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?


回答1:


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



回答2:


glColor3f is the correct call, but you must be aware that color is a global state, so setting it will make everything be drawn 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))


来源:https://stackoverflow.com/questions/3255663/how-to-set-text-color-in-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!