Color keys in OpenGL

Started by
7 comments, last by BradDaBug 22 years ago
Is there a way to make a specific color completely transparent? I see plenty about alpha blending, but nothing about specific colors being transparent.
I like the DARK layout!
Advertisement
It''s not supported by the hardware. You''ll have to fake it by an alpha mask or using regcoms.
Well, how do I do that?
I like the DARK layout!
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
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.
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?
I like the DARK layout!
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?
I like the DARK layout!
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.
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!
I like the DARK layout!

This topic is closed to new replies.

Advertisement