Color Key working not the way I expect
Hi gamedevers,
I'm new to game programming and I hope you guys don't mind about my stupid question. I'm really having a hard time trying to figure out how to solve this problem. I hope you can help me.
One way to enable color keying in OpenGL is creating an alpha channel on my image. Setting 0 for pixels to be ignored and 1 for colored ones. Then, using blending options.
So far so good, pixels to be ignored are just ignored. However, when two colored ones intersect, a new brigther one comes up.
That's a behaviour I wouldn't like to happen with my images.
Appers to me that DEPTH_TEST is the solution. It turns out I didn't manage to make it work properly.
Here's my image (they are brigther where they overlap)
<br /><br /> Quickpost this image to Myspace, Digg, Facebook, and others!
Thanks
What did you set your blending function to?
Also, you said "0 for pixels to be ignored and 1 for colored ones." - do you put them as floats(0.0-1.0) or as integers(0-255)?
Also, you said "0 for pixels to be ignored and 1 for colored ones." - do you put them as floats(0.0-1.0) or as integers(0-255)?
Quote:Original post by JPerry
Hi gamedevers,
I'm new to game programming and I hope you guys don't mind about my stupid question. I'm really having a hard time trying to figure out how to solve this problem. I hope you can help me.
One way to enable color keying in OpenGL is creating an alpha channel on my image. Setting 0 for pixels to be ignored and 1 for colored ones. Then, using blending options.
So far so good, pixels to be ignored are just ignored. However, when two colored ones intersect, a new brigther one comes up.
That's a behaviour I wouldn't like to happen with my images.
Appers to me that DEPTH_TEST is the solution. It turns out I didn't manage to make it work properly.
Here's my image (they are brigther where they overlap)
<br /><br /> Quickpost this image to Myspace, Digg, Facebook, and others!
Thanks
Please post your relevant rendering code between [ source ] and [ /source ] tags w/o the spaces so we can get a look at what you are actually doing.
I assume its cause u have some additive mode enabled
use something else eg GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
or if its just a colorkey like effect then dont enable blending at all
but use glEnable( GL_ALPHA_TEST );
gALPhaFunc( GL_GREATERm 0.0 )
use something else eg GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
or if its just a colorkey like effect then dont enable blending at all
but use glEnable( GL_ALPHA_TEST );
gALPhaFunc( GL_GREATERm 0.0 )
someboddy: sorry, I meant 255. They are all integers.
The root of the problem was my TexEnvF. Setting it REPLACE instead of DECAL did the trick. I found a reference on opengl superbible 4th edition.
I'm now going with only alphatest. I wonder when is alphablend more desirable than alphatest??
Thank you for all your help.
The root of the problem was my TexEnvF. Setting it REPLACE instead of DECAL did the trick. I found a reference on opengl superbible 4th edition.
Quote:If you want simple replace the color of the underlying geometry, you can specify GL_REPLACE for the environment mode. Making this change eliminates any effect on the texture from the underlying geometry.
I'm now going with only alphatest. I wonder when is alphablend more desirable than alphatest??
Thank you for all your help.
alphatest only has two results, pass + fail
blending with say GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
lets u specify how much to blend, thus results generally look a bit nicer (esp around the edges), though its slightly slower than alphatest.
one benifit with alphatest is if the fragment fails, it does get written to the depthbuffer.
blending it does even if the fragement aint visiable
blending with say GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
lets u specify how much to blend, thus results generally look a bit nicer (esp around the edges), though its slightly slower than alphatest.
one benifit with alphatest is if the fragment fails, it does get written to the depthbuffer.
blending it does even if the fragement aint visiable
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement