Archived

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

BradDaBug

OpenGL Color keys in OpenGL

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