Sign in to follow this  
Crypter

OpenGL font rendering problem

Recommended Posts

Hello everyone, I have been having an issue with setting the color of our fonts. I am using wglUseFontBitmaps to create the characters in a display list and can render the characters without problems. However I cannot seem to be able to change the color of the displayed text... Here is my rendering routine. If texturing is enabled, font is whatever the last color that was used. If its disabled, all characters are white (always white) except the first character rendered - it, too, is the color of the last color used. In both cases the glColor3i call seems to not effect anything - which is the problem.
void fontWGL::render ( std::string str, point2d<float> pos, color col ) {

	//! set position
	glRasterPos2f (pos.x, pos.y);

	glDisable (GL_TEXTURE_2D);
	glTexEnvi (GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

	//! enable color material
	glEnable(GL_COLOR_MATERIAL);

	//! font always white? (except 1st character)
	glColor3i (0,0,0);

	//! set base character to 0
	glPushAttrib(GL_LIST_BIT);
	glListBase (baseDisplayList - 32);

	//! renders display list
	glCallLists(str.length(), GL_UNSIGNED_BYTE, str.c_str() );
	glPopAttrib ();

	//! disable color material
//	glDisable(GL_COLOR_MATERIAL);
}
Any and all suggestions are greatly appreciated [smile]

Share this post


Link to post
Share on other sites
The current color and the current raster color are two different things. The current raster color is only updated with the current color, when RasterPos is called.

So set the color before RasterPos.

Share this post


Link to post
Share on other sites
Hello szecs,

Thank you for your response - that fixed it :) ...However the first character in the output string is never being changed. ie, calling glColor3f sets the color for all characters except the first...

Any more suggestions are greatly appreciated [smile]

Share this post


Link to post
Share on other sites
Why do you glEnable(GL_COLOR_MATERIAL) ?
And why don't you glDisable(GL_LIGHTING) ?

Apart from that: I have no freakin' idea how can the first letter be rendered in a different way than the others.

Did you try different texts? (Okay, a very stupid question)

Share this post


Link to post
Share on other sites
Hello again,

Moving the call to disable GL_TEXTURE_2D before glColor3f fixes that issue.. Everything is working as expected now. Thank you for your help!

As of current, lighting is already disabled. I suppose I will need to disable it though when rendering the text. Thank you for the suggestion.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this