Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Is it possible to acheive "screen" blending with al_set_blender()?

This thread is locked; no one can reply to it. rss feed Print
Is it possible to acheive "screen" blending with al_set_blender()?
Tumlee
Member #15,061
April 2013

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
Major Reynaldo
May 2007
avatar

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
al_set_blender(ALLEGRO_ADD , ALLEGRO_ONE , ALLEGRO_INVERSE_SRC_COLOR);

That should get you your 'screen' blending back.

Tumlee
Member #15,061
April 2013

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

Arthur Kalliokoski
Second in Command
February 2005
avatar

It takes constant practice to maintain.

They all watch too much MSNBC... they get ideas.

Go to: