glBlendFunc.3   [plain text]


'\" te  
'\"macro stdmacro
.ds Vn Version 1.2
.ds Dt 24 September 1999
.ds Re Release 1.2.1
.ds Dp May 22 14:44
.ds Dm 9 May 22 14:
.ds Xs 18970    10
.TH GLBLENDFUNC 3G
.SH NAME
.B "glBlendFunc
\- specify pixel arithmetic

.SH C SPECIFICATION
void \f3glBlendFunc\fP(
GLenum \fIsfactor\fP,
.nf
.ta \w'\f3void \fPglBlendFunc( 'u
	GLenum \fIdfactor\fP )
.fi

.EQ
delim $$
.EN
.SH PARAMETERS
.TP \w'\f2sfactor\fP\ \ 'u 
\f2sfactor\fP
Specifies how the red, green, blue,
and alpha source blending factors are computed.
The following symbolic constants are accepted:
\%\f3GL_ZERO\fP,
\%\f3GL_ONE\fP,
\%\f3GL_DST_COLOR\fP,
\%\f3GL_ONE_MINUS_DST_COLOR\fP,
\%\f3GL_SRC_ALPHA\fP,
\%\f3GL_ONE_MINUS_SRC_ALPHA\fP,
\%\f3GL_DST_ALPHA\fP,
\%\f3GL_ONE_MINUS_DST_ALPHA\fP, and
\%\f3GL_SRC_ALPHA_SATURATE\fP.
The initial value is \%\f3GL_ONE\fP.
.TE

Additionally, if the \%\f3GL_ARB_imaging\fP extension is supported, the
following constants are accepted:
\%\f3GL_CONSTANT_COLOR\fP,
\%\f3GL_ONE_MINUS_CONSTANT_COLOR\fP,
\%\f3GL_CONSTANT_ALPHA\fP,
\%\f3GL_ONE_MINUS_CONSTANT_ALPHA\fP.
.TP
\f2dfactor\fP
Specifies how the red, green, blue,
and alpha destination blending factors are computed.
Eight symbolic constants are accepted:
\%\f3GL_ZERO\fP,
\%\f3GL_ONE\fP,
\%\f3GL_SRC_COLOR\fP,
\%\f3GL_ONE_MINUS_SRC_COLOR\fP,
\%\f3GL_SRC_ALPHA\fP,
\%\f3GL_ONE_MINUS_SRC_ALPHA\fP,
\%\f3GL_DST_ALPHA\fP, and
\%\f3GL_ONE_MINUS_DST_ALPHA\fP.
The initial value is \%\f3GL_ZERO\fP.
.TE

