Jump to content
  • Advertisement
Sign in to follow this  
WilyCoder

OpenGL Text color?

This topic is 4822 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

I am having some trouble with drawing text in OpenGL. I've gotten it to render the text, but color changes have no effect. The color is stuck on black, and no calls are able to change the color.
glPushMatrix();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glRasterPos3f(-2.0f,0.0f,-10.0f);
glPushAttrib(GL_LIST_BIT);
glListBase(Win32Object.Base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
glPopMatrix();

I can see the text when there is a white object behind the text. Any ideas on why the color won't change? I am able to change the color for other parts of rendering....

Share this post


Link to post
Share on other sites
Advertisement
Here's the snippet right before the text rendering code:


glDisable( GL_POINT_SPRITE_ARB );
glDisable( GL_DEPTH_TEST );
glDisable( GL_BLEND );
glDisable( GL_TEXTURE_2D);




<stumped> ive gone through multiple tutorials, including nehe, but to no avail...

Share this post


Link to post
Share on other sites
Quote:
Original post by WilyCoder
glDisable( GL_POINT_SPRITE_ARB );
glDisable( GL_DEPTH_TEST );
glDisable( GL_BLEND );
glDisable( GL_TEXTURE_2D);
Make sure lighting is disabled as well.

Share this post


Link to post
Share on other sites
Try this:

  1. Disable texturing before rendering the text

  2. Set the color for the text

  3. Draw text

  4. Reenable texturing



Example:

// Stores the color and texture state before the text rendering
glPushAttrib(GL_CURRENT_BIT | GL_TEXTURE_BIT);
glDisable(GL_TEXTURE_2D);
glColor3f( 1.0f, 0.0f, 0.0f);

// Render your text here

// Restores the color and texture state back to what it was before
glPopAttrib();

Share this post


Link to post
Share on other sites
I've disabled all render calls, save the text rendering. Here's the entire render code, sans glBegin() etc....



glDisable( GL_POINT_SPRITE_ARB );
glDisable( GL_DEPTH_TEST );
glDisable( GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor3f(1.0f, 1.0f, 1.0f);
glPushMatrix();
glColor3f(1.0f, 1.0f, 1.0f);
glRasterPos3f(-2.0f,0.0f,-10.0f);
glPushAttrib(GL_LIST_BIT);
glListBase(Win32Object.Base - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
glPopMatrix();





Note that my clear color is black. When I draw a white triangle behind my text, I can see that the text is indeed black.

Share this post


Link to post
Share on other sites
you are calling glColor3f within glBegin() and glEnd(), which will keep it from doing anything, I believe. Position it before you draw the text, and it should work. I had the same problem awhile ago - kind of non-intuitive, I guess :)

Share this post


Link to post
Share on other sites
Quote:
Original post by silverphyre673
you are calling glColor3f within glBegin() and glEnd(), which will keep it from doing anything, I believe. Position it before you draw the text, and it should work. I had the same problem awhile ago - kind of non-intuitive, I guess :)



I'm not sure that matters, IIRC you can call glColor3fs inside a glBegin/End statement because you can change the color each of a primitives vertices, However, I dont knwo about using it with text.

Share this post


Link to post
Share on other sites
Make sure texturing is disabled on _all_ texture units (if you use more than one in your program.)
Check glGetError() to see OpenGL has any problems to report.

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!