fglBlendFunc(3G)
fglBlendFunc - specify pixel arithmetic
As shipped in IRIX 6.5. First release of IRIX 6.5.
NAME fglBlendFunc - specify pixel arithmetic FORTRAN SPECIFICATION SUBROUTINE fglBlendFunc( INTEGER*4 sfactor, INTEGER*4 dfactor ) PARAMETERS sfactor Specifies how the red, green, blue, and alpha 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, GL_SRC_ALPHA_SATURATE, GL_CONSTANT_COLOR_EXT, GL_ONE_MINUS_CONSTANT_COLOR_EXT, GL_CONSTANT_ALPHA_EXT, and GL_ONE_MINUS_CONSTANT_ALPHA_EXT. dfactor Specifies how the red, green, blue, and alpha 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, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR_EXT, GL_ONE_MINUS_CONSTANT_COLOR_EXT, GL_CONSTANT_ALPHA_EXT, and GL_ONE_MINUS_CONSTANT_ALPHA_EXT. DESCRIPTION In RGB mode, pixels can be drawn using a function that blends the incoming (source) RGBA values with the RGBA values that are already in the frame buffer (the destination values). Blending is initially disabled. Use fglEnable and fglDisable with argument GL_BLEND to enable and disable blending. When blending is enabled, fglBlendFunc, fglBlendColorEXT, and fglBlendEquationEXT determine the blending operation. sfactor and dfactor 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 following, source, destination, and GL_BLEND_COLOR_EXT color components are denoted by (R ,G ,B ,A ), (R ,G ,B ,A ) and (R ,G ,B ,A ), s s s s d d d d c c c c respectively. Color components are understood to have integer values m c between 0 and (k ,k ,k ,k ), where k = 2 -1 with m being the number of R G B A c c bitplanes for the corresponding color component (c is one of R, G, B, or A). All scale factors are in the range [0,1]. Source and destination scale factors are denoted by (s ,s ,s ,s ) and (d ,d ,d ,d ). In the R G B A R G B A following table, (f ,f ,f ,f ) denotes either source or destination R G B A factors, and i = min(A , k -A ) / k . s A d A parameter (f , f , f , f ) R G B A _____________________________________________________________________________ GL_ZERO (0, 0, 0, 0) GL_ONE (1, 1, 1, 1) GL_SRC_COLOR (R /k , G /k , B /k , A /k ) s R s G s B s A GL_ONE_MINUS_SRC_COLOR (1, 1, 1, 1) - (R /k , G /k , B /k , A /k ) s R s G s B s A GL_DST_COLOR (R /k , G /k , B /k , A /k ) d R d G d B d A GL_ONE_MINUS_DST_COLOR (1, 1, 1, 1) - (R /k , G /k , B /k , A /k ) d R d G d B d A GL_SRC_ALPHA (A /k , A /k , A /k , A /k ) s A s A s A s A GL_ONE_MINUS_SRC_ALPHA (1, 1, 1, 1) - (A /k , A /k , A /k , A /k ) s A s A s A s A GL_DST_ALPHA (A /k , A /k , A /k , A /k ) d A d A d A d A GL_ONE_MINUS_DST_ALPHA (1, 1, 1, 1) - (A /k , A /k , A /k , A /k ) d A d A d A d A GL_CONSTANT_COLOR_EXT (R G B A c, c, c, c) GL_ONE_MINUS_CONSTANT_COLOR_EXT (1, 1, 1, 1) - (R G B A c, c, c, c) GL_CONSTANT_ALPHA_EXT (A A A A c, c, c, c) GL_ONE_MINUS_CONSTANT_ALPHA_EXT (1, 1, 1, 1) - (A A A A c, c, c, c) GL_SRC_ALPHA_SATURATE (i, i, i, 1) Blending combines corresponding source and destination color components according to the blending operation specified by GL_BLEND_EQUATION_EXT. The blending operations are: GL_BLEND_EQUATION_EXT Binary Operation __________________________________________________ GL_FUNC_ADD_EXT min(C *s +C *d ,k ) s C d C C GL_FUNC_SUBTRACT_EXT max(C *s -C *d ,0) s C d C GL_FUNC_REVERSE_SUBTRACT_EXT max(C *d -C *s ,0) d C s C GL_LOGIC_OP C Lop C s d GL_MIN_EXT min(C ,C ) s d GL_MAX_EXT max(C ,C ) s d where C is the relevant color component (R, G, B, or A), C and C are s d the source and destination color components, respectively, s and d are C C the source and destination scale factors, respectively, and Lop is one of 16 bitwise operators specified by fglLogicOp. Despite the apparent precision of the above equations, blending arithmetic is not exactly specified, because blending operates with imprecise integer color values. However, a blend factor that should be equal to one is guaranteed not to modify its multiplicand, and a blend factor equal to zero reduces its multiplicand to zero. Thus, for example, when sfactor is GL_SRC_ALPHA, dfactor is GL_ONE_MINUS_SRC_ALPHA, GL_BLEND_EQUATION_EXT is GL_FUNC_ADD_EXT, and A is equal to k , the s A equations reduce to simple replacement: R = R , G = G , B = B , A = A . d s d s d s d s EXAMPLES Transparency is best implemented using 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 bitplanes in the frame buffer. Blend function (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 blend function (GL_SRC_ALPHA_SATURATE, GL_ONE) with polygons sorted from nearest to farthest. (See the fglEnable, fglDisable reference page and the GL_POLYGON_SMOOTH argument for information on polygon antialiasing.) Destination alpha bitplanes, which must be present for this blend function to operate correctly, store the accumulated coverage. To blend two RGB (no alpha component) images as (1-p)*ImageA+p*ImageB, one would disable blending, draw ImageA into the frame buffer, enable blending, set GL_BLEND_COLOR_EXT to (0,0,0,p), the blend function to (GL_CONSTANT_ALPHA_EXT, GL_ONE_MINUS_CONSTANT_ALPHA_EXT), (and the blend equation to the default GL_FUNC_ADD_EXT), and draw ImageB. NOTES Incoming (source) alpha is correctly thought of as a material opacity, ranging from 1.0 (K ), representing complete opacity, to 0.0 (0), A 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 fglDrawBuffer.) Blending affects only RGB rendering. It is ignored by color index renderers. ERRORS GL_INVALID_ENUM is generated if either sfactor or dfactor is not an accepted value. GL_INVALID_OPERATION is generated if fglBlendFunc is executed between the execution of fglBegin and the corresponding execution of fglEnd. ASSOCIATED GETS fglGet with argument GL_BLEND_SRC, GL_BLEND_DST, GL_LOGIC_OP_MODE, or GL_BLEND_EQUATION_EXT, GL_BLEND_COLOR_EXT. fglIsEnabled with argument GL_BLEND MACHINE DEPENDENCIES RealityEngine, RealityEngine2, and VTX systems do not support the use of source blend factor GL_SRC_ALPHA_SATURATE and a destination factor based on the constant blend color (GL_.._CONSTANT_.._EXT); such combinations produce incorrect results. SEE ALSO fglAlphaFunc, fglClear, fglDrawBuffer, fglEnable, fglLogicOp, fglStencilFunc, fglBlendColorEXT, fglBlendEquationEXT.