Drawing translucent Bitmap.
coder123

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

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.

Mark Oates

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.)

Thomas Fjellstrom

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.

coder123

Thank you.

That's what I need.

:)

Thread #612132. Printed from Allegro.cc