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

NAME

6       glBlendFunc - specify pixel arithmetic
7

C SPECIFICATION

9       void glBlendFunc(GLenum sfactor, GLenum dfactor);
10
11       void glBlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor);
12

PARAMETERS

14       buf
15           For glBlendFunci, specifies the index of the draw buffer for which
16           to set the blend function.
17
18       sfactor
19           Specifies how the red, green, blue, and alpha source blending
20           factors are computed. The initial value is GL_ONE.
21
22       dfactor
23           Specifies how the red, green, blue, and alpha destination blending
24           factors are computed. The following symbolic constants are
25           accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
26           GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA,
27           GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA.
28           GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA,
29           and GL_ONE_MINUS_CONSTANT_ALPHA. The initial value is GL_ZERO.
30

DESCRIPTION

32       Pixels can be drawn using a function that blends the incoming (source)
33       RGBA values with the RGBA values that are already in the frame buffer
34       (the destination values). Blending is initially disabled. Use
35       glEnable() and glDisable() with argument GL_BLEND to enable and disable
36       blending.
37
38       glBlendFunc defines the operation of blending for all draw buffers when
39       it is enabled.  glBlendFunci defines the operation of blending for a
40       single draw buffer specified by buf when enabled for that draw buffer.
41       sfactor specifies which method is used to scale the source color
42       components.  dfactor specifies which method is used to scale the
43       destination color components. Both parameters must be one of the
44       following symbolic constants: GL_ZERO, GL_ONE, GL_SRC_COLOR,
45       GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
46       GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA,
47       GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
48       GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE,
49       GL_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR, GL_SRC1_ALPHA, and
50       GL_ONE_MINUS_SRC1_ALPHA. The possible methods are described in the
51       following table. Each method defines four scale factors, one each for
52       red, green, blue, and alpha. In the table and in subsequent equations,
53       first source, second source and destination color components are
54       referred to as R s0 G s0 B s0 A s0, R s1 G s1 B s1 A s1 and R d G d B d
55       A d, respectively. The color specified by glBlendColor() is referred to
56       as R c G c B c A c. They are understood to have integer values between
57       0 and k R k G k B k A, where
58
59       and m R m G m B m A is the number of red, green, blue, and alpha
60       bitplanes.
61
62       Source and destination scale factors are referred to as s R s G s B s A
63       and d R d G d B d A. The scale factors described in the table, denoted
64       f R f G f B f A, represent either source or destination factors. All
65       scale factors have range 0 1.
66
67       ┌──────────────────────────────────┬────────────────────────────────────────────┐
68       │                                  │                                            │
69Parameter │                                            │
70       │                                  │                                            │
71       │                                  │                                            │
72       │                                  │                                 f          
73       │                                  │                                 R          
74       │                                  │                                            │
75       │                                  │                                 f          
76       │                                  │                                 G          
77       │                                  │                                            │
78       │                                  │                                 f          
79       │                                  │                                 B          
80       │                                  │                                            │
81       │                                  │                                 f          
82       │                                  │                                 A          
83       │                                  │                                            │
84       │                                  │                                            │
85       │                                  │                                            │
86       │                                  │                                            │
87       ├──────────────────────────────────┼────────────────────────────────────────────┤
88GL_ZERO                           │ 0                                          │
89       │                                  │                                 0          │
90       │                                  │                                 0          │
91       │                                  │                                 0          │
92       ├──────────────────────────────────┼────────────────────────────────────────────┤
93GL_ONE                            │ 1                                          │
94       │                                  │                                 1          │
95       │                                  │                                 1          │
96       │                                  │                                 1          │
97       ├──────────────────────────────────┼────────────────────────────────────────────┤
98GL_SRC_COLOR                      │ R                                          │
99       │                                  │                                     s0     │
100       │                                  │                                            │
101       │                                  │                                     k      │
102       │                                  │                                     R      │
103       │                                  │                                            │
104       │                                  │                                            │
105       │                                  │                                            │
106       │                                  │                                     G      │
107       │                                  │                                     s0     │
108       │                                  │                                            │
109       │                                  │                                     k      │
110       │                                  │                                     G      │
111       │                                  │                                            │
112       │                                  │                                            │
113       │                                  │                                            │
114       │                                  │                                     B      │
115       │                                  │                                     s0     │
116       │                                  │                                            │
117       │                                  │                                     k      │
118       │                                  │                                     B      │
119       │                                  │                                            │
120       │                                  │                                            │
121       │                                  │                                            │
122       │                                  │                                     A      │
123       │                                  │                                     s0     │
124       │                                  │                                            │
125       │                                  │                                     k      │
126       │                                  │                                     A      │
127       ├──────────────────────────────────┼────────────────────────────────────────────┤
128GL_ONE_MINUS_SRC_COLOR            │ 1                                          │
129       │                                  │                                     1      │
130       │                                  │                                     1      │
131       │                                  │                                     1      │
132       │                                  │                                            │
133       │                                  │                                 -          │
134       │                                  │                                            │
135       │                                  │                                            │
136       │                                  │                                         R  │
137       │                                  │                                         s0 │
138       │                                  │                                            │
139       │                                  │                                         k  │
140       │                                  │                                         R  │
141       │                                  │                                            │
142       │                                  │                                            │
143       │                                  │                                            │
144       │                                  │                                         G  │
145       │                                  │                                         s0 │
146       │                                  │                                            │
147       │                                  │                                         k  │
148       │                                  │                                         G  │
149       │                                  │                                            │
150       │                                  │                                            │
151       │                                  │                                            │
152       │                                  │                                         B  │
153       │                                  │                                         s0 │
154       │                                  │                                            │
155       │                                  │                                         k  │
156       │                                  │                                         B  │
157       │                                  │                                            │
158       │                                  │                                            │
159       │                                  │                                            │
160       │                                  │                                         A  │
161       │                                  │                                         s0 │
162       │                                  │                                            │
163       │                                  │                                         k  │
164       │                                  │                                         A  │
165       ├──────────────────────────────────┼────────────────────────────────────────────┤
166GL_DST_COLOR                      │ R                                          │
167       │                                  │                                     d      │
168       │                                  │                                            │
169       │                                  │                                     k      │
170       │                                  │                                     R      │
171       │                                  │                                            │
172       │                                  │                                            │
173       │                                  │                                            │
174       │                                  │                                     G      │
175       │                                  │                                     d      │
176       │                                  │                                            │
177       │                                  │                                     k      │
178       │                                  │                                     G      │
179       │                                  │                                            │
180       │                                  │                                            │
181       │                                  │                                            │
182       │                                  │                                     B      │
183       │                                  │                                     d      │
184       │                                  │                                            │
185       │                                  │                                     k      │
186       │                                  │                                     B      │
187       │                                  │                                            │
188       │                                  │                                            │
189       │                                  │                                            │
190       │                                  │                                     A      │
191       │                                  │                                     d      │
192       │                                  │                                            │
193       │                                  │                                     k      │
194       │                                  │                                     A      │
195       ├──────────────────────────────────┼────────────────────────────────────────────┤
196GL_ONE_MINUS_DST_COLOR            │ 1                                          │
197       │                                  │                                     1      │
198       │                                  │                                     1      │
199       │                                  │                                     1      │
200       │                                  │                                            │
201       │                                  │                                 -          │
202       │                                  │                                            │
203       │                                  │                                            │
204       │                                  │                                         R  │
205       │                                  │                                         d  │
206       │                                  │                                            │
207       │                                  │                                         k  │
208       │                                  │                                         R  │
209       │                                  │                                            │
210       │                                  │                                            │
211       │                                  │                                            │
212       │                                  │                                         G  │
213       │                                  │                                         d  │
214       │                                  │                                            │
215       │                                  │                                         k  │
216       │                                  │                                         G  │
217       │                                  │                                            │
218       │                                  │                                            │
219       │                                  │                                            │
220       │                                  │                                         B  │
221       │                                  │                                         d  │
222       │                                  │                                            │
223       │                                  │                                         k  │
224       │                                  │                                         B  │
225       │                                  │                                            │
226       │                                  │                                            │
227       │                                  │                                            │
228       │                                  │                                         A  │
229       │                                  │                                         d  │
230       │                                  │                                            │
231       │                                  │                                         k  │
232       │                                  │                                         A  │
233       ├──────────────────────────────────┼────────────────────────────────────────────┤
234GL_SRC_ALPHA                      │ A                                          │
235       │                                  │                                     s0     │
236       │                                  │                                            │
237       │                                  │                                     k      │
238       │                                  │                                     A      │
239       │                                  │                                            │
240       │                                  │                                            │
241       │                                  │                                            │
242       │                                  │                                     A      │
243       │                                  │                                     s0     │
244       │                                  │                                            │
245       │                                  │                                     k      │
246       │                                  │                                     A      │
247       │                                  │                                            │
248       │                                  │                                            │
249       │                                  │                                            │
250       │                                  │                                     A      │
251       │                                  │                                     s0     │
252       │                                  │                                            │
253       │                                  │                                     k      │
254       │                                  │                                     A      │
255       │                                  │                                            │
256       │                                  │                                            │
257       │                                  │                                            │
258       │                                  │                                     A      │
259       │                                  │                                     s0     │
260       │                                  │                                            │
261       │                                  │                                     k      │
262       │                                  │                                     A      │
263       ├──────────────────────────────────┼────────────────────────────────────────────┤
264GL_ONE_MINUS_SRC_ALPHA            │ 1                                          │
265       │                                  │                                     1      │
266       │                                  │                                     1      │
267       │                                  │                                     1      │
268       │                                  │                                            │
269       │                                  │                                 -          │
270       │                                  │                                            │
271       │                                  │                                            │
272       │                                  │                                         A  │
273       │                                  │                                         s0 │
274       │                                  │                                            │
275       │                                  │                                         k  │
276       │                                  │                                         A  │
277       │                                  │                                            │
278       │                                  │                                            │
279       │                                  │                                            │
280       │                                  │                                         A  │
281       │                                  │                                         s0 │
282       │                                  │                                            │
283       │                                  │                                         k  │
284       │                                  │                                         A  │
285       │                                  │                                            │
286       │                                  │                                            │
287       │                                  │                                            │
288       │                                  │                                         A  │
289       │                                  │                                         s0 │
290       │                                  │                                            │
291       │                                  │                                         k  │
292       │                                  │                                         A  │
293       │                                  │                                            │
294       │                                  │                                            │
295       │                                  │                                            │
296       │                                  │                                         A  │
297       │                                  │                                         s0 │
298       │                                  │                                            │
299       │                                  │                                         k  │
300       │                                  │                                         A  │
301       ├──────────────────────────────────┼────────────────────────────────────────────┤
302GL_DST_ALPHA                      │ A                                          │
303       │                                  │                                     d      │
304       │                                  │                                            │
305       │                                  │                                     k      │
306       │                                  │                                     A      │
307       │                                  │                                            │
308       │                                  │                                            │
309       │                                  │                                            │
310       │                                  │                                     A      │
311       │                                  │                                     d      │
312       │                                  │                                            │
313       │                                  │                                     k      │
314       │                                  │                                     A      │
315       │                                  │                                            │
316       │                                  │                                            │
317       │                                  │                                            │
318       │                                  │                                     A      │
319       │                                  │                                     d      │
320       │                                  │                                            │
321       │                                  │                                     k      │
322       │                                  │                                     A      │
323       │                                  │                                            │
324       │                                  │                                            │
325       │                                  │                                            │
326       │                                  │                                     A      │
327       │                                  │                                     d      │
328       │                                  │                                            │
329       │                                  │                                     k      │
330       │                                  │                                     A      │
331       ├──────────────────────────────────┼────────────────────────────────────────────┤
332GL_ONE_MINUS_DST_ALPHA            │ 1                                          │
333       │                                  │                                     1      │
334       │                                  │                                     1      │
335       │                                  │                                     1      │
336       │                                  │                                            │
337       │                                  │                                 -          │
338       │                                  │                                            │
339       │                                  │                                            │
340       │                                  │                                         A  │
341       │                                  │                                         d  │
342       │                                  │                                            │
343       │                                  │                                         k  │
344       │                                  │                                         A  │
345       │                                  │                                            │
346       │                                  │                                            │
347       │                                  │                                            │
348       │                                  │                                         A  │
349       │                                  │                                         d  │
350       │                                  │                                            │
351       │                                  │                                         k  │
352       │                                  │                                         A  │
353       │                                  │                                            │
354       │                                  │                                            │
355       │                                  │                                            │
356       │                                  │                                         A  │
357       │                                  │                                         d  │
358       │                                  │                                            │
359       │                                  │                                         k  │
360       │                                  │                                         A  │
361       │                                  │                                            │
362       │                                  │                                            │
363       │                                  │                                            │
364       │                                  │                                         A  │
365       │                                  │                                         d  │
366       │                                  │                                            │
367       │                                  │                                         k  │
368       │                                  │                                         A  │
369       ├──────────────────────────────────┼────────────────────────────────────────────┤
370GL_CONSTANT_COLOR                 │ R                                          │
371       │                                  │                                 c          │
372       │                                  │                                            │
373       │                                  │                                 G          │
374       │                                  │                                 c          │
375       │                                  │                                            │
376       │                                  │                                 B          │
377       │                                  │                                 c          │
378       │                                  │                                            │
379       │                                  │                                 A          │
380       │                                  │                                 c          │
381       ├──────────────────────────────────┼────────────────────────────────────────────┤
382GL_ONE_MINUS_CONSTANT_COLOR       │ 1                                          │
383       │                                  │                                     1      │
384       │                                  │                                     1      │
385       │                                  │                                     1      │
386       │                                  │                                            │
387       │                                  │                                 -          │
388       │                                  │                                            │
389       │                                  │                                     R      │
390       │                                  │                                     c      │
391       │                                  │                                            │
392       │                                  │                                     G      │
393       │                                  │                                     c      │
394       │                                  │                                            │
395       │                                  │                                     B      │
396       │                                  │                                     c      │
397       │                                  │                                            │
398       │                                  │                                     A      │
399       │                                  │                                     c      │
400       ├──────────────────────────────────┼────────────────────────────────────────────┤
401GL_CONSTANT_ALPHA                 │ A                                          │
402       │                                  │                                 c          │
403       │                                  │                                            │
404       │                                  │                                 A          │
405       │                                  │                                 c          │
406       │                                  │                                            │
407       │                                  │                                 A          │
408       │                                  │                                 c          │
409       │                                  │                                            │
410       │                                  │                                 A          │
411       │                                  │                                 c          │
412       ├──────────────────────────────────┼────────────────────────────────────────────┤
413GL_ONE_MINUS_CONSTANT_ALPHA       │ 1                                          │
414       │                                  │                                     1      │
415       │                                  │                                     1      │
416       │                                  │                                     1      │
417       │                                  │                                            │
418       │                                  │                                 -          │
419       │                                  │                                            │
420       │                                  │                                     A      │
421       │                                  │                                     c      │
422       │                                  │                                            │
423       │                                  │                                     A      │
424       │                                  │                                     c      │
425       │                                  │                                            │
426       │                                  │                                     A      │
427       │                                  │                                     c      │
428       │                                  │                                            │
429       │                                  │                                     A      │
430       │                                  │                                     c      │
431       ├──────────────────────────────────┼────────────────────────────────────────────┤
432GL_SRC_ALPHA_SATURATE             │ i                                          │
433       │                                  │                                 i          │
434       │                                  │                                 i          │
435       │                                  │                                 1          │
436       ├──────────────────────────────────┼────────────────────────────────────────────┤
437GL_SRC1_COLOR                     │ R                                          │
438       │                                  │                                     s1     │
439       │                                  │                                            │
440       │                                  │                                     k      │
441       │                                  │                                     R      │
442       │                                  │                                            │
443       │                                  │                                            │
444       │                                  │                                            │
445       │                                  │                                     G      │
446       │                                  │                                     s1     │
447       │                                  │                                            │
448       │                                  │                                     k      │
449       │                                  │                                     G      │
450       │                                  │                                            │
451       │                                  │                                            │
452       │                                  │                                            │
453       │                                  │                                     B      │
454       │                                  │                                     s1     │
455       │                                  │                                            │
456       │                                  │                                     k      │
457       │                                  │                                     B      │
458       │                                  │                                            │
459       │                                  │                                            │
460       │                                  │                                            │
461       │                                  │                                     A      │
462       │                                  │                                     s1     │
463       │                                  │                                            │
464       │                                  │                                     k      │
465       │                                  │                                     A      │
466       ├──────────────────────────────────┼────────────────────────────────────────────┤
467GL_ONE_MINUS_SRC1_COLOR           │ 1                                          │
468       │                                  │                                     1      │
469       │                                  │                                     1      │
470       │                                  │                                     1      │
471       │                                  │                                            │
472       │                                  │                                 -          │
473       │                                  │                                            │
474       │                                  │                                            │
475       │                                  │                                         R  │
476       │                                  │                                         s1 │
477       │                                  │                                            │
478       │                                  │                                         k  │
479       │                                  │                                         R  │
480       │                                  │                                            │
481       │                                  │                                            │
482       │                                  │                                            │
483       │                                  │                                         G  │
484       │                                  │                                         s1 │
485       │                                  │                                            │
486       │                                  │                                         k  │
487       │                                  │                                         G  │
488       │                                  │                                            │
489       │                                  │                                            │
490       │                                  │                                            │
491       │                                  │                                         B  │
492       │                                  │                                         s1 │
493       │                                  │                                            │
494       │                                  │                                         k  │
495       │                                  │                                         B  │
496       │                                  │                                            │
497       │                                  │                                            │
498       │                                  │                                            │
499       │                                  │                                         A  │
500       │                                  │                                         s1 │
501       │                                  │                                            │
502       │                                  │                                         k  │
503       │                                  │                                         A  │
504       ├──────────────────────────────────┼────────────────────────────────────────────┤
505GL_SRC1_ALPHA                     │ A                                          │
506       │                                  │                                     s1     │
507       │                                  │                                            │
508       │                                  │                                     k      │
509       │                                  │                                     A      │
510       │                                  │                                            │
511       │                                  │                                            │
512       │                                  │                                            │
513       │                                  │                                     A      │
514       │                                  │                                     s1     │
515       │                                  │                                            │
516       │                                  │                                     k      │
517       │                                  │                                     A      │
518       │                                  │                                            │
519       │                                  │                                            │
520       │                                  │                                            │
521       │                                  │                                     A      │
522       │                                  │                                     s1     │
523       │                                  │                                            │
524       │                                  │                                     k      │
525       │                                  │                                     A      │
526       │                                  │                                            │
527       │                                  │                                            │
528       │                                  │                                            │
529       │                                  │                                     A      │
530       │                                  │                                     s1     │
531       │                                  │                                            │
532       │                                  │                                     k      │
533       │                                  │                                     A      │
534       ├──────────────────────────────────┼────────────────────────────────────────────┤
535GL_ONE_MINUS_SRC1_ALPHA           │ 1                                          │
536       │                                  │                                     1      │
537       │                                  │                                     1      │
538       │                                  │                                     1      │
539       │                                  │                                            │
540       │                                  │                                 -          │
541       │                                  │                                            │
542       │                                  │                                            │
543       │                                  │                                         A  │
544       │                                  │                                         s1 │
545       │                                  │                                            │
546       │                                  │                                         k  │
547       │                                  │                                         A  │
548       │                                  │                                            │
549       │                                  │                                            │
550       │                                  │                                            │
551       │                                  │                                         A  │
552       │                                  │                                         s1 │
553       │                                  │                                            │
554       │                                  │                                         k  │
555       │                                  │                                         A  │
556       │                                  │                                            │
557       │                                  │                                            │
558       │                                  │                                            │
559       │                                  │                                         A  │
560       │                                  │                                         s1 │
561       │                                  │                                            │
562       │                                  │                                         k  │
563       │                                  │                                         A  │
564       │                                  │                                            │
565       │                                  │                                            │
566       │                                  │                                            │
567       │                                  │                                         A  │
568       │                                  │                                         s1 │
569       │                                  │                                            │
570       │                                  │                                         k  │
571       │                                  │                                         A  │
572       └──────────────────────────────────┴────────────────────────────────────────────┘
573
574       In the table,
575
576       To determine the blended RGBA values of a pixel, the system uses the
577       following equations:
578
579       Despite the apparent precision of the above equations, blending
580       arithmetic is not exactly specified, because blending operates with
581       imprecise integer color values. However, a blend factor that should be
582       equal to 1 is guaranteed not to modify its multiplicand, and a blend
583       factor equal to 0 reduces its multiplicand to 0. For example, when
584       sfactor is GL_SRC_ALPHA, dfactor is GL_ONE_MINUS_SRC_ALPHA, and A s is
585       equal to k A, the equations reduce to simple replacement:
586

