Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Drawing translucent Bitmap.

This thread is locked; no one can reply to it. rss feed Print
Drawing translucent Bitmap.
coder123
Member #14,305
May 2012

Hi,
I draw a bitmap in normal mode but in certain
condition I want to draw it in translucent mode.(Look like disable)

In this way I draw the bitmap:

al_draw_bitmap_region(BTNBMP, curFrame, framePos, frameWidth, frameHeight, cx, cy, 0);

Using A5.

Thomas Fjellstrom
Member #476
June 2000
avatar

I believe you want al_draw_tinted_bitmap_region.

ie: al_draw_tinted_bitmap_region(bitmap, al_map_rgba_f(1, 1, 1, 0.5), sx, sy, sw, sh, dx, dy, 0);

Will draw the bitmap at 50% translucency.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Mark Oates
Member #1,146
March 2001
avatar

ie: al_draw_tinted_bitmap_region(bitmap, al_map_rgba_f(1, 1, 1, 0.5), sx, sy, sw, sh, dx, dy, 0);

You should multiply each of the color components by the opacity:

float opacity = 0.5;
ALLEGRO_COLOR tint = al_map_rgba_f(1*opacity, 1*opacity, 1*opacity, opacity);
al_draw_tinted_bitmap_region(bitmap, tint, sx, sy, sw, sh, dx, dy, 0);

(interesting fact: "tint" is not the correct term in color theory for this type of color change, but it's what allegro uses.)

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Thomas Fjellstrom
Member #476
June 2000
avatar

Hm, I grabbed that example from the docs. but I think you're right. To use the code I gave, you'd have to disable pre-multiplied alpha.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

coder123
Member #14,305
May 2012

Thank you.

That's what I need.

:)

Go to: