Game Development Reference
In-Depth Information
In Listing 5-23, the original SDL palette has been replaced by XColor * colours . Note that the
Doom engine uses a 768-color palette (256 colors each for 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 5-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
0xFF << 24 represents the alpha (opacity) value of the pixel—fully visible in this case.
Finally, the array is sent back using the callback jni_send_pixels(pixels) , where Android
will do the rendering.
Listing 5-24. Video Buffer Renderer Function from i_video.c
void I_FinishUpdate (void)
{
if (I_SkipFrame()) return;
// Screen size
int size = SCREENWIDTH * SCREENHEIGHT;
// ARGB pixels
int pixels[size], i;
for ( i = 0 ; i < size ; i ++) {
byte b = screens[0].data[i];
XColor color = colours[b];
pixels[i] = (0xFF << 24)
| (color.red << 16)
| (color.green << 8)
| color.blue;
}
 
 
Search WWH ::




Custom Search