Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_set_blender and al_draw_tinted_bitmap

This thread is locked; no one can reply to it. rss feed Print
al_set_blender and al_draw_tinted_bitmap
Schyfis
Member #9,752
May 2008
avatar

I searched a bit and played with various calls to al_set_blender and al_set_separate_blender, but now I'm pretty sure this is an Allegro bug or oversight.

What I'm trying to do is port some existing XNA code over to Allegro, and part of that involves drawing an image using additive blending, but at 50% opacity. As far as I can tell, Allegro should be capable of this if I use al_set_blender and al_draw_tinted_bitmap, but it doesn't work as expected.

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
al_draw_tinted_bitmap(current_buffer, al_map_rgba_f(1, 1, 1, 0.5f), 0, 0, 0);

Even if I change the 0.5f to 0, it will still be drawn at 100% opacity. The red, green, and blue values work as expected with additive blending, but not alpha.

I'm using Allegro 5.0.9.

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

Jeff Bernard
Member #6,698
December 2005
avatar

Use the default blender (don't call al_set_blender).

--
I thought I was wrong once, but I was mistaken.

kazzmir
Member #1,786
December 2001
avatar

I do this all the time (exactly the way you described) but I use ALLEGRO_ALPHA and ALLEGRO_INVERSE_ALPHA.

al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);

tobing
Member #5,213
November 2004
avatar

Try it with ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA.

Schyfis
Member #9,752
May 2008
avatar

Use the default blender (don't call al_set_blender).

If I do that, it's not drawn using additive blending...

kazzmir said:

I do this all the time (exactly the way you described) but I use ALLEGRO_ALPHA and ALLEGRO_INVERSE_ALPHA.

tobing said:

Try it with ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA.

I tried this, but it doesn't give the desired effect.
{"name":"607330","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/2\/a2de032033c4340b3980591b20152f57.png","w":960,"h":303,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/2\/a2de032033c4340b3980591b20152f57"}607330

The original is drawn first, then the glow is drawn on top of it using an additive blender and at 50% opacity. The third picture should be the same as the second picture, but Allegro isn't doing anything with the alpha channel. Even if it's zero, it'll still look like the third picture.

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

Trent Gamblin
Member #261
April 2000
avatar

Show code 'cuz you're doing it wrong.

EDIT: nvm, you showed enough code. Allegro uses premultiplied alpha, so your color should be al_map_rgba_f(color.r*a, color.g*a, color.b*a, a).

Schyfis
Member #9,752
May 2008
avatar

Argh, why didn't I think of that?! Using additive blending, doing that is exactly the same as changing the alpha! I guess I was looking at it for too long.

Thanks for the fix, it now looks almost exactly the same as my XNA implementation!

*gives cookies*

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

Go to: