Next | Prev | Up | Top | Contents | Index

The Constant Color Blending Extension

The standard blending feature allows you to blend source and destination pixels. The constant color blending extension, EXT_blend_color, enhances this capability by defining a constant color that you can include in blending equations.

Constant color blending allows you to specify input source with constant alpha that is not 1 without actually specifying the alpha for each pixel. Alternatively, when working with visuals that have no alpha, you can use the blend color for constant alpha. This also allows you to modify a whole incoming source by blending with a constant color (which is faster than clearing to that color). In effect, the image looks as if it is viewed through colored glasses.


Using Constant Colors for Blending

To use a constant color for blending, follow these steps:

  1. Call glBlendColorEXT() to specify the blending color:

    void glBlendColorEXT( GLclampf red, GLclampf green, GLclampf blue,

    GLclampf alpha )

    The four parameters are clamped to the range [0,1] before being stored. The default value for the constant blending color is (0,0,0,0).

  2. Call glBlendFunc() to specify the blending function, using one of the tokens listed in Table 7-2 as source or destination factor, or both.

    Blending Factors Defined by the Blend Color Extension
    ConstantComputed Blend Factor
    GL_CONSTANT_COLOR_EXT(Rc, Gc, Bc, Ac)
    GL_ONE_MINUS_CONSTANT_COLOR_EXT(1, 1, 1, 1) - (Rc, Gc, Bc, Ac)
    GL_CONSTANT_ALPHA_EXT(Ac, Ac, Ac, Ac)
    GL_ONE_MINUS_CONSTANT_ALPHA_EXT(1, 1, 1, 1) - (Ac, Ac, Ac, Ac)

    Rc, Gc, Bc, and Ac are the four components of the constant blending color. These blend factors are already in the range [0,1].

    You can, for example, fade between two images by drawing both images with Alpha and 1-Alpha as Alpha goes from 1 to 0, as in the following code fragment:

    glBlendFunc(GL_ONE_MINUS_CONSTANT_COLOR_EXT, GL_CONSTANT_COLOR_EXT);

    for (alpha = 0.0; alpha <= 1.0; alpha += 1.0/16.0) {

    glClear(GL_COLOR_BUFFER_BIT);

    glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, image0);

    glEnable(GL_BLEND);

    glBlendColorEXT(alpha, alpha, alpha, alpha);

    glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, image1);

    glDisable(GL_BLEND);

    glXSwapBuffers(display, window);

    }


New Functions

glBlendColorEXT().


Next | Prev | Up | Top | Contents | Index