al_set_blender
void al_set_blender(int op, int src, int dst)
Introduced in 5.0.0
Sets the function to use for blending for the current thread.
Blending means, the source and destination colors are combined in drawing operations.
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): sr, sg, sb, sa. And this color is drawn to a destination, which already has a color: dr, dg, db, da.
The conceptional formula used by Allegro to draw any pixel then depends on the op parameter:
ALLEGRO_ADD
r = dr * dst + sr * src g = dg * dst + sg * src b = db * dst + sb * src a = da * dst + sa * srcALLEGRO_DEST_MINUS_SRC
r = dr * dst - sr * src g = dg * dst - sg * src b = db * dst - sb * src a = da * dst - sa * srcALLEGRO_SRC_MINUS_DEST
r = sr * src - dr * dst g = sg * src - dg * dst b = sb * src - db * dst a = sa * src - da * dst
Valid values for src and dst passed to this function are
ALLEGRO_ZERO
src = 0 dst = 0ALLEGRO_ONE
src = 1 dst = 1ALLEGRO_ALPHA
src = sa dst = saALLEGRO_INVERSE_ALPHA
src = 1 - sa dst = 1 - sa
Blending examples:
So for example, to restore the default of using premultiplied alpha blending, you would use (pseudo code)
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA)If you are using non-pre-multiplied alpha, you could use
al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA)Additive blending would be achieved with
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE)Copying the source to the destination (including alpha) unmodified
al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO)See also: al_set_separate_blender, al_get_blender
Examples: ex_bitmap_flip, ex_bitmap_target, ex_blend, ex_blend2, ex_blend_bench, ex_blend_test, ex_blit, ex_clip, ex_display_options, ex_draw, ex_draw_bitmap, ex_expose, ex_haiku, ex_lines, ex_logo, ex_membmp, ex_mixer_pp, ex_mouse_cursor, ex_mouse_events, ex_native_filechooser, ex_pixelformat, ex_premulalpha, ex_prim, ex_rotate, ex_scale, ex_stream_seek, ex_threads, ex_threads2, ex_transform, ex_windows
Most helpful discussions:
- [Allegro 5.0.10] Lightning with blenders (1)
- [A5] Blender (1)
- A5 - printing text to memory bitmap (1)
- Is it possible to acheive "screen" blending with al_set_blender()? (1)
- al_set_blender and al_draw_tinted_bitmap (1)
- Blending issues (1)
- [a5 rc4] anomalous blending (1)
- KrampusHack 2016
- Complications when drawing FPS
- Further question regarding camera and projection transforms
Other recent discussions:
- Font loading crashing with Allegro 5.2
- Still trying to debug ManyMouse and al_set_target_bitmap
- What's the blending mode settings for write alpha?
- Lightning with some light points
- Mask / combine bitmaps
- Lighting using too much cpu
- Image transition too slow !
- Blit to Android display
- al_set_separate_blender() help
- Allegro 5.1.12 released!