1GLBLENDFUNC(3G)                                                GLBLENDFUNC(3G)
2
3
4

NAME

6       glBlendFunc - specify pixel arithmetic
7
8

C SPECIFICATION

10       void glBlendFunc( GLenum sfactor,
11                         GLenum dfactor )
12
13

PARAMETERS

15       sfactor  Specifies  how the red, green, blue, and alpha source blending
16                factors are computed.  The following  symbolic  constants  are
17                accepted:         GL_ZERO,        GL_ONE,        GL_DST_COLOR,
18                GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA,
19                GL_DST_ALPHA,            GL_ONE_MINUS_DST_ALPHA,           and
20                GL_SRC_ALPHA_SATURATE.  The initial value is GL_ONE.
21
22                Additionally, if the GL_ARB_imaging  extension  is  supported,
23                the   following  constants  are  accepted:  GL_CONSTANT_COLOR,
24                GL_ONE_MINUS_CONSTANT_COLOR,                GL_CONSTANT_ALPHA,
25                GL_ONE_MINUS_CONSTANT_ALPHA.
26
27       dfactor  Specifies  how  the  red,  green,  blue, and alpha destination
28                blending factors are computed.  Eight symbolic  constants  are
29                accepted:         GL_ZERO,        GL_ONE,        GL_SRC_COLOR,
30                GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA,
31                GL_DST_ALPHA,  and  GL_ONE_MINUS_DST_ALPHA.  The initial value
32                is GL_ZERO.
33
34                Additionally, if the GL_ARB_imaging  extension  is  supported,
35                the   following  constants  are  accepted:  GL_CONSTANT_COLOR,
36                GL_ONE_MINUS_CONSTANT_COLOR,                GL_CONSTANT_ALPHA,
37                GL_ONE_MINUS_CONSTANT_ALPHA.
38

DESCRIPTION

40       In  RGBA  mode,  pixels  can  be drawn using a function that blends the
41       incoming (source) RGBA values with the RGBA values that are already  in
42       the  frame buffer (the destination values).  Blending is initially dis‐
43       abled.  Use glEnable and glDisable with argument GL_BLEND to enable and
44       disable blending.
45
46       glBlendFunc  defines  the  operation  of  blending  when it is enabled.
47       sfactor specifies which of nine methods is used  to  scale  the  source
48       color  components.  dfactor specifies which of eight methods is used to
49       scale the destination color components.  The  eleven  possible  methods
50       are  described  in the following table.  Each method defines four scale
51       factors, one each for red, green, blue, and alpha.
52
53       In the table and in subsequent equations, source and destination  color
54       components  are  referred  to  as (Rs,Gs,Bs,As) and (Rd,Gd,Bd,Ad).  The
55       color specified by glBlendColor is referred to as (Rc,Gc,Bc,Ac).   They
56       are  understood  to  have  integer  values between 0 and (kR,kG,kB,kA),
57       where
58
59                                          kc=2mc−1
60
61       and (mR,mG,mB,mA) is the number of red, green,  blue,  and  alpha  bit‐
62       planes.
63
64       Source  and  destination scale factors are referred to as (sR,sG,sB,sA)
65       and (dR,dG,dB,dA).  The scale factors described in the  table,  denoted
66       (fR,fG,fB,fA),  represent  either  source  or destination factors.  All
67       scale factors have range [0, 1].
68
69          ──────────────────────────────────────────────────────────────────
70          Parameter                               (fR,fG,fB,fA)
71          ──────────────────────────────────────────────────────────────────
72          GL_ZERO                                    (0,0,0,0)
73          GL_ONE                                     (1,1,1,1)
74          GL_SRC_COLOR                       (Rs/kR,Gs/kG,Bs/kB,As/kA)
75          GL_ONE_MINUS_SRC_COLOR        (1,1,1,1)−(Rs/kR,Gs/kG,Bs/kB,As/kA)
76          GL_DST_COLOR                       (Rd/kR,Gd/kG,Bd/kB,Ad/kA)
77          GL_ONE_MINUS_DST_COLOR        (1,1,1,1)−(Rd/kR,Gd/kG,Bd/kB,Ad/kA)
78          GL_SRC_ALPHA                       (As/kA,As/kA,As/kA,As/kA)
79          GL_ONE_MINUS_SRC_ALPHA        (1,1,1,1)−(As/kA,As/kA,As/kA,As/kA)
80          GL_DST_ALPHA                       (Ad/kA,Ad/kA,Ad/kA,Ad/kA)
81          GL_ONE_MINUS_DST_ALPHA        (1,1,1,1)−(Ad/kA,Ad/kA,Ad/kA,Ad/kA)
82          GL_SRC_ALPHA_SATURATE                      (i,i,i,1)
83          GL_CONSTANT_COLOR                        (Rc,Gc,Bc,Ac)
84          GL_ONE_MINUS_CONSTANT_COLOR         (1,1,1,1)−(Rc,Gc,Bc,Ac)
85          GL_CONSTANT_ALPHA                        (Ac,Ac,Ac,Ac)
86          GL_ONE_MINUS_CONSTANT_ALPHA         (1,1,1,1)−(Ac,Ac,Ac,Ac)
87          ──────────────────────────────────────────────────────────────────
88
89       In the table,
90
91                     i=min(As,kAAd)/kA
92
93       To determine the blended RGBA values of a pixel when  drawing  in  RGBA
94       mode, the system uses the following equations:
95
96                     Rd=min(kR,RssR+RddR)
97                     Gd=min(kG,GssG+GddG)
98                     Bd=min(kB,BssB+BddB)
99                     Ad=min(kA,AssA+AddA)
100
101       Despite  the apparent precision of the above equations, blending arith‐
102       metic is not exactly specified, because blending operates  with  impre‐
103       cise  integer  color  values.   However,  a blend factor that should be
104       equal to 1 is guaranteed not to modify its multiplicand,  and  a  blend
105       factor  equal  to  0  reduces its multiplicand to 0.  For example, when
106       sfactor is GL_SRC_ALPHA, dfactor is GL_ONE_MINUS_SRC_ALPHA, and  As  is
107       equal to kA, the equations reduce to simple replacement:
108
109                     Rd=Rs
110                     Gd=Gs
111                     Bd=Bs
112                     Ad=As
113

