View Full Version : transparency!
05-25-2003, 03: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!
05-25-2003, 03:55 PM
Could you be more specific? Maybe you don't have the right blending factors set? Maybe your alpha values are incorrect?
05-25-2003, 04: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.
05-25-2003, 04:06 PM
Ive tried this approach
glColor4f (1.0f, 1.0f, 1.0f, 0.3f);
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.
05-26-2003, 05: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
05-26-2003, 11:36 AM
How would I set the alpha value in a .bmp texture?
05-26-2003, 11:37 PM
As far as I know, .bmp's do not support an alpha channel, you need to use a 32 bit TGA image.
05-27-2003, 05: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
infoheader.alpha_data[j + 3] = 0;
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!
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.