1al_set_blender(3)                                            al_set_blender(3)
2
3
4

NAME

6       al_set_blender - Allegro 5 API
7

SYNOPSIS

9              #include <allegro5/allegro.h>
10
11              void al_set_blender(int op, int src, int dst)
12

DESCRIPTION

14       Sets the function to use for blending for the current thread.
15
16       Blending means, the source and destination colors are combined in draw‐
17       ing operations.
18
19       Assume the source color (e.g. color of a rectangle to draw, or pixel of
20       a  bitmap  to draw) is given as its red/green/blue/alpha components (if
21       the bitmap has no alpha it always is assumed to be fully opaque, so 255
22       for 8-bit or 1.0 for floating point): s = s.r, s.g, s.b, s.a.  And this
23       color is drawn to a destination, which already has a color:  d  =  d.r,
24       d.g, d.b, d.a.
25
26       The conceptional formula used by Allegro to draw any pixel then depends
27       on the op parameter:
28
29       • ALLEGRO_ADD
30
31                   r = d.r * df.r + s.r * sf.r
32                   g = d.g * df.g + s.g * sf.g
33                   b = d.b * df.b + s.b * sf.b
34                   a = d.a * df.a + s.a * sf.a
35
36       • ALLEGRO_DEST_MINUS_SRC
37
38                   r = d.r * df.r - s.r * sf.r
39                   g = d.g * df.g - s.g * sf.g
40                   b = d.b * df.b - s.b * sf.b
41                   a = d.a * df.a - s.a * sf.a
42
43       • ALLEGRO_SRC_MINUS_DEST
44
45                   r = s.r * sf.r - d.r * df.r
46                   g = s.g * sf.g - d.g * df.g
47                   b = s.b * sf.b - d.b * df.b
48                   a = s.a * sf.a - d.a * df.a
49
50       Valid values for the factors sf and df passed to this function  are  as
51       follows,  where  s  is the source color, d the destination color and cc
52       the color set with al_set_blend_color(3) (white by default)
53
54       • ALLEGRO_ZERO
55
56                   f = 0, 0, 0, 0
57
58       • ALLEGRO_ONE
59
60                   f = 1, 1, 1, 1
61
62       • ALLEGRO_ALPHA
63
64                   f = s.a, s.a, s.a, s.a
65
66       • ALLEGRO_INVERSE_ALPHA
67
68                   f = 1 - s.a, 1 - s.a, 1 - s.a, 1 - s.a
69
70       • ALLEGRO_SRC_COLOR (since: 5.0.10, 5.1.0)
71
72                   f = s.r, s.g, s.b, s.a
73
74       • ALLEGRO_DEST_COLOR (since: 5.0.10, 5.1.8)
75
76                   f = d.r, d.g, d.b, d.a
77
78       • ALLEGRO_INVERSE_SRC_COLOR (since: 5.0.10, 5.1.0)
79
80                   f = 1 - s.r, 1 - s.g, 1 - s.b, 1 - s.a
81
82       • ALLEGRO_INVERSE_DEST_COLOR (since: 5.0.10, 5.1.8)
83
84                   f = 1 - d.r, 1 - d.g, 1 - d.b, 1 - d.a
85
86       • ALLEGRO_CONST_COLOR (since: 5.1.12, not supported on OpenGLES 1.0)
87
88                   f = cc.r, cc.g, cc.b, cc.a
89
90       • ALLEGRO_INVERSE_CONST_COLOR (since: 5.1.12, not supported on OpenGLES
91         1.0)
92
93                   f = 1 - cc.r, 1 - cc.g, 1 - cc.b, 1 - cc.a
94
95       Blending examples:
96
97       So  for  example,  to  restore the default of using premultiplied alpha
98       blending, you would use:
99
100              al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
101
102       As formula:
103
104              r = d.r * (1 - s.a) + s.r * 1
105              g = d.g * (1 - s.a) + s.g * 1
106              b = d.b * (1 - s.a) + s.b * 1
107              a = d.a * (1 - s.a) + s.a * 1
108
109       If you are using non-pre-multiplied alpha, you could use
110
111              al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
112
113       Additive blending would be achieved with
114
115              al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
116
117       Copying the source to the destination (including alpha) unmodified
118
119              al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
120
121       Multiplying source and destination components
122
123              al_set_blender(ALLEGRO_ADD, ALLEGRO_DEST_COLOR, ALLEGRO_ZERO)
124
125       Tinting the source (like al_draw_tinted_bitmap(3))
126
127              al_set_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_ONE);
128              al_set_blend_color(al_map_rgb(0, 96, 255)); /* nice Chrysler blue */
129
130       Averaging source and destination pixels
131
132              al_set_blender(ALLEGRO_ADD, ALLEGRO_CONST_COLOR, ALLEGRO_CONST_COLOR);
133              al_set_blend_color(al_map_rgba_f(0.5, 0.5, 0.5, 0.5));
134
135       As formula:
136
137              r = d.r * 0 + s.r * d.r
138              g = d.g * 0 + s.g * d.g
139              b = d.b * 0 + s.b * d.b
140              a = d.a * 0 + s.a * d.a
141

SEE ALSO

143       al_set_separate_blender(3), al_set_blend_color(3), al_get_blender(3)
144
145
146
147Allegro reference manual                                     al_set_blender(3)
Impressum