File: al_set_blender.3

package info (click to toggle)
allegro5 2%3A5.2.6.0-3%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 24,212 kB
  • sloc: ansic: 125,319; cpp: 15,781; objc: 4,579; python: 2,802; java: 2,254; javascript: 1,204; sh: 1,002; makefile: 51; perl: 37; xml: 25; pascal: 24
file content (264 lines) | stat: -rw-r--r-- 4,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
.\" Automatically generated by Pandoc 1.19.2.4
.\"
.TH "al_set_blender" "3" "" "Allegro reference manual" ""
.hy
.SH NAME
.PP
al_set_blender \- Allegro 5 API
.SH SYNOPSIS
.IP
.nf
\f[C]
#include\ <allegro5/allegro.h>

void\ al_set_blender(int\ op,\ int\ src,\ int\ dst)
\f[]
.fi
.SH DESCRIPTION
.PP
Sets the function to use for blending for the current thread.
.PP
Blending means, the source and destination colors are combined in
drawing operations.
.PP
Assume the source color (e.g.
color of a rectangle to draw, or pixel of a bitmap to draw) is given as
its red/green/blue/alpha components (if the bitmap has no alpha it
always is assumed to be fully opaque, so 255 for 8\-bit or 1.0 for
floating point): \f[I]s = s.r, s.g, s.b, s.a\f[].
And this color is drawn to a destination, which already has a color:
\f[I]d = d.r, d.g, d.b, d.a\f[].
.PP
The conceptional formula used by Allegro to draw any pixel then depends
on the \f[C]op\f[] parameter:
.IP \[bu] 2
ALLEGRO_ADD
.RS 2
.IP
.nf
\f[C]
\ r\ =\ d.r\ *\ df.r\ +\ s.r\ *\ sf.r
\ g\ =\ d.g\ *\ df.g\ +\ s.g\ *\ sf.g
\ b\ =\ d.b\ *\ df.b\ +\ s.b\ *\ sf.b
\ a\ =\ d.a\ *\ df.a\ +\ s.a\ *\ sf.a
\f[]
.fi
.RE
.IP \[bu] 2
ALLEGRO_DEST_MINUS_SRC
.RS 2
.IP
.nf
\f[C]
\ r\ =\ d.r\ *\ df.r\ \-\ s.r\ *\ sf.r
\ g\ =\ d.g\ *\ df.g\ \-\ s.g\ *\ sf.g
\ b\ =\ d.b\ *\ df.b\ \-\ s.b\ *\ sf.b
\ a\ =\ d.a\ *\ df.a\ \-\ s.a\ *\ sf.a
\f[]
.fi
.RE
.IP \[bu] 2
ALLEGRO_SRC_MINUS_DEST
.RS 2
.IP
.nf
\f[C]
\ r\ =\ s.r\ *\ sf.r\ \-\ d.r\ *\ df.r
\ g\ =\ s.g\ *\ sf.g\ \-\ d.g\ *\ df.g
\ b\ =\ s.b\ *\ sf.b\ \-\ d.b\ *\ df.b
\ a\ =\ s.a\ *\ sf.a\ \-\ d.a\ *\ df.a
\f[]
.fi
.RE
.PP
Valid values for the factors \f[C]sf\f[] and \f[C]df\f[] passed to this
function are as follows, where \f[C]s\f[] is the source color,
\f[C]d\f[] the destination color and \f[C]cc\f[] the color set with
al_set_blend_color(3) (white by default)
.IP \[bu] 2
ALLEGRO_ZERO
.RS 2
.IP
.nf
\f[C]
\ f\ =\ 0,\ 0,\ 0,\ 0
\f[]
.fi
.RE
.IP \[bu] 2
ALLE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\ 1\ \-\ cc.b,\ 1\ \-\ cc.a
\f[]
.fi
.RE
.PP
Blending examples:
.PP
So for example, to restore the default of using premultiplied alpha
blending, you would use:
.IP
.nf
\f[C]
al_set_blender(ALLEGRO_ADD,\ ALLEGRO_ONE,\ ALLEGRO_INVERSE_ALPHA);
\f[]
.fi
.PP
As formula:
.IP
.nf
\f[C]
r\ =\ d.r\ *\ (1\ \-\ s.a)\ +\ s.r\ *\ 1
g\ =\ d.g\ *\ (1\ \-\ s.a)\ +\ s.g\ *\ 1
b\ =\ d.b\ *\ (1\ \-\ s.a)\ +\ s.b\ *\ 1
a\ =\ d.a\ *\ (1\ \-\ s.a)\ +\ s.a\ *\ 1
\f[]
.fi
.PP
If you are using non\-pre\-multiplied alpha, you could use
.IP
.nf
\f[C]
al_set_blender(ALLEGRO_ADD,\ ALLEGRO_ALPHA,\ ALLEGRO_INVERSE_ALPHA);
\f[]
.fi
.PP
Additive blending would be achieved with
.IP
.nf
\f[C]
al_set_blender(ALLEGRO_ADD,\ ALLEGRO_ONE,\ ALLEGRO_ONE);
\f[]
.fi
.PP
Copying the source to the destination (including alpha) unmodified
.IP
.nf
\f[C]
al_set_blender(ALLEGRO_ADD,\ ALLEGRO_ONE,\ ALLEGRO_ZERO);
\f[]
.fi
.PP
Multiplying source and destination components
.IP
.nf
\f[C]
al_set_blender(ALLEGRO_ADD,\ ALLEGRO_DEST_COLOR,\ ALLEGRO_ZERO)
\f[]
.fi
.PP
Tinting the source (like al_draw_tinted_bitmap(3))
.IP
.nf
\f[C]
al_set_blender(ALLEGRO_ADD,\ ALLEGRO_CONST_COLOR,\ ALLEGRO_ONE);
al_set_blend_color(al_map_rgb(0,\ 96,\ 255));\ /*\ nice\ Chrysler\ blue\ */
\f[]
.fi
.PP
Averaging source and destination pixels
.IP
.nf
\f[C]
al_set_blender(ALLEGRO_ADD,\ ALLEGRO_CONST_COLOR,\ ALLEGRO_CONST_COLOR);
al_set_blend_color(al_map_rgba_f(0.5,\ 0.5,\ 0.5,\ 0.5));
\f[]
.fi
.PP
As formula:
.IP
.nf
\f[C]
r\ =\ d.r\ *\ 0\ +\ s.r\ *\ d.r
g\ =\ d.g\ *\ 0\ +\ s.g\ *\ d.g
b\ =\ d.b\ *\ 0\ +\ s.b\ *\ d.b
a\ =\ d.a\ *\ 0\ +\ s.a\ *\ d.a
\f[]
.fi
.SH SEE ALSO
.PP
al_set_separate_blender(3), al_set_blend_color(3), al_get_blender(3)