transparency!

I want to take an image, blend it a bit so it looks more transparent, and draw it onto the screen. I can get it to look transparent, but I CANT GET IT TO BLEND WITH THE BACKGROUND, since part of it is white, and I do not want that to show!

Could you be more specific? Maybe you don’t have the right blending factors set? Maybe your alpha values are incorrect?

I have an image that is part black part white. I have looked at a previous post, and can’t seem to get it to work like that. What I want to do is blend that image so that the white parts of it blend with the background and the black parts are transparent.

Ive tried this approach

glColor4f (1.0f, 1.0f, 1.0f, 0.3f);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Then I bind the texture normally and draw the polygon. It is transparent, but the white parts of it still show, which is what I do not want to happen.

If that’s all you want, then just set the alpha value in your texture to 0 for white and 1 for black.
Then you upload this with glTexImage2D or whatever you are using.
Set the texture environment to GL_MODULATE.

You have to enable blending and maybe have
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

How would I set the alpha value in a .bmp texture?

As far as I know, .bmp’s do not support an alpha channel, you need to use a 32 bit TGA image.

To add an Alpha channel to the bmp file, I think you are going to have to change the bmp image to a RGBA image when you load it up in your code. Take the image data and just add an alpha channel:
// For each pixel copy the RGB buffer to a new RGBA buffer
infoheader.alpha_data[j] = infoheader.data[i];
infoheader.alpha_data[j + 1] = infoheader.data[i + 1];
infoheader.alpha_data[j + 2] = infoheader.data[i + 2];
// Do we use display this pixel?
if((infoheader.alpha_data[j] == transparent.red) && (infoheader.alph
a_data[j + 1] == transparent.green) && (infoheader.alpha_data[j + 2] == transpar
ent.blue)){
infoheader.alpha_data[j + 3] = 0;
}
else{
infoheader.alpha_data[j + 3] = 255;
}

So, you will not display pixels with the alpha_data[j + 3] value of 0
and you will display (using full alpha) everything else.

You will also need to experiment with
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
and other parameters to get exactly what you want.
And be sure to use
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA… when you finish defining your texture.

I hope this helps you!

Seth