draw_sprite(3)

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

πŸ’– draw_sprite(3) β€” the Allegro manual, but make it slay ✨

okay bestie, welcome to draw_sprite(3) from the Allegro manual πŸŽ€ this one is a certified classic, it's giving "hello I put a sprite on the screen" and honestly? iconic. Allegro game programming library representation fr fr πŸ’…


🌸 NAME 🌸

draw_sprite β€” draws a copy of the sprite onto the destination bitmap. Allegro game programming library.


✨ SYNOPSIS ✨

#include <allegro.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically, bestie: this copies the sprite bitmap onto the destination bitmap at the position you asked for. No cap, that's the whole job.

It's almost the exact same thing as:

blit(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h)

but the way that it differs is that it uses a masked drawing mode where transparent pixels get skipped entirely πŸ™ˆ so the background image shows right on through the masked parts of the sprite. Very "I'm not really there" energy. Main character sprite, invisible background, periodt.

Transparent pixels are marked by:

  • a zero in 256-color modes, or
  • bright pink for truecolor data β€” that's maximum red, maximum blue, and zero green πŸ’–

Example moment, look at her go:

BITMAP *spaceship;
...
draw_sprite(screen, spaceship, x, y);

Okay and now the gfx tea β˜• if the GFX_HW_VRAM_BLIT_MASKED bit in the gfx_capabilities flag is set, then the current driver supports hardware accelerated sprite drawing when the source image is a video memory bitmap or a sub-bitmap of the screen πŸ”₯πŸ”₯ This is extremely fast, so when this flag is set it may genuinely be worth storing some of your more frequently used sprites in an offscreen portion of the video memory. Obsessed, honestly. Store your faves offscreen, they'll pop off instantly πŸ’…

⚠️ Warning bestie, this one matters: if the hardware acceleration flag is not set, draw_sprite() will not work correctly when used with a sprite image in system or video memory β€” so the latter must be a memory bitmap. 😭 No skipping this, fr fr.

And last but absolutely not least 🫢 although Allegro generally doesn't support graphics of mixed color depths, as a special case this function can be used to draw 256-color source images onto truecolor destination bitmaps β€” so you can use palette effects on specific sprites inside a truecolor program. Not me enabling your niche palette aesthetic 😌✨ ate.


πŸ‘‘ SEE ALSO πŸ‘‘

go read these next, bestie, they're all in the same friend group πŸ’œ


that's the whole page, you understood it, I'm so proud of you πŸ₯Ή this was Allegro, version 4.4.3, and yes the vibe check passed πŸŒˆπŸ’– mwah, go draw something cute πŸŽ€βœ¨

πŸ“¦ where this page comes from