EXAMPLES

588       Transparency is best implemented using blend function (GL_SRC_ALPHA,
589       GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to
590       nearest. Note that this transparency calculation does not require the
591       presence of alpha bitplanes in the frame buffer.
592
593       Blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is also useful
594       for rendering antialiased points and lines in arbitrary order.
595
596       Polygon antialiasing is optimized using blend function
597       (GL_SRC_ALPHA_SATURATE, GL_ONE) with polygons sorted from nearest to
598       farthest. (See the glEnable(), glDisable() reference page and the
599       GL_POLYGON_SMOOTH argument for information on polygon antialiasing.)
600       Destination alpha bitplanes, which must be present for this blend
601       function to operate correctly, store the accumulated coverage.
602

NOTES

604       Incoming (source) alpha is correctly thought of as a material opacity,
605       ranging from 1.0 (K A), representing complete opacity, to 0.0 (0),
606       representing complete transparency.
607
608       When more than one color buffer is enabled for drawing, the GL performs
609       blending separately for each enabled buffer, using the contents of that
610       buffer for destination color. (See glDrawBuffer().)
611
612       When dual source blending is enabled (i.e., one of the blend factors
613       requiring the second color input is used), the maximum number of
614       enabled draw buffers is given by GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, which
615       may be lower than GL_MAX_DRAW_BUFFERS.
616

ERRORS

618       GL_INVALID_ENUM is generated if either sfactor or dfactor is not an
619       accepted value.
620
621       GL_INVALID_VALUE is generated by glBlendFunci if buf is greater than or
622       equal to the value of GL_MAX_DRAW_BUFFERS.
623

ASSOCIATED GETS

625       glGet() with argument GL_BLEND_SRC
626
627       glGet() with argument GL_BLEND_DST
628
629       glIsEnabled() with argument GL_BLEND
630

SEE ALSO

632       glBlendColor(), glBlendEquation(), glBlendFuncSeparate(), glClear(),
633       glDrawBuffer(), glEnable(), glLogicOp(), glStencilFunc()
634
636       Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed
637       under the SGI Free Software B License. For details, see
638       http://oss.sgi.com/projects/FreeB/.
639

AUTHORS

641       opengl.org
642
643
644
645opengl.org                        06/10/2014                   GLBLENDFUNC(3G)
Impressum