Jump to content
  • Advertisement
Sign in to follow this  
JPerry

OpenGL Color Key working not the way I expect

This topic is 3565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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) Free Image Hosting at www.ImageShack.us<br /><br />QuickPost Quickpost this image to Myspace, Digg, Facebook, and others! Thanks

Share this post


Link to post
Share on other sites
Advertisement
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)?

Share this post


Link to post
Share on other sites
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)

Free Image Hosting at www.ImageShack.us<br /><br />QuickPost 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.

Share this post


Link to post
Share on other sites
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 )

Share this post


Link to post
Share on other sites
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.

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!