Mail Archives: djgpp/1997/03/04/18:30:05
Chris writes:
> To improve the engine, I want to add some lighting effects using
>Allegro's draw_lit_sprite() to "tint" areas of tiles surrounding a light.
>How do I do this?
Declare a global color mapping table, eg.
COLOR_MAP the_color_map;
This is 64k in size, so you might be better off allocating it on the
heap. In your startup code, write:
create_light_table(&the_color_map, my_palette, 0, 0, 0, NULL);
color_map = &the_color_map;
The table generation function takes a while, so you might prefer to
precalculate the table with the colormap utility, and load it as part of
a datafile. Then to draw your sprites, call draw_lit_sprite() or
draw_lit_rle_sprite() instead of the normal drawing functions, and pass
them a color parameter of 255 to have no effect on the color, 0 to make
the sprite black, and something in between to tint it somewhere between
the two extremes.
If you want to tint the sprites to some color other than black, pass a
color other than "0, 0, 0" to the create_light_table() routine, eg.
"255, 255, 255" to tint the images to white. If you want to tint them in
both directions, you could (a bit more work) use the
create_color_table() function to build a lookup table which will treat
light level 128 as the original color, 0 as black, and 255 as white.
How successful these functions will be is very dependent on your choice
of palette. Being limited to 256 colors, tinting a red pixel towards
black is obviously only going to work if there are some dark reds
available...
/*
* Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
* Beauty is a French phonetic corruption of a short cloth neck ornament.
*/
- Raw text -