Using 8 bpp Screens |
Top Previous Next |
When using 8 bpp screen, also known as palletized screens, there are some special functions for setting and using colors. Unlike 16,24 and 32 bpp true color screen the 8 bpp screen uses a palette to store colors and a palette index to specify the color in drawing functions. The palette The palette consists of 256 entries (0 - 255) that can store an RGB color. The palette may be set manually or loaded from a bitmap image. To load a palette from a bitmap image use the LOADPALETTE command. LOADPALETTE only loads the palette data from the image, not the image itself. LOADPALETTE GETSTARTPATH+"pal.bmp" In order for sprites to display in the correct colors on an 8 bpp screen the screens palette must be identical to the sprites. Only 256 color bitmaps can be used properly as sprite images. Setting a palette color can be done using the SETPALETTECOLOR command. SETPALETTECOLOR 2, RGB(255,255,0) Retrieving the color stored in a palette is done with GETPALETTECOLOR col = GETPALETTECOLOR(2) The entire 255 entry palette can be filled with a single color using FILLPALETTE FILLPALETTE RGB(255,255,255)
Fading the screen One of the neat tricks to do with a palletized screen is create a smooth fade to color effect by changing palette values on the fly over time. Use the FADEPALETTE command to achieve this. CREATESCREEN 640,480,8 The time value is specified in 2/25th of a second (0.08). So to specify 8 seconds the value would be 8/.08 = 100. Some common values are: 13 = about 1 second 25 = 2 seconds 50 = 4 seconds 100 = 8 seconds
Use with drawing commands The 2D drawing commands such as DRAWLINE and DRAWRECT accept a palette index directly when using 8 bpp screens. SETPALETTECOLOR 1, RGB(255,0,0) The Emergence BASIC drawing commands require the conversion function PALETTEINDEX to properly work with 8 bpp screens CIRCLE BackBuffer,110,125,50,PALETTEINDEX(3),PALETTEINDEX(4)
Notes Alpha blending is not possible with 8 bpp screens in as much drawing functions that use an alpha value will fail. These include DrawAlphaLine, WriteAlphaPixel and the drawing modes @ALPHA, @TRANSALPHA, and @TRANSSHADOW for sprites. When using direct buffer writing remember that an 8bpp screen uses a single byte for each pixel and each byte is a palette index number, not an RGB color. |