Skip to main content
gamedev.net
🔒 Locked

transparency

Started by k0d3rk1dd33 Nov 13, 2004 at 2:28 PM 3 replies 500+ views
Original Post
k0d3rk1dd33
k0d3rk1dd33
I'm trying to do billboarding and I want the black part of my bmp texture to be transparent. right now i have.... glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER,0.0f); but that makes the whole thing somewhat transparent, when I tried glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), none of it was transparent.. what parameters do I need to pass to glBlendFunc? Thanks a lot
stroma
stroma
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);

this will(should) make your bitmaps black parts transparent.
+-+-+-+-+-STR
stroma
stroma
are you using tga or bmp file? i am using bmp and works ok. if you use tga maybe the image alpha channel disabled? and try to use: glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); i dont know if it effects...
+-+-+-+-+-STR
zedzeek
zedzeek
>>this will(should) make your bitmaps black parts transparent.<<

no it wont, u also need a bit more,
what u need to do is during the image loading phase check each pixel to see if its black if it is set that pixels alpha to 0.0 else set it to 1.0. and then u can do

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.0f);
stroma
stroma
oh i see, i thought he made this part.
ok so you should use someting like this to load bitmap dara:

unsigned char *LoadBitmapFileWithAlpha(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
unsigned char *bitmapImage = LoadBitmapFile(filename, bitmapInfoHeader); //load a bitmap file normally
unsigned char *bitmapWithAlpha = (unsigned char *)malloc(bitmapInfoHeader->biSizeImage * 4 / 3);

if (bitmapImage == NULL || bitmapWithAlpha == NULL)
return NULL;

// loop bitmap data
for (unsigned int src = 0, dst = 0; src < bitmapInfoHeader->biSizeImage; src +=3, dst +=4)
{
// if the pixel is black, set the alpha to 0. Otherwise, set it to 255.
if (bitmapImage[src] == 0 && bitmapImage[src+1] == 0 && bitmapImage[src+2] == 0)
bitmapWithAlpha[dst+3] = 0;
else
bitmapWithAlpha[dst+3] = 0xFF;

// copy pixel data over
bitmapWithAlpha[dst] = bitmapImage[src];
bitmapWithAlpha[dst+1] = bitmapImage[src+1];
bitmapWithAlpha[dst+2] = bitmapImage[src+2];
}

free(bitmapImage);

return bitmapWithAlpha;
} // end LoadBitmapFileWithAlpha()

i hope it helps...
+-+-+-+-+-STR

Topic Locked

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

Sign in to reply to this topic.