Silicon Graphics

[Prev] [TOC] [Next]



(-) OpenGL Programming Guide
(-) Chapter 7Blending, Antialiasing, and Fog
(-) Blending

The Source and Destination Factors

During blending, color values of the incoming fragment (the source) are combined with the color values of the corresponding currently stored pixel (the destination) in a two-stage process. First, you specify how to compute source and destination factors. These factors are RGBA quadruplets that are multiplied by each component of the R, G, B, and A values in the source and destination, respectively. Then, the corresponding components in the two sets of RGBA quadruplets are added. To show this mathematically, let the source and destination blending factors be (Sr, Sg, Sb, Sa) and (Dr, Dg, Db, Da), respectively, and the RGBA values of the source and destination be indicated with a subscript of s or d. Then, the final, blended RGBA values are given by

(RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa)

Each component of this quadruplet is eventually clamped to [0,1].

Now let's look at how the source and destination blending factors are generated. You use glBlendFunc() to supply two constants: one that specifies how the source factor should be computed, and one that indicates how the destination factor should be computed. Also, to have blending take effect, you need to enable it:

glEnable(GL_BLEND); 

Use glDisable() with GL_BLEND to disable blending. Also, note that using the constants GL_ONE (source) and GL_ZERO (destination) gives the same results as when blending is disabled; these values are the default. void glBlendFunc(GLenum sfactor, GLenum dfactor)

Controls how color values in the fragment being processed (the source) are combined with those already stored in the framebuffer (the destination). The argument sfactor indicates how to compute a source blending factor; dfactor indicates how to compute a destination blending factor. The possible values for these arguments are explained in Table 7-1 . The blend factors are assumed to lie in the range [0,1]; after the color values in the source and destination are combined, they're clamped to the range [0,1].

In Table 7-1 , the RGBA values of the source and destination are indicated with the subscripts s and d, respectively. Also, division of an RGBA quadruplet by a scalar means dividing each component by that value. Similarly, subtraction of quadruplets means subtracting them componentwise. The Relevant Factor column indicates whether the corresponding constant can be used to specify the source or destination blend factor.

ConstantRelevant FactorComputed Blend Factor

GL_ZERO

source or destination

(0, 0, 0, 0)

GL_ONE

source or destination

(1, 1, 1, 1)

GL_DST_COLOR

source

(Rd, Gd, Bd, Ad)

GL_SRC_COLOR

destination

(Rs, Gs, Bs, As)

GL_ONE_MINUS_DST_COLOR

source

(1, 1, 1, 1)-(Rd, Gd, Bd, Ad)

GL_ONE_MINUS_SRC_COLOR

destination

(1, 1, 1, 1)-(Rs, Gs, Bs, As)

GL_SRC_ALPHA

source or destination

(As, As, As, As)

GL_ONE_MINUS_SRC_ALPH A

source or destination

(1, 1, 1, 1)-(As, As, As, As)

GL_DST_ALPHA

source or destination

(Ad, Ad, Ad, Ad)

GL_ONE_MINUS_DST_ALPH A

source or destination

(1, 1, 1, 1)-(Ad, Ad, Ad, Ad)

GL_SRC_ALPHA_SATURATE

source

(f, f, f, 1); f=min(As, 1-Ad)

Table 7-1 : Source and Destination Blending Factors



[Prev] [TOC] [Next]

OpenGL Programming Guide


Maintained by Maintainer: Send e-mail to .htm">name@address.