Original Post
Hi
If i load a BMP file, and then use it to a sprite. How can i tell Open GL that i want to have all blue areas(a specific RGB code for that blue color) transparent?
Thanks
// Ioxunimous
int width, height; //dimensions of your bitmap
char *srcdata; //pointer to your loaded 24bit bitmap
char *tgtdata;
//Allocate memory to store the copy
tgtdata = new char [width * height * 4];
int x, y;
/*
This will convert from 24bit. If your bitmap is already
32bit, then you don''t need this step
*/
char *src = srcdata;
char *tgt = tgtdata;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
tgt [0] = src [0]; //Red
tgt [1] = src [1]; //Green
tgt [2] = src [2]; //Blue
tgt [3] = 0; //Alpha
tgt += 4;
src += 3;
}
}
//This makes everything opaque except your specified colour
int colourkey = 0x112233; //Red = 0x33, Green = 0x22, Blue = 0x11
int *data = (int *)tgtdata;
int size = width * height;
while (size--)
{
if (*data != colourkey) *data |= 0xFF000000; //Make alpha 255
++data;
}
//Load the bitmap from file
LoadFromFile
//Convert the bitmap
ConvertBitmap (my sample code)
//Create a texture
glGenTextures
glBindTexture
//Upload bitmap to texture
glTexImage2D
glBindTexture
glBegin (GL_QUADS)
glEnd
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more