Sign in to follow this  

transparency

This topic is 4781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to do billboarding and I want the black part of my bmp texture to be transparent. right now i have.... <code> glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER,0.0f); </code> 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
>>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);

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

This topic is 4781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this