draw_trans_sprite(3alleg4)
π NAME π
draw_trans_sprite β bestie, this one draws a sprite and blends it with whatever's already underneath. It's from the Allegro game programming library, and yes it's giving ghost-mode, see-through, translucent icon energy. π»β¨
β¨ SYNOPSIS β¨
#include <allegro.h>
void draw_trans_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y);
π¦ DESCRIPTION π¦
Okay so here's the tea: this function overlays your sprite on top of the existing image, using either the global color_map table or the truecolor blender functions. And no, you can't just call it whenever you feel like it β you must have already set up the color mapping table (that's for your 256-color modes) or the blender functions (that's for truecolor modes) first. Setup first, slay second. π
Now the important part, and I need you to actually listen bestie: this thing reads from the bitmap memory and writes to it. So if you're drawing straight to video RAM, translucent drawing is very slow. Like, painfully slow. Not cute. Wherever you possibly can, use a memory bitmap instead. π
Here's the vibe in code:
/* 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 color depth rules, because there are rules:
- Normally, the bitmap and the sprite have to be in the same color depth. That's the standard situation, no cap.
- BUT there's 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 another one: you can draw 8-bit alpha images onto a 32-bit RGBA destination β as long as you call
set_write_alpha_blender()first.
Also, just like draw_sprite(), this function skips transparent pixels β with one lil exception. If the source sprite is an 8-bit image, it does not skip them the same way, so you need to pay attention and properly set up your color map table for index 0. Don't forget that part or it's gonna look a whole mess. π
β οΈ Real talk: if you skip the color map / blender setup, or you get the color depths mismatched, this is not going to behave. Do the setup. It's the whole point.
πΈ SEE ALSO πΈ
draw_sprite(3alleg4)draw_lit_sprite(3alleg4)draw_trans_rle_sprite(3alleg4)color_map(3alleg4)set_trans_blender(3alleg4)set_alpha_blender(3alleg4)set_write_alpha_blender(3alleg4)bitmap_mask_color(3alleg4)exalpha(3alleg4)exblend(3alleg4)exlights(3alleg4)exrotscl(3alleg4)extrans(3alleg4)exxfade(3alleg4)
And that's the whole page, bestie!! π This was draw_trans_sprite(3alleg4) from Allegro, version 4.4.3 β go forth and blend your sprites responsibly, mwah πππ
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms