PDA

View Full Version : Blending problem



jpummill
10-25-2002, 08:57 AM
Hi All,

I am having a problem with blending.

If I load a texture (.bmp file format) that is black and white, then the white part shows up and the black part is transparent.

What I want is the black part to show up and the white part to be transparent.

I currently have glBlendFunc set to (GL_ONE, GL_SRC_ALPHA).

Can I change the blending function to get the results I want or is this all I am going to get while using .bmp's because they don't have an alpha channel???

Any help would be appreciated,
jpummill

zeckensack
10-25-2002, 10:23 AM
Strange.
Without an alpha channel in your texture, the blending function you gave shouldn't do anything ...

Are you sure that the black parts are truly transparent, or are they just invisible because you draw onto a black background?

The 'correct' blending function for your current mode of behaviour (with alpha channel) would be
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

or
glBlendFunc(GL_SRC_ALPHA,GL_ONE); //additive blending

without an alpha channel would be
glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
or
glBlendFunc(GL_SRC_COLOR,GL_ONE); //additive

To invert the thing, so that black becomes opaque and white becomes transparent, you can flip the thing around, eg

glBlendFunc(GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA);
or
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA,GL_ONE);
or
glBlendFunc(GL_ONE_MINUS_SRC_COLOR,GL_SRC_COLOR);
or
glBlendFunc(GL_ONE_MINUS_SRC_COLOR,GL_ONE);

Leyder Dylan
10-25-2002, 01:30 PM
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_BLEND);
// Draw your stuff
glDisable(GL_BLEND);