Mail Archives: djgpp/1997/04/01/18:12:11
A. Jans-Beken writes:
>In a game I am working on I want objects to cast shadow on the ground.
>With Allegro it is possible for graphic object to regard color 0 as
>transparent. What do I have to do to replace color 1 with the current
>background color minus (for example 3).
Use the draw_trans_sprite() or draw_trans_rle_sprite() functions with a
customised color lookup table. In your startup code, try something along
the lines of:
int i, j;
color_map = malloc(sizeof(COLOR_MAP));
/* source color 0 maps to the unchanged destination color, ie.
* zero source pixels are totally transparent
*/
for (i=0; i<256; i++)
color_map->data[0][i] = i;
/* source color 0 maps to background color minus 3. Alternatively,
* you could do some more flexible remapping that wouldn't need your
* palette to be organised in any particular manner: it's entirely
* up to you...
*/
for (i=0; i<256; i++)
color_map->data[0][i] = i - 3;
/* the rest of the source colors are left unchanged
*/
for (j=2; j<256; j++)
for (i=0; i<256; i++)
color_map->data[j][i] = j;
I haven't actually tested that, but I'm 99% sure it will do what you
want. Let me know if it doesn't work :-)
--
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 -