Game Development Reference
In-Depth Information
if ((colours == NULL) || (cachedgamma != usegamma)) {
int pplump = W_GetNumForName("PLAYPAL");
int gtlump = (W_CheckNumForName)("GAMMATBL",ns_prboom);
register const byte * palette = W_CacheLumpNum(pplump);
register const byte * const gtable = (const byte *)W_CacheLumpNum(gtlump)
+ 256*(cachedgamma = usegamma);
register int i;
num_pals = W_LumpLength(pplump) / (3*256);
num_pals *= 256;
if (!colours) {
// First call - allocate and prepare colour array
colours = malloc(sizeof(*colours)*num_pals);
}
// set the colormap entries
for (i=0 ; (size_t)i<num_pals ; i++) {
colours[i].red = gtable[palette[0]];
colours[i].green = gtable[palette[1]];
colours[i].blue = gtable[palette[2]];
palette += 3;
}
W_UnlockLumpNum(pplump);
W_UnlockLumpNum(gtlump);
num_pals/=256;
}
}
In Listing 7-23, the original SDL palette has been replaced by XColor * colours . Note that the Doom
engine uses a 768-color palette (256 colors for each one of red, green, and blue). The palette is read from
the game file, along with a gamma table (used to apply a brightness factor to each color). With this
information, the palette is filled and kept in memory for later use.
The final change to i_video.c is the function that does the actual rendering, I_FinishUpdate (see
Listing 7-24). This function uses the width and height of the screen to create an array of pixels (each one
representing an Android packed ARGB color). It then loops through the array and uses the byte value
from the screen buffer to look up the color from the palette:
byte b = screens[0].data[i]; // Video buffer byte
XColor color = colours[b]; // Palette color for that byte
It then constructs a 32-bit pixel using the RGB values of color:
pixels[i] = (0xFF << 24) | (color.red << 16) | (color.green << 8) | color.blue
Note that 0xFF << 24 represents the alpha (opacity) value of the pixel—fully visible in this case.
Search WWH ::




Custom Search