Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BradDaBug

OpenGL Color keys in OpenGL

This topic is 6025 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

Is there a way to make a specific color completely transparent? I see plenty about alpha blending, but nothing about specific colors being transparent.

Share this post


Link to post
Share on other sites
Advertisement
It''s not supported by the hardware. You''ll have to fake it by an alpha mask or using regcoms.

Share this post


Link to post
Share on other sites
search this forum for ''colourkey'' btw u cant do it in opengl but it should give the answer u want

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
You can use AlphaTest

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,GL_ZERO);

to simulate a colorkey. This is very fast
but you must have a spezial alpha channal
(GL_RGBA) because this function only draws
the texture pixel with an alpha value greater
then zero.
It is better then Alphblending because
it is much faster and you have no problem
with lightning which appears on blending
parts too.

Share this post


Link to post
Share on other sites
Here''s what I did. I used set a color key to the SDL_Surface, used SDL_DisplayFormatAlpha() to get a surface with an alpha channel with the keyed color set to alpha of 0. Then I created a texture from the alpha surface with the GL_BGRA (SDL loads bitmaps in BGR format) thing set.

it ALMOST worked. Now, instead of the color key color, I get black. Any ideas?

Share this post


Link to post
Share on other sites
I got it to work a little better. Now the color keyed color is transparent, but it leaves 1 pixel of black along the right edge of whatever it''s drawing. Like, if I''m drawing text, it makes the text look bold. like this: 0 = 0).

And ideas?

Share this post


Link to post
Share on other sites
That''s caused by the bilinear interpolation of the alpha channel. If you use an alpha-test to get it transparent, then instead of testing for > 0, test for > threshold. Threshold is a value between 0 and 254, that will cut the black border at different positions, try some values until you got a good result. Another possibility is to stay with > 0, but turn off filtering on text.

Share this post


Link to post
Share on other sites
Oh! you mean it''s smoothing it! ok. I set the texture smoothing thing from GL_LINEAR to GL_NEAREST and it fixed it.

Thanks!

Share this post


Link to post
Share on other sites

  • 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!