PDA

View Full Version : Classic Tree Billboard ( How The Hell? )



jeff_a16
11-25-2001, 11:17 AM
Alright, I have my bmp file loaded. How do I eliminate the black background of the image, but not make the tree translucent? Is there a special combination of the Blend function that will allow me to do this. Please HELP!!!

ET3D
11-25-2001, 02:32 PM
I don't understand exactly what you mean, but basically, you should set the alpha of the black pixels to zero (assuming your black is background, and no other pixels in the tree are black), leave the rest at 1, and do an alpha test when you render, so that you don't render the ones with alpha=0.

Dong Ke
11-25-2001, 05:34 PM
Maybe I have the same question with jeff_a16. But I don't know how to assign each pixel of the BMP an specific alpha value. As far as I know, BMP doesn't contain alpha channel. And, how to use the BMP to build tree billboard after setting its alpha value? I'm a little confused. Would you please put some code here? Thanx so much.

MrShoe
11-25-2001, 05:49 PM
You would need to enable Blending with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_ALPHA); and your bmp loading function should have code that gives each black coloured pixed an alpha value of 0, and all other pixels 1, this way the black coloured pixels will be transparent

MrShoe
11-25-2001, 05:50 PM
You would need to enable Blending with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_ALPHA); and your bmp loading function should have code that gives each black coloured pixed an alpha value of 0, and all other pixels 1, this way the black coloured pixels will be transparent

Dong Ke
11-25-2001, 06:13 PM
Perhaps I didn't make myself clear.
My point is: BMP file format doesn't include any alpha information. You said: '...and your bmp loading function should have code that gives each black coloured pixel an alpha value of 0, and all other pixels 1' But where should I assign the alpha value of each pixel of the BMP to?


[This message has been edited by Dong Ke (edited 11-25-2001).]

Lev
11-25-2001, 09:41 PM
Use some format that supports alpha channel, like tga. (I have a loader source on my site). Then I would advice to use alpha test, for which you need not to sort the polys in any case. For blending the polys have to be sorted in some cases (If you use GL_SRC_ALPHA, GL_SRC_ONE_MINUS_ALPHA with alpha values other than 1 and 0)

-Lev

Dong Ke
11-25-2001, 11:04 PM
Originally posted by Lev:
Use some format that supports alpha channel, like tga. (I have a loader source on my site). Then I would advice to use alpha test, for which you need not to sort the polys in any case. For blending the polys have to be sorted in some cases (If you use GL_SRC_ALPHA, GL_SRC_ONE_MINUS_ALPHA with alpha values other than 1 and 0)

-Lev

So would you please put your link to your site here?

Michalek366
11-26-2001, 03:30 AM
Originally posted by Lev:
Use some format that supports alpha channel, like tga.

Right, but he has a BMP file.

void make_alpha (char *rgb, int count, char **rgba)
{
static int trans_pix = 0x00000000;
*rgba = new char[count*4*sizeof char];
for (char *p=&rgb[count*3-3], *p2=*rgba[count*4-4]; p >= rgb; p-=3, p2-=4)
{
*p2=p[2],p2[1]=p[1],p2[2]=*p;
if ((((int&)*p) & 0x00ffffff) == 0)
p2[3] = 0;
else
p2[3] = 0xff;
}
}

should be working


[This message has been edited by Michalek366 (edited 11-26-2001).]

Bob
11-26-2001, 03:41 AM
So would you please put your link to your site here?

Why not check out his user profile (one of the four buttons above the message)?

Dong Ke
11-26-2001, 04:26 PM
Yeah I'v got it, thanx