draw_trans_sprite(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

✨ draw_trans_sprite ✨

okay bestie, gather round, because today we're talking about draw_trans_sprite from the Allegro manual πŸ’… this is a function that draws a sprite and blends it with the destination β€” it's from the Allegro game programming library, and it's lowkey iconic for ghost effects 🫢


🌸 SYNOPSIS 🌸

#include <allegro.h>

void draw_trans_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y);

πŸ¦‹ DESCRIPTION πŸ¦‹

so what it does is: it uses the global color_map table, or the truecolor blender functions, to overlay the sprite on top of the existing image ✨

⚠️ important bestie: this must only be used after you've set up the color mapping table (for 256-color modes) or the blender functions (for truecolor modes). no setup, no slay. 😭

and because translucent drawing involves reading as well as writing the bitmap memory, it is very slow if you draw directly to video RAM πŸ’€ so wherever possible you should use a memory bitmap instead. fr fr, take the hint.

example time, look at her go:

/* Some one time initialisation code. */
COLOR_MAP global_trans_table;
create_trans_table(&global_trans_table, my_palette,
                   128, 128, 128, NULL);
...
if (get_color_depth() == 8)
   color_map = &global_trans_table;
else
   set_trans_blender(128, 128, 128, 128);

draw_trans_sprite(buffer, ghost_sprite, x, y);

now, the tea about color depths πŸ“ β€” the bitmap and the sprite must normally be in the same color depth. but as a special case:

  • you can draw 32 bit RGBA format sprites onto any hicolor or truecolor bitmap, as long as you call set_alpha_blender() first πŸ‘‘
  • and you can draw 8-bit alpha images onto a 32-bit RGBA destination, as long as you call set_write_alpha_blender() first πŸ’–

and just like draw_sprite(), this function skips transparent pixels β€” except if the source sprite is an 8-bit image. if that's the case, bestie, you should pay attention to properly setting up your color map table for index 0 πŸ™ˆ don't skip that part, it matters.


🌈 SEE ALSO 🌈


and that's the whole vibe check, bestie πŸŽ€ this was draw_trans_sprite(3) from the Allegro manual, version 4.4.3 β€” go forth and blend your sprites, you absolute main character πŸ’œβœ¨

πŸ“¦ where this page comes from