Alpha blending and masking.

In my app, I currently use alpha blending, just to achieve the normal effect of translucency (glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)).

In addition, I want to do some masking. Some portions of the screen should be opaque, some translucent. So, I guess I need something like an alpha mask, but without affecting my original blending I described above.

Is there a way to achieve this with destination alpha or some other method?


Additionally, I can say that I am using orthographic projection and do some 2D only. Maybe this helps.

You can use the stencil buffer.

Yes, but is there a possibility to do this with destination alpha? Or what are example applications for destination alpha?


Try looking at Nehe Tutorials. There is a good tutorial about using of alpha mask and effect of transparency. Meaby it’s worth looking at.



I haven’t really done much alpha stuff but can’t you change the blend mode after you have drawn the stuff using the first blending mode to a different more useful one then switch back again?


Well, my problem is how do I apply the alpha mask to the image? E.g. when I first draw the whole scene (which is actually 2D only) then I could switch to a different glBlendFunc() that uses destination alpha and draw a big rectangle over the whole scene. This would apply the alpha mask.

The problem with this approach is it would lead to an effect that I do not desire. I would draw the whole scene first and then apply the alpha mask instead of applying the alpha mask everytime I draw a … well, lets call it primitive. This would be possible with the stencil buffer, I know, but can you imagine an approach using destination alpha or some other method (except stencil buffer, I actually use it for various other things)?

This would help me a lot.