Advertisement

blending+transparecy

Started by September 27, 2001 03:08 PM
2 comments, last by CoderTCD 23 years, 4 months ago
I want to blend a texture but only the non black pixels. The black pixels won''t be drawn but the nonblack ones will be blended with the previous pixels on screen. How can I do it?
By previuos pixels are you referring to a previous frame or just things already drawn on the screen by the time you''re drawing the object in question?

I''ll assume the latter. The question is, how do you want you pixels blended? There are many ways -- that''s what the glBlendFunc() is for.

If you''re trying to do anything at all fancy -- you''re likely gonna need a 4 channel texture (RGBA). Your alpha channel will be the "mask" to determine how pixels get used. This way, you can completely discount pixels that you wish to by affecting their corresponding alpha.

So what blend effect are you going for?
Advertisement
I know what I want to do but I don''t know which parameter to use with glblendfunc. Do you now a good website or tutorial that explain glblendfunc (with pictures prefered). I read helpand some articles about this but I still don''t understand well.
Usually, for transparency, the proper blending function is:

glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

With your non-black pixels having an alpha value of 1.0 (255) and your black pixels having an alpha value of 0.0 (0, duh you''ll be able to mask out those pesky black pixels.

The problem is, that if you are using the depth buffer, you''ll get drawing artifacts where, for example, if you''re drawing front to back, nothing will be drawn behind the "black" pixels. To fix this, you need to use the glAlphaFunc() function.

As an example, say, you want to discard fragments (pixels) that have an alpha value other than 1.0. You call glAlphaFunc thusly:

glAlphaFunc (GL_EQUAL, 1.0);

This means that fragments will be drawn if the alpha value is EQUAL to 1.0. You can use the other OpenGL comparison operators to achieve different affects. Oh, and don''t forget to glEnable (GL_ALPHA_TEST)

Hope this helps!

Mark Grocki
Lead Developer
2Real Entertainment
http://www.2realentertainment.com
Mark Grocki

This topic is closed to new replies.

Advertisement