draw_lit_sprite(3alleg4)

πŸ’– draw_lit_sprite β€” bestie edition πŸ’–

okay so you're in the Allegro manual, page 3alleg4, and today's main character is a little function called draw_lit_sprite ✨


🌈 NAME 🌈

draw_lit_sprite β€” draws a sprite, but make it tinted with a specific color πŸ’… straight from the Allegro game programming library, no cap.


✨ SYNOPSIS ✨

#include <allegro.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, and it depends on your color depth, okay? two whole situations:

In 256-color modes, it uses the global color_map table to tint the sprite image to the specified color, or to light it to the level specified by color β€” which one you get depends entirely on which function you used to build that table (create_trans_table or create_light_table, iykyk). Then it draws the resulting image onto the destination bitmap. πŸŽ€

In truecolor modes, it uses the blender functions to light the sprite image using the alpha level specified by color β€” and yes, the alpha level that was passed to the blender functions is ignored, so don't come for her about it πŸ’€ β€” then it draws the resulting image onto the destination bitmap.

the color parameter must be in the range [0-255] whatever its actual meaning is. like, whatever it's doing in there, the number itself has to live between 0 and 255. periodt.

🫢 lowkey important: this must only be used after you have set up the color mapping table (for 256-color modes) or the blender functions (for truecolor modes). do it out of order and it's giving chaos, bestie.

example time, look at her:

/* Some one time initialisation code. */
COLOR_MAP global_light_table;
create_light_table(&global_trans_table, my_palette,
                   10, 10, 60, NULL);
...
if (get_color_depth() == 8)
   color_map = &global_light_table;
else
   set_trans_blender(40, 40, 255, 255);

/* Lit the cape with a blueish light. */
draw_lit_sprite(buffer, colored_cape, x, y, 64);

πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole vibe check πŸ’œ this was Allegro version 4.4.3, page draw_lit_sprite(3alleg4) β€” slay, go light up some sprites, mwah πŸŽ€πŸ’–βœ¨