Additionally, if the \%\f3GL_ARB_imaging\fP extension is supported, the
following constants are accepted:
\%\f3GL_CONSTANT_COLOR\fP,
\%\f3GL_ONE_MINUS_CONSTANT_COLOR\fP,
\%\f3GL_CONSTANT_ALPHA\fP,
\%\f3GL_ONE_MINUS_CONSTANT_ALPHA\fP.
.SH DESCRIPTION
In RGBA 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 \%\f3glEnable\fP and \%\f3glDisable\fP with argument \%\f3GL_BLEND\fP
to enable and disable blending.
.P
\%\f3glBlendFunc\fP defines the operation of blending when it is enabled.
\f2sfactor\fP specifies which of nine methods is used to scale the
source color components.
\f2dfactor\fP specifies which of eight methods is used to scale the
destination color components.
The eleven possible methods are described in the following table.
Each method defines four scale factors,
one each for red, green, blue, and alpha.
.P
In the table and in subsequent equations, source and destination
color components are referred to as
$(R sub s , G sub s , B sub s , A sub s )$ and
$(R sub d , G sub d , B sub d , A sub d )$.
The color specified by \%\f3glBlendColor\fP is referred to as
$(R sub c , G sub c , B sub c , A sub c )$.
They are understood to have integer values between 0 and
$(k sub R , k sub G , k sub B , k sub A )$,
where
.P
.RS
.ce
$k sub c ~=~ 2 sup m sub c - 1$ 
.RE
.P
and
$(m sub R , m sub G , m sub B , m sub A )$
is the number of red,
green,
blue,
and alpha bitplanes.
.P
Source and destination scale factors are referred to as
$(s sub R , s sub G , s sub B , s sub A )$ and
$(d sub R , d sub G , d sub B , d sub A )$.
The scale factors described in the table,
denoted $(f sub R , f sub G , f sub B , f sub A )$,
represent either source or destination factors.
All scale factors have range [0,\ 1].
.P
.TS
center;
lb cb
l c .
_
Parameter	$(f sub R , ~~ f sub G , ~~ f sub B , ~~ f sub A )$ 
_
\%\f3GL_ZERO\fP	$(0, ~0, ~0, ~0 )$
\%\f3GL_ONE\fP	$(1, ~1, ~1, ~1 )$
\%\f3GL_SRC_COLOR\fP	$(R sub s / k sub R , ~G sub s / k sub G , ~B sub s / k sub B , ~A sub s / k sub A )$
\%\f3GL_ONE_MINUS_SRC_COLOR\fP	$(1, ~1, ~1, ~1 ) ~-~ (R sub s / k sub R , ~G sub s / k sub G , ~B sub s / k sub B , ~A sub s / k sub A )$
\%\f3GL_DST_COLOR\fP	$(R sub d / k sub R , ~G sub d / k sub G , ~B sub d / k sub B , ~A sub d / k sub A )$
\%\f3GL_ONE_MINUS_DST_COLOR\fP	$(1, ~1, ~1, ~1 ) ~-~ (R sub d / k sub R , ~G sub d / k sub G , ~B sub d / k sub B , ~A sub d / k sub A )$
\%\f3GL_SRC_ALPHA\fP	$(A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A )$
\%\f3GL_ONE_MINUS_SRC_ALPHA\fP	$(1, ~1, ~1, ~1 ) ~-~ (A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A )$
\%\f3GL_DST_ALPHA\fP	$(A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A )$
\%\f3GL_ONE_MINUS_DST_ALPHA\fP	$(1, ~1, ~1, ~1 ) ~-~ (A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A )$
\%\f3GL_SRC_ALPHA_SATURATE\fP	$(i, ~i, ~i, ~1 )$
\%\f3GL_CONSTANT_COLOR\fP	$(R sub c, G sub c, B sub c, A sub c)$
\%\f3GL_ONE_MINUS_CONSTANT_COLOR\fP	$(1, ~1, ~1, ~1 ) ~-~ (R sub c, G sub c, B sub c, A sub c)$
\%\f3GL_CONSTANT_ALPHA\fP	$(A sub c, A sub c, A sub c, A sub c)$
\%\f3GL_ONE_MINUS_CONSTANT_ALPHA\fP	$(1, ~1, ~1, ~1 ) ~-~ (A sub c, A sub c, A sub c, A sub c)$
_
.TE
.sp
In the table,
.P
.RS
.nf
.IP
$i ~=~  min (A sub s , ~k sub A ~-~ A sub d ) ~/~ k sub A$
.fi
.RE
.P
To determine the blended RGBA values of a pixel when drawing in RGBA mode,
the system uses the following equations:
.P
.RS
.nf
.IP
$R sub d ~=~ mark   min ( k sub R, ~R sub s~s sub R~+~R sub d~d sub R )$
$G sub d ~=~ lineup min ( k sub G, ~G sub s~s sub G~+~G sub d~d sub G )$
$B sub d ~=~ lineup min ( k sub B, ~B sub s~s sub B~+~B sub d~d sub B )$
$A sub d ~=~ lineup min ( k sub A, ~A sub s~s sub A~+~A sub d~d sub A )$
.fi
.RE
.P
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 1
is guaranteed not to modify its multiplicand,
and a blend factor equal to 0 reduces its multiplicand to 0.
For example,
when \f2sfactor\fP is \%\f3GL_SRC_ALPHA\fP,
\f2dfactor\fP is \%\f3GL_ONE_MINUS_SRC_ALPHA\fP,
and $A sub s$ is equal to $k sub A$,
the equations reduce to simple replacement:
.P
.RS
.nf
.IP
$R sub d ~=~ mark   R sub s$
$G sub d ~=~ lineup G sub s$
$B sub d ~=~ lineup B sub s$
$A sub d ~=~ lineup A sub s$
.fi
.RE
.P
.SH EXAMPLES
.P
Transparency is best implemented using blend function
(\%\f3GL_SRC_ALPHA\fP, \%\f3GL_ONE_MINUS_SRC_ALPHA\fP)
with primitives sorted from farthest to nearest.
Note that this transparency calculation does not require
the presence of alpha bitplanes in the frame buffer.
.P
Blend function
(\%\f3GL_SRC_ALPHA\fP, \%\f3GL_ONE_MINUS_SRC_ALPHA\fP)
is also useful for rendering antialiased points and lines
in arbitrary order.
.P
Polygon antialiasing is optimized using blend function
.br
(\%\f3GL_SRC_ALPHA_SATURATE\fP, \%\f3GL_ONE\fP)
with polygons sorted from nearest to farthest.
(See the \%\f3glEnable\fP, \%\f3glDisable\fP reference page and the 
\%\f3GL_POLYGON_SMOOTH\fP argument for information on polygon antialiasing.)
Destination alpha bitplanes,
which must be present for this blend function to operate correctly,
store the accumulated coverage.
.SH NOTES
Incoming (source) alpha is correctly thought of as a material opacity,
ranging from 1.0 ($K sub A$), representing complete opacity,
to 0.0 (0), representing complete 
transparency.
.P
When more than one color buffer is enabled for drawing,
the GL performs blending separately for each enabled buffer,
using the contents of that buffer for destination color.
(See \%\f3glDrawBuffer\fP.)
.P
Blending affects only RGBA rendering.
It is ignored by color index renderers.
.P
\%\f3GL_CONSTANT_COLOR\fP, \%\f3GL_ONE_MINUS_CONSTANT_COLOR\fP,
\%\f3GL_CONSTANT_ALPHA\fP, \%\f3GL_ONE_MINUS_CONSTANT_ALPHA\fP are only
available if the \%\f3GL_ARB_imaging\fP is supported by your implementation.
.SH ERRORS
\%\f3GL_INVALID_ENUM\fP is generated if either \f2sfactor\fP or \f2dfactor\fP is not an
accepted value.
.P
\%\f3GL_INVALID_OPERATION\fP is generated if \%\f3glBlendFunc\fP
is executed between the execution of \%\f3glBegin\fP
and the corresponding execution of \%\f3glEnd\fP.
.SH ASSOCIATED GETS
\%\f3glGet\fP with argument \%\f3GL_BLEND_SRC\fP
.br
\%\f3glGet\fP with argument \%\f3GL_BLEND_DST\fP
.br
\%\f3glIsEnabled\fP with argument \%\f3GL_BLEND\fP
.br
.SH SEE ALSO
\%\f3glAlphaFunc\fP,
\%\f3glBlendColor\fP,
\%\f3glBlendEquation\fP,
\%\f3glClear\fP,
\%\f3glDrawBuffer\fP,
\%\f3glEnable\fP,
\%\f3glLogicOp\fP,
\%\f3glStencilFunc\fP