[ Previous | Next | Contents | Glossary | Home | Search ]
OpenGL 1.1 for AIX: Reference Manual

glBlendFunc Subroutine


Specifies pixel arithmetic.


OpenGL C bindings library: libGL.a

C Syntax

void glBlendFunc(GLenum SourceFactor, GLenum DestinationFactor)


SourceFactor Specifies how the RGBA source-blending factors are computed. Thirteen symbolic constants are accepted: GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, and GL_SRC_ALPHA_SATURATE. These symbolic constants are defined in the Description section. The initial value is GL_ONE.
DestinationFactor Specifies how the RGBA destination-blending factors are computed. Twelve symbolic constants are accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA and GL_ONE_MINUS_DST_ALPHA. These symbolic constants are defined in the Description section. The initial value is GL_ZERO.


In RGB mode, pixels can be drawn using a function that blends the incoming (source) red, green, blue, and alpha (RGBA) values with the RGBA values that are already in the frame buffer (the destination values). By default, blending is disabled. Use the glEnable and glDisable subroutines with argument GL_BLEND to enable and disable blending.

When blending is enabled, glBlendFunc and glBlendEquationEXT determine the blending operation. SourceFactor and DestinationFactor specify the scaling rules used for scaling the source and destination color components, respectively. Each rule defines four scale factors, one each for red, green, blue, and alpha. The rules are described in the table below.

In the table and in subsequent equations, source color components are referred to as:

(Rs, Gs, Bs, As)

Destination color components are referred to as:

(Rd, Gd, Bd, Ad)

They are understood to have integer values between 0 (zero) and:

(kR, kG, kB, kA)


(kc = 2mc - 1)
(m R, m G, m B, m A)

represents the number of RGBA bit planes.

Source scale factors are referred to as:

(s R, s G, s B, s A)

Destination scale factors are referred to as:

(d R, d G, d B, d A)

The scale factors:

(fR, fG, fB, fA)

represent either source or destination factors. All scale factors have the range [0,1].

Parameter (fR, fG, fB, fA)
GL_ZERO (0, 0, 0, 0 )
GL_ONE ( 1, 1, 1, 1 )
GL_SRC_COLOR (Rs/kR, Gs/kG, Bs/kB, As/kA )
GL_ONE_MINUS_SRC_COLOR (1, 1, 1, 1 ) - (Rs/kR, Gs/kG, Bs/kB, As/kA )
GL_DST_COLOR (Rd/kR, Gd/kG, Bd/kB, Ad/kA )
GL_ONE_MINUS_DST_COLOR (1, 1, 1, 1 ) - (Rd/kR, Gd/kG, Bd/kB, Ad/kA )
GL_SRC_ALPHA (As/kA, As/kA, As/kA, As/kA )
GL_ONE_MINUS_SRC_ALPHA (1, 1, 1, 1 ) - (As/kA, As/kA, As/kA, As/kA )
GL_DST_ALPHA (Ad/kA, Ad/kA, Ad/kA, Ad/kA )
GL_ONE_MINUS_DST_ALPHA (1, 1, 1, 1 ) - (Ad/kA, Ad/kA, Ad/kA, Ad/kA)
                          (i, i, i, 1)

i = min (As, kA - Ad )/kA

To determine the blended RGBA values of a pixel when drawing in RGB mode, the system uses the following equations:

Rd = min (kR, RssR + RddR)
Gd = min (kG, GssG + GddG)
Bd = min (kB, BssB + BddB)
Ad = min (kA, AssA + AddA)

Blending combines corresponding source and destination color components according to the blending operation specified by GL_BLEND_EQUATION_EXT. The blending operations are:

                          min(Cs x sC+Cd x dC,kC)
                          max(Cs x sC-Cd x dC,0)
                          max(Cd x dC-Cs x sC,0)
GL_MIN_EXT min(Cs, Cd)
GL_MAX_EXT max(Cs, Cd)

where C is the relevant color component (R, G, B, or A), Cs and Cd are the source and destination color components, respectively, sC and sD are the source and destination scale factors, respectively, and Lop is one of 16 bitwise operators specified by glLogicOp.

Despite the apparent precision of the preceding equations, blending arithmetic is not exactly specified, because blending operates with imprecise integer color values. However, a blend factor that should be equal to 1 is guaranteed not to modify its multiplicand, and a blend factor equal to 0 reduces its multiplicand to 0. Thus, for example, when SourceFactor is GL_SRC_ALPHA, DestinationFactor is GL_ONE_MINUS_SRC_ALPHA, and As is equal to kA, the equations reduce to simple replacement:

Rd = Rs
Gd = Gs
Rd = Bs
Ad = As


Incoming (source) alpha is correctly thought of as a material opacity, ranging from 1.0 (KA), representing complete opacity, to 0.0 (0), representing complete transparency.

When more than one color buffer is enabled for drawing, blending is done separately for each enabled buffer, using for destination color the contents of that buffer. (See the glDrawBuffer subroutine.)

Blending affects only RGB rendering. It is ignored by color index renderers.


GL_INVALID_ENUM Either SourceFactor or DestinationFactor is set to an unaccepted value.
GL_INVALID_OPERATION The glBlendFunc subroutine is called between a call to glBegin and the corresponding call to glEnd.

Associated Gets

Associated gets for the glBlendFunc subroutine are as follows. (See the glGet subroutine for more information.)


glIsEnabled with argument GL_BLEND


Transparency is best implemented using a blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest. Note that this transparency calculation does not require the presence of alpha bit planes in the frame buffer.

The blend function operation (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is also useful for rendering antialiased points and lines in arbitrary order.

Polygon antialiasing is optimized using a blend function (GL_SRC_ALPHA_SATURATE, GL_ONE) with polygons sorted from nearest to farthest. (See the glEnable or glDisable subroutine and the GL_POLYGON_SMOOTH argument for information on polygon antialiasing.) Destination alpha bit planes, which must be present for this blend function to operate correctly, store the accumulated coverage.


/usr/include/GL/gl.h Contains C language constants, variable type definitions, and ANSI function prototypes for OpenGL.

Related Information

The glAlphaFunc subroutine, glBegin or glEnd subroutine, glClear subroutine, glDrawBuffer subroutine, glEnable or Disable subroutine, glLogicOp subroutine, glStencilFunc subroutine.

OpenGL Overview.

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