Skip to main content
gamedev.net
🔒 Locked

Transparency?!?!?!?!?!!!

Started by Ioxunimous Oct 29, 2002 at 5:01 AM 3 replies 650+ views
Original Post
Ioxunimous
Ioxunimous
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
Kippesoep
Kippesoep
Load the bitmap into memory and convert it to be 32bit. 24bit for the colour data and 8bit alpha. Make sure that the alpha byte is 0 for the colour that you want to be transparent and 255 for the opaque sections.

Something like this:

  
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;
}


Kippesoep
Ioxunimous
Ioxunimous
Well, im not so familiar with the functions in opengl, but dont i load a bitmap with some glGenTexutures, glTexParameters etc, and then bind them to some quads? (Thats what i have done)

Where do put in all that stuff, and if i should make a function for the transparent color(to set that), how do i do?

Thanks

// Ioxunimous
Kippesoep
Kippesoep
No, that''s not loading a bitmap, that''s creating a texture. Loading a bitmap is loading the stuff from the file. Then, you should do the conversion as I specified, then you should create the texture and upload the information.


//Load the bitmap from file
LoadFromFile

//Convert the bitmap
ConvertBitmap (my sample code)

//Create a texture
glGenTextures
glBindTexture

//Upload bitmap to texture
glTexImage2D


Then, when you need to use it


glBindTexture
glBegin (GL_QUADS)
glEnd


Kippesoep

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.