transparency question

Hi people,
Can anyone tell me if there is a name for the type of transparency I am using in a game I am working on?

When drawing the textures I am using GlBlend at the start which makes all parts of the image that are black transparent. Is there a specific name for this and is it a good way to make tex’s transparent.

Thanx in advance for any replies :o)

Sounds like you’re using

glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);

A special name for it? “Color key” comes to mind.

Is it a good way? If it does what you need it to do, then yes.

Thanx, what I don’t understand though, is why does it make the black transparent? Would I be able to change it so that it made another colour transparent like, say, pink. This way I would avoid making colours transparent which shouldn’t be (as black is a comon colour in my scene).

PLEASE, BennUK, do not double post.

What is your glBlendFunc ?

Instead of trying to do color keying, it will be easier to use alpha channel. Set the alpha to 1.0 for opaque parts, and 0.0 for transparent ones.
Then, you can activate alpha testing with glEnable(GL_ALPHA_TEST) and use glAlphaFunc(GL_GREATER,0.5f) to mask out the transparent parts.

If you really need blending (for smoother edges or semi-transparent parts) , activate blending and use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

That is the problem with using a color to create a transparent area, what do you do when you want to use that color.

Some older games used this color key type of transparentcy.

But a more improve way, is to use a transparentcy mask, this way the mask dictakes what areas of the image are transparent. This way you free you all your colors for use in your image.

nehe.gamedev.net has a tutor on this type of image transparentcy using the Alpha channel as the mask, I think it is tutor 32.

Originally posted by BennUK:
Thanx, what I don’t understand though, is why does it make the black transparent? Would I be able to change it so that it made another colour transparent like, say, pink. This way I would avoid making colours transparent which shouldn’t be (as black is a comon colour in my scene).

if you are using texture loading code from the nehe tutorials, here is some code to use transparent colors without masking:

char* Image= new char [width by height by 4]

for every pixel
int i = (y * width+x) * 4;
int i2 = (i >> 2) * 3;
Image[i] = data[I2]
Image[I+1] = data[I2+1]
Image[I+2] = data[I2+2]
if(Image[i] == whatever transp. red value
Image[I+1] == blue
Image[I+2] == green)
Image[I+3] == 0;
else its 255

then put CCImage as last parameter in glTexImage2D

I hope this helps, cause its superior to masking in every way.

Really don’t see that, I would say very little diffrence in the whole scheme of things.

Ether create a mask at time of creating the image, or during loading.

Big diffrence is that with your way you lose the use of one color. I guess now not as big of deal as when you only had 16 or 256 colors!!!

Originally posted by Avenger:

I hope this helps, cause its superior to masking in every way.

Thanks for all that guys, I think it will be best for me to work through the nehe masking tutorial and gt to grips with rendering this way if it superior ) Cheers.

BennUK