From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Allegro won't display more than 1 PCX (properly)!!! Date: Mon, 27 Jan 1997 22:29:38 +0000 Organization: None Distribution: world Message-ID: <$siMMLBSxS7yEwsE@talula.demon.co.uk> References: <5ce17t$68h AT news DOT interlog DOT com> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 53 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Gautam N. Lad writes: >I modified the example EX15.C source to display two different PCXs. >So, here's the code. Now what I don't understand is why >does Allegro use one palette to display an image, and when another >palette is created for another image, that original palette >gets screwed up, and starts using the palette from the new palette. It does that because that's how the hardware works... I'll have a go at describing what is going on, but palettes aren't the easiest concept to get to grips with. For a better explanation, download the PCGPE from x2ftp and read Denthor's article in tut2.txt. The examples are all in Pascal, but he explains it very clearly. In a 256 color graphics mode, each pixel is stored in video memory as a single byte, containing a number 0-255. These numbers don't represent colors directly - they are indexes into a table called the palette, which lists what color each of the 256 possible pixel values refers to. So when the video hardware sees a pixel with a value of 10, it goes and grabs the tenth entry from the palette and displays that color on your monitor. It could be red, it could be blue, it all depends what you put in the palette. This means that displaying an image must be done in two steps. First, set the palette registers to tell the hardware which 256 colors you want to use. Then you can copy the pixels to the screen, and they will come out looking right. When you change the palette it affects all the pixels on the screen, not just the ones that are drawn after you make the change. To display two PCX images side by side, they will have to be using the same palette. The easiest way to do this is with a paint program or a conversion tool like Image Alchemy. It can be done in your code, of course, but generating an optimal palette for merging two bitmaps is a non-trivial task... This may seem awkward, but once you get the hang of them palettes can be used to great effect. Once you have drawn a graphics onto the screen, you can totally change it's color just by altering a few palette registers (much faster than redrawing the image itself). Hence you can get nice smooth fade out effects by altering the entire palette to gradually make all the entries black. Or you can tint the entire palette to a different color (how do you think Doom makes the screen go red when you are about do die?). Or you can rapidly cycle a few of the palette colors to get very efficient animation effects (waterfalls being the most common use - I'm not sure I've ever seen a platform game that doesn't have a palette-cycled waterfall in it somewhere :-) /* * 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'. */