Mail Archives: djgpp/1997/01/04/14:15:05
From: | Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Drawing in diffrent colours in Allegro
|
Date: | Sat, 4 Jan 1997 14:13:43 +0000
|
Organization: | None
|
Lines: | 57
|
Distribution: | world
|
Message-ID: | <KI7BVBAXWmzyEwIM@talula.demon.co.uk>
|
References: | <5ak513$680 AT news1 DOT io DOT org>
|
NNTP-Posting-Host: | talula.demon.co.uk
|
MIME-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Andrew Ellem writes:
>I'd like some help on how to draw the same sprite in diffrent
>colours using Allegro. I would like to draw a sprite, changing
>all bytes x to y.
>
>Something like this :
>draw_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int c1, int c2);
>Where every c1 in the sprite would be changed to c2, in addition
>to ignoring the 0's.
I can think of three approaches:
You could preprocess your sprites into all the different colors you
need. Easy, but could take up a lot of space depending how many
different versions you have.
Alternatively you could write your own sprite drawer. Off the top of my
head, something like:
#include <sys/farptr.h>
draw_thingy(BITMAP *bmp, BITMAP *sprite, int x, int y, int c1, int c2)
{
int xpos, ypos, pix;
unsigned long address;
_farsetsel(bmp->seg);
for (ypos=0; ypos<sprite->h; ypos++) {
address = bmp_write_line(bmp, y+ypos) + x;
for (xpos=0; xpos<sprite->w; xpos++) {
pix = sprite->line[ypos][xpos];
if (pix) {
if (pix == c1)
pix = c2;
_farnspokeb(address+xpos, pix);
}
}
}
}
That should work for everything except mode-X screen bitmaps, although I
have to admit I haven't actually tested it :-) It doesn't do any
clipping, but I expect the speed will be adequate for most purposes...
Another possibility is to wait until I finish the translucency/lighting
code I'm working on at the moment. This will use a lookup table to blend
colors, and will provide several ways of drawing sprites, including one
which tints them to a different color using a lookup table to map every
color into a different color. Set up the lookup table correctly, and
you'll be able to do any number of c1->c2 conversions in a single step.
No promises how long this will take me to implement, though :-)
/*
* Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
* Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
*/
- Raw text -