OpenGL C bindings library: libGL.a
void glBlendFunc(GLenum SourceFactor, GLenum DestinationFactor)
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)
(fR, fG, fB, fA)
represent either source or destination factors. All scale factors have the range [0,1].
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:
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.
Associated gets for the glBlendFunc subroutine are as follows. (See the glGet subroutine for more information.)
glGet with argument GL_BLEND_SRC, GL_BLEND_DST, GL_LOGIC_OP_MODE, or GL_BLEND_EQUATION_EXT.
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. |
The glAlphaFunc subroutine, glBegin or glEnd subroutine, glClear subroutine, glDrawBuffer subroutine, glEnable or Disable subroutine, glLogicOp subroutine, glStencilFunc subroutine.