PDA

View Full Version : Bitmap Font Color



jqweezy
04-15-2008, 02:40 PM
Hello,

I currently have a program that prints to the screen using the bitmap font technique. On the bitmap the background is black and the characters are white. Because of this I can enable blending, call glBlendFunc(GL_ONE, GL_ONE) and do a glColor4f(...) to print in any color I choose. This works fine.

The problem arises when I add a background texture and then try to print to the screen. I can no longer print in the color I want. For example, I add the background texture, then do a glColor4f(1.0f,0.0f,0.0f,1.0f) (since I want red text) then do a call to my print function. The text prints, however, it's not red, it's more a light red, a pinkish red if you will. I'm not sure if the problem has to do with my texture environment or my blending function.

Here's some code:
[CODE]
bool Font::RenderScene()
{
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
DrawQuad(-1.0f,-1.0f,1.0f,1.0f,textures[0]); //background texture

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f); //red text
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);
arial->Print(-0.9f, 0.6f, "Hello World!");

return true;
}

[/B][/QUOTE]

again, the color of the text works if i don't add the background texture. however, when i do add the background texture, the color is always lighter than its suppose to be. Any ideas? Thank in advance.

Regards,
JQ

ZbuffeR
04-15-2008, 02:52 PM
put glDisable(GL_TEXTURE_2D); just before drawing the text.

jqweezy
04-15-2008, 02:56 PM
Disable textures? The text itself is a texture. The characters are just parts of a bitmap image.

-NiCo-
04-16-2008, 03:57 AM
Shouldn't your blending function be something like
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR)
?

jqweezy
04-16-2008, 08:01 AM
I've tried this blend function, however its not quite what i want. The letters are the color i want, however the background for the texture (black) appears, and I don't want that. Which is why I was using GL_ONE, GL_ONE. Can you think of anything else I can try? Oh, I am using OpenGL ES 1.1.

Regards,
JQ

ZbuffeR
04-16-2008, 08:43 AM
Well you did not tell us everything :-)

If you have alpha you have to take it in account. Try with glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

jqweezy
04-16-2008, 09:20 AM
Well originally my bitmap font image was a simple RGB image, no alpha. However, after mindless time wasting I realized that I could just use imagemagik and make the black background transparent:

convert oldimage -transparent black newimage

With the background now gone I can simply use transparency...and Viola!

So your right, I didn't tell you everything, but thats because I was not even taking alpha into account.

Thanks -NiCo- and ZbuffeR for your help.

Regards,
JQ