Jump to content
  • Advertisement
Sign in to follow this  
cppcdr

How to change the color of a font

This topic is 4038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!