draw_character_ex(3)

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

πŸ’… draw_character_ex β€” NAME

ok so bestie, this is draw_character_ex, page three of the Allegro manual, and it Draws non transparent pixels of the sprite with a color. it lives in the Allegro game programming library, which is the whole vibe. πŸŽ€


✨ SYNOPSIS ✨

#include <allegro.h>

void draw_character_ex(BITMAP *bmp, BITMAP *sprite, int x, int y, color,
bg);

no cap, that's the whole signature. yes the color and bg params forgot their types in the listing, but that's literally how it's written, so we're keeping it exactly like that. 🫢


🌸 DESCRIPTION 🌸

okay so here's the tea. draw_character_ex takes a copy of the sprite bitmap and draws it onto the destination bitmap at the position you asked for β€” but with a glow-up. the transparent pixels get drawn in the background color instead (or just skipped entirely if the background color is -1), and every other pixel β€” all the not-transparent ones β€” gets set to the color you specified. it's giving silhouette mode. it's giving stencil. obsessed. πŸ”₯

and how do we know which pixels are "transparent"?? bestie, the rules are:

  • in 256-color modes, a transparent pixel is marked by a zero
  • in truecolor data, it's bright pink (which means maximum red and blue, and zero green) πŸ’—
⚠️ IMPORTANT, no cap: the sprite must be an 8-bit image, even if the destination is a truecolor bitmap. that's the rule, don't fight it. πŸ™ˆ

Example time, because examples slay:

BITMAP *logo;
...
/* Draw the logo silhouette in red. */
draw_character_ex(screen, logo, SCREEN_W / 2, SCREEN_H / 2,
                  makecol(255, 0, 0), -1);

look at that. logo silhouette. dead center. red. -1 for the bg so the transparent pixels just dip out entirely instead of getting painted over. main character energy fr fr. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, iykyk, they're part of the same little friend group πŸ’œ


and that's the whole page!! this was Allegro, version 4.4.3, and it's the draw_character_ex(3) page β€” ty for coming to my ted talk, go draw something cute, mwah πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from