Is it possible to acheive "screen" blending with al_set_blender()?
Tumlee

I want to set a certain blending mode that I have used in previous games, called "screen" blending, which results in a color that is always at least as bright as the input colors, but is not the same as additive blending. More details about it can be found here.

Basically, I want the resulting color to be the following:

```r = 1 - ((1 - sr) * (1 - dr));
g = 1 - ((1 - sg) * (1 - dg));
b = 1 - ((1 - sb) * (1 - db));
```

Is this at all possible using al_set_blender() or am I going to have to do this sort of stuff with my own code?

Edgar Reynaldo

Rearrange your formula a bit to see which blender you need :

r = 1 - (1-sr)*(1-dr)
r = 1 - (1 -sr -dr +sr*dr)
r = 1 - 1 + sr + dr - sr*dr
r = 0 + sr + dr - sr*dr

so

r = sr(1 - dr) + dr

or

r = sr + dr(1 - sr)

So, use al_set_blender(ALLEGRO_ADD , ALLEGRO_INVERSE_DEST_COLOR , ALLEGRO_ONE);

or

That should get you your 'screen' blending back.

Tumlee

Thank you very much! It's amazing how I can pass calculus and then trip over my own feet on basic algebra.

Arthur Kalliokoski

It takes constant practice to maintain.