[a5] set_multiply_blender

What is the A5 equivalent of set_multiply_blender / draw_trans_sprite?


draw_trans_sprite = al_convert_mask_to_alpha?

The other one I have no idea.


Sorry I meant the combination of set_multiply_blender with draw_trans_sprite. I want to get that effect.

al_draw_tinted_bitmap is effectively equal to draw_trans_sprite with the right blender set.


For someone not knowing what those A4 functions do - what is the effect you want?


Well here is the description from allegro.txt:


void set_multiply_blender(int r, int g, int b, int a);
Enables a multiply blender mode for combining translucent or lit
truecolor pixels. Combines the source and destination images, multiplying
the colours to produce a darker colour. If a colour is multiplied by
white it remains unchanged; when multiplied by black it also becomes

I don't know how to describe what the blender is doing any other way. Its implemented by multiplying the individual components of the two colors (source and destination). Here is the code I use in sdl which was copied from allegro4.

1 2static inline unsigned int transBlender(unsigned int x, unsigned int y, unsigned int n){ 3 unsigned long result; 4 5 if (n) 6 n = (n + 1) / 8; 7 8 /* hex: 0x7E0F81F 9 * binary: 0111 1110 0000 1111 1000 0001 1111 10 */ 11 x = ((x & 0xFFFF) | (x << 16)) & 0x7E0F81F; 12 y = ((y & 0xFFFF) | (y << 16)) & 0x7E0F81F; 13 14 result = ((x - y) * n / 32 + y) & 0x7E0F81F; 15 16 return ((result & 0xFFFF) | (result >> 16)); 17} 18 19static inline unsigned int multiplyBlender(unsigned int x, unsigned int y, unsigned int n){ 20 Uint8 redX = 0; 21 Uint8 greenX = 0; 22 Uint8 blueX = 0; 23 SDL_GetRGB(x, &format565, &redX, &greenX, &blueX); 24 Uint8 redY = 0; 25 Uint8 greenY = 0; 26 Uint8 blueY = 0; 27 SDL_GetRGB(y, &format565, &redY, &greenY, &blueY); 28 29 int r = redX * redY / 256; 30 int g = greenX * greenY / 256; 31 int b = blueX * blueY / 256; 32 return transBlender(makeColor(r, g, b), y, n); 33}

Where x is source, y is destination, and n is the current alpha value.

Mark Oates

trans sprite is going to be

float alpha = 0.1;
al_draw_tinted_bitmap(bmp, al_map_rgba_f(alpha, alpha, alpha, alpha), x, y, NULL);

There is no multiply blender. The closest thing you can get to is the subtractive blender:


or make a shader :-/


Are all the hardware blenders implemented in scanline_drawers.c? Couldn't a new blender be added that did

r = dr * dst * sr * sa;

Or am I missing how the blenders are associated with hardware acceleration?

Thomas Fjellstrom

Those are software blenders. They are used on locked bitmaps, or memory bitmaps.


So yes, if you want to add it, you need to add it to the software blenders, but also for OpenGL and DirectX.

For OpenGL it would be almost trivial, what you need is probably either the SRC_COLOR or DST_COLOR blend factor (in A5 it would be another blend factor like ALLEGRO_ALPHA mapped 1:1 to it, ALLEGRO_SOURCE_COLOR and ALLEGRO_DESTINATION_COLOR maybe):


No idea about DirectX but since GPUs support it DirectX most likely also supports it somehow.

Thread #607480. Printed from Allegro.cc