From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Palettes (or is it palletes?) Date: Thu, 13 Mar 1997 21:12:50 +0000 Organization: None Distribution: world Message-ID: References: <5g8004$dtu AT netra DOT montana DOT edu> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 59 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Paul Peavyhouse writes: > Where I am confused is with all of this "0-63", "0-255", and other >talk about how to use the color_map palette and such to introduce lighting >effects. You don't need to worry about the color mapping tables for most purposes: it's better to get to grips with the basics of how palettes work before you try to use that. In overview, the VGA has 256 colors. When you call putpixel(), line(), or some other drawing function, you pass it a color in the range 0-255, which is written to video memory. The video hardware then uses this color value as an index into a table of 256 entries, called the palette, which determines how that color is displayed on the screen, ie. whether it is red, green, or whatever. Each entry in the palette has three components to specify the amount of red, green, and blue in the color, and these are in the range 0 (none) to 63 (lots). So to display a particular color you must first set a palette entry to the correct combination of red, green, and blue, and then write the number representing that part of the palette to the screen. >use PaintShop to create an image with a palette that fades from black (0,0,0) >to bright green (0,255,0), if I load that image in the program I am writing >and "set_palette(grass_palette);", the results should NOT be cyan?!?!?!?! How are you loading the image? I think you are right that it shouldn't be cyan: can you post some code that demonstrates the trouble? As an example of how to do a fade from black to green, you could write something like: PALETTE mypal; int i; for (i=0; i<256; i++) { /* set up a 256 color palette */ pal[i].r = 0; /* set red component to zero */ pal[i].g = i/4; /* fade from black to green */ pal[i].b = 0; /* set blue component to zero */ } set_palette(mypal); After that you can call whatever drawing functions you like, passing them colors from 0 to 255. Zero is black, 255 is green, and values between the two will come out as somewhere in between. The divide by four is because there are 256 colors in the palette, but only 64 possible levels for the amount of green in the color. This means that colors 0, 1, 2, and 3 will actually be the same, as will colors 4, 5, 6, 7, etc. Hope that helps. Email me privately if there's anything you still need help with. /* * 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. */