Game Development Reference
In-Depth Information
Next, you flip the SDL surface based on its resolution (bits per pixel). Listing 3-14 shows
how this is done for an 8-bit RGB surface.
Listing 3-14. Flipping an SDL Surface by Resolution
/**
* Flip SDL Surface by bits per pixel
*/
static void JNI_FlipByBPP (SDL_Surface *surface)
{
int bpp = surface->format->BitsPerPixel;
switch ( bpp ) {
case 8:
JNI_Flip8Bit (surface);
break;
case 16:
// Flip 16bit RGB (surface);
break;
case 32:
// flip 32 bit RGB (surface);
break;
default:
printf("Invalid depth %d for surface of size %dx%d", bpp, surface->w, surface->h);
}
}
/**
* Flip 8bit SDL surface
*/
static void JNI_Flip8Bit(SDL_Surface *surface )
{
int i;
int size = surface->w * surface->h;
int bpp = surface->format->BitsPerPixel;
unsigned short pixels [size]; // RGB565
SDL_Color * colors = surface->format->palette->colors;
for ( i = 0 ; i < size ; i++ ) {
unsigned char pixel = ((unsigned char *)surface->pixels)[i];
pixels[i] = ( (colors[pixel].r >> 3) << 11)
| ( (colors[pixel].g >> 2) << 5)
| (colors[pixel].b >> 3); // RGB565
}
DrawIntoTextureRGB565 (pixels, surface->w, surface->h);
jni_swap_buffers ();
}
Search WWH ::




Custom Search