delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/01/18:12:11

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro - shadow of sprites
Date: Tue, 1 Apr 1997 20:34:17 +0100
Organization: None
Distribution: world
Message-ID: <WYzGRbA5MWQzEwWf@talula.demon.co.uk>
References: <33387866 DOT 3593 AT oce DOT nl>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 42
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019