Archived

This topic is now archived and is closed to further replies.

Blending on White Backgrounds

This topic is 5148 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 a problem with blending modes. My bitmap font resides in an image with white letters and black background, so that I can occlude the black when I draw the text. I use glBlendFunc(GL_SRC_ALPHA, GL_ONE) to get rid of the black background. I apply a colour to the font by changing the quad colour that the font characters are bound to, using glColor4fv() using 1.0 as the alpha value. However, I have a background image some of which is white. When text is drawn on top of this (no matter what colour) is does not show up. (Text is drawn in areas where black and white are present, text on the black areas displays fine, but text of white areas does not). I know it is the blending because when I turn blending off the text appears with the correct colour (albeit with the black font background - the occlusion of which was the whole point in using blending in the first place). I''m not sure if it matters but I''m drawing the background using glDrawPixels() and as mentioned the font characters are mapped on coloured quads. The background is drawn first, then I turn off depth testing to draw the font. Is there an all-encompasing solution? I''m relatively new to blending modes so I''m unsure of how best to proceed. Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
The first parameter tells OGL how to use the new colors you are drawing in the blend, and the second tells OGL how to use the colors that are already on the screen in the blend.
GL_SRC_ALPHA tells OpenGL to multiply the colors by the current alpha value, GL_ONE_MINUS_SRC_ALPHA tells it to multiply the colors by 1 minus the same aplha value. Then OpenGL adds together the two colors and puts the resault on the screen. When you use GL_ONE it multiplies the color on the screen by 1, therefor it keeps it. That way if the screen has white on it and it adds the font on it, its still white cause its as bright as the colors go.
Anyway, glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) should fix it.

Share this post


Link to post
Share on other sites
to use "GL_ONE_MINUS_SRC_ALPHA", you will have to use a image with an alpha channel for your font. if you do not want to add this into the image file (or can''t if you are using a bitmap), you can always pre-process the image when you load it and change the alpha value of all black pixels to 0.

Share this post


Link to post
Share on other sites
Thanks guys, I eventually figured it out, it is GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, like you said. I am loading TGAs using my own loader so I just exported from Photoshop with 32bit and transparency and it put in the alpha values for me, how nice Now it's just as I want, perfection.

[edited by - sckoobs on November 13, 2003 12:54:30 PM]

Share this post


Link to post
Share on other sites