PDA

View Full Version : Very confused with transparent parts of texture?



Andy Gilbert
04-09-2010, 07:15 AM
Hi, Ive googled and googled but getting confused about how i go about this?

All im trying to do is...

Draw a quad and texture it with a texture where i want to make any black parts transparent, aswell as the quad?

So i end up with a just the remaining colored bits visible?

Thanks
Andy

Dark Photon
04-09-2010, 06:27 PM
All im trying to do is... Draw a quad and texture it with a texture where i want to make any black parts transparent, aswell as the quad?
The standard way is to assign those desired-transparent texels an alpha value of 0.0 Give the other texels an alpha value of 1.0 (i.e. 255, if you're using storing your texels unsigning unsigned char components).

Then before rendering, enable blending:


glEnable( GL_BLEND );
glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );

As an optimization, you can additionally do this:


glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_GREATER, 0.1 );
which'll just wack transparent fragments before they even get to the blend unit.

Andy Gilbert
04-10-2010, 05:29 AM
Hi, thanks for that, although its this bit im still unsure how i go about doing?

The standard way is to assign those desired-transparent texels an alpha value of 0.0 Give the other texels an alpha value of 1.0 (i.e. 255, if you're using storing your texels unsigning unsigned char components).

Does it matter or make it any easier to what image format to use? I ask becasue i noticed if i load in TGA's an transparant areas are transparent, but you can still see the quad surface underneath?

Thanks
Andy

Fugitive
04-10-2010, 12:16 PM
Basically, instead of hacing a texture map with 3 channels (R,G,B), you have one more channel (A=alpha). So, your pixel data looks like this: R,G,B,A

Usually people will load two textures from disk, one with the RGB and the other (mask) that has all the A, i.e, transparency information, then combine them into one array, and forward that as a texture to OpenGL. Then by choosing the appropriate blending function (as Dark Photon pointed out) you will get transparency.