SYNOPSIS

  • #include <allegro5/allegro.h>
    
    void al_set_blender(int op, int src, int dst)
    
    

DESCRIPTION

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:

\[bu]

ALLEGRO_ADD

  •  r = dr * dst + sr * src
     g = dg * dst + sg * src
     b = db * dst + sb * src
     a = da * dst + sa * src
    
    
\[bu]

ALLEGRO_DEST_MINUS_SRC

  •  r = dr * dst - sr * src
     g = dg * dst - sg * src
     b = db * dst - sb * src
     a = da * dst - sa * src
    
    
\[bu]

ALLEGRO_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

\[bu]

ALLEGRO_ZERO

  •  src = 0
     dst = 0
    
    
\[bu]

ALLEGRO_ONE

  •  src = 1
     dst = 1
    
    
\[bu]

ALLEGRO_ALPHA

  •  src = sa
     dst = sa
    
    
\[bu]

ALLEGRO_INVERSE_ALPHA

  •  src = 1 - sa
     dst = 1 - sa
    
    
\[bu]

ALLEGRO_SRC_COLOR (since: 5.0.10, 5.1.0)

  •  f = s.r, s.g, s.b, s.a
    
    
\[bu]

ALLEGRO_DEST_COLOR (since: 5.0.10, 5.1.8)

  •  f = d.r, d.g, d.b, d.a
    
    
\[bu]

ALLEGRO_INVERSE_SRC_COLOR (since: 5.0.10, 5.1.0)

  •  f = 1 - s.r, 1 - s.g, 1 - s.b, 1 - s.a
    
    
\[bu]

ALLEGRO_INVERSE_DEST_COLOR (since: 5.0.10, 5.1.8)

  •  f = 1 - d.r, 1 - d.g, 1 - d.b, 1 - d.a
    
    

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)
    
    

Multiplying source and destination components

  • al_set_blender(ALLEGRO_ADD, ALLEGRO_DEST_COLOR, ALLEGRO_ZERO)
    
    

RELATED TO al_set_blender…

al_set_separate_blender(3alleg5), al_get_blender(3alleg5)