PDA

View Full Version : transparency!



thasadams
05-25-2003, 02:53 PM
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!

Omaha
05-25-2003, 02:55 PM
Could you be more specific? Maybe you don't have the right blending factors set? Maybe your alpha values are incorrect?

thasadams
05-25-2003, 03:00 PM
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.

thasadams
05-25-2003, 03:06 PM
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.

V-man
05-26-2003, 04:32 AM
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);

thasadams
05-26-2003, 10:36 AM
How would I set the alpha value in a .bmp texture?

foniks
05-26-2003, 10:37 PM
As far as I know, .bmp's do not support an alpha channel, you need to use a 32 bit TGA image.

morecraf
05-27-2003, 04:54 AM
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