How to change the color of a font

Started by
3 comments, last by Kalidor 16 years, 9 months ago
Hi, I have created a font manager class and I am struggling on how to set the color of the text. I discovered that to change the color of the text, I had to do: glBegin(GL_TRIANGLES); glColor3f(1.0f, 0.0f, 1.0f); glEnd(); glRasterPos2f(0, 0.5); g_pFontManager->PrintText(g_fontID[0], "Testing"); For some reason, without putting the glColor3f in glBegin and glEnd, the text coes out white... but when in the glBegin and glEnd, like in the code, it works. Why does it do that and how is the correct way to do it? Thanks in advance!
Advertisement
Do you have texturing enabled when you call your fonts?

You don't want texturing enabled if you are using the glColor3f().

call

if(glIsEnabled(GL_TEXTURE_2D))
glDisabled(GL_TEXTURE_2D);

What happens is if you have no color data before you render the text, the color will be replaced with your glClearColor() which I am guessing is set to white?

Without more code I am only guessing here.
The texturing is disabled.

Here is the font code from the font manager.

glColor3f (clrText.r, clrText.g, clrText.b);

SelectObject(m_pCore->GethDC(), m_pFonts[id]);
wglUseFontBitmaps(m_pCore->GethDC(), 32, 96, m_pFontList[id]);

glPushAttrib(GL_LIST_BIT);
glListBase(m_pFontList[id] - 32);

glCallLists(strlen(finalMessage), GL_UNSIGNED_BYTE, finalMessage);
glPopAttrib();

The glColor3f inside the font manager does not change the color of the font, but the one that is called just before calling PrintText (in my other post) does change the color, but only in between the glBegin and glEnd. If it is not between glBegin and glEnd, nothing happens.

glClearColor is set to black.
Ok, I found it. glRasterPos must be called after setting the color. I was setting the color after setting the position so it was not working.

I understand the problem, but not the reason for it. Could someone explain why opengl does this?

Thanks
Quote:Original post by cppcdr
Ok, I found it. glRasterPos must be called after setting the color. I was setting the color after setting the position so it was not working.

I understand the problem, but not the reason for it. Could someone explain why opengl does this?

Thanks
Read #11 in Avoiding 16 Common OpenGL Pitfalls.

This topic is closed to new replies.

Advertisement