EXAMPLES

115       Transparency  is  best  implemented using blend function (GL_SRC_ALPHA,
116       GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest  to  near‐
117       est.   Note  that  this  transparency  calculation does not require the
118       presence of alpha bitplanes in the frame buffer.
119
120       Blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)  is  also  useful
121       for rendering antialiased points and lines in arbitrary order.
122
123       Polygon antialiasing is optimized using blend function
124       (GL_SRC_ALPHA_SATURATE,  GL_ONE)  with  polygons sorted from nearest to
125       farthest.   (See  the  glEnable,  glDisable  reference  page  and   the
126       GL_POLYGON_SMOOTH  argument  for  information on polygon antialiasing.)
127       Destination alpha bitplanes, which must be present for this blend func‐
128       tion to operate correctly, store the accumulated coverage.
129

NOTES

131       Incoming  (source) alpha is correctly thought of as a material opacity,
132       ranging from 1.0 (KA), representing complete opacity, to 0.0 (0),  rep‐
133       resenting complete transparency.
134
135       When more than one color buffer is enabled for drawing, the GL performs
136       blending separately for each enabled buffer, using the contents of that
137       buffer for destination color.  (See glDrawBuffer.)
138
139       Blending  affects  only  RGBA  rendering.  It is ignored by color index
140       renderers.
141
142       GL_CONSTANT_COLOR,   GL_ONE_MINUS_CONSTANT_COLOR,    GL_CONSTANT_ALPHA,
143       GL_ONE_MINUS_CONSTANT_ALPHA are only available if the GL_ARB_imaging is
144       supported by your implementation.
145

ERRORS

147       GL_INVALID_ENUM is generated if either sfactor or  dfactor  is  not  an
148       accepted value.
149
150       GL_INVALID_OPERATION  is  generated  if glBlendFunc is executed between
151       the execution of glBegin and the corresponding execution of glEnd.
152

ASSOCIATED GETS

154       glGet with argument GL_BLEND_SRC
155       glGet with argument GL_BLEND_DST
156       glIsEnabled with argument GL_BLEND
157

SEE ALSO

159       glAlphaFunc(3G),  glBlendColor(3G),  glBlendEquation(3G),  glClear(3G),
160       glDrawBuffer(3G), glEnable(3G), glLogicOp(3G), glStencilFunc(3G)
161
162
163
164                                                               GLBLENDFUNC(3G)
Impressum