PDA

View Full Version : transparency question



BennUK
01-19-2004, 09:37 AM
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)

Omaha
01-19-2004, 11:43 AM
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.

BennUK
01-20-2004, 02:10 AM
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).

ZbuffeR
01-20-2004, 02:59 AM
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);

nexusone
01-20-2004, 05:12 AM
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).

01-21-2004, 10:50 AM
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.

nexusone
01-21-2004, 02:02 PM
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.

BennUK
01-22-2004, 06:59 AM
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 http://www.opengl.org/discussion_boards/ubb/redface.gif) Cheers.

BennUK