[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 Version 4.1 for AIX: Programming Concepts

Alpha Blending Modes

Alpha-blending provides a mechanism for drawing semi-transparent surfaces. With alpha-blending enabled, pixel colors in the frame buffer can be blended in varying proportion with the color of the graphics primitive being drawn. The proportion is referred to as the "transparency" or alpha value. In normal usage, the incoming color is multiplied by alpha, while the existing color is multiplied by one minus alpha, and the two are summed, to determine the resulting color. That is, the blending is linear:

FinalColor = alpha * IncomingColor + (1.0-alpha) * ExistingColor

In this normal mode of operation, the whole can never be more than the sum of the parts, because (alpha + (1.0-alpha)) equals one. Generically, the blending can be more general:

FinalColor = alpha * IncomingColor + beta * ExistingColor

This usage is more rare, and is used only for special purposes. In GL, the blending is done on a per pixel basis; that is, the blending is done for each pixel individually. Blending is supported in RGB mode only; blending in color index mode is not well supported. The blending is performed for the red, green and blue channels individually:

FinalRed = alpha * IncomingRed + beta * ExistingRed

FinalGreen = alpha * IncomingGreen + beta * ExistingGreen

FinalBlue = alpha * IncomingBlue + beta * ExistingBlue

The alpha and beta blending factors can be set with the blendfunction subroutine. For more information on this subroutine, please refer to the Graphics Technical Reference.

By its very nature, alpha-blending is order dependent. That is, drawing one semi-transparent polygon after another gives a different visual result than drawing the one before the other. In most cases, it is desirable to draw the image from back to front, drawing the closest semi-transparent polygon last. The graphics system does not automatically order or re-order graphics primitives to be in the right order when alpha-blending is enabled; it is up to the graphics program to order drawing. Note that the z-buffer, while useful for hidden surface removal, does not actually provide any ordering. That is, if a more distant polygon is drawn after a closer, semi-transparent polygon, that more distant polygon does not automatically appear behind the semi-transparent polygon.

An example program illustrating alpha-blending can be found in the /usr/lpp/GL/examples file.

For information on specifying the function to be used for alpha blending, see the blendfunction subroutine.

For information on setting the current color in RGB mode, see the c subroutine.

For information on specifying RGBA color with a single packed 32-bit integer, see the cpack subroutine.

For information on defining a new material, light, or lighting model, see the lmdef subroutine.


[ Previous | Next | Contents | Glossary | Home | Search ]