[SDL] Best way to implement a simple "Framebuffer"
havoc at ghdigital.com
Mon Sep 26 08:14:21 PDT 2011
Personally this is how I would approach it, assuming we have an SDL_Surface that has been created to point at our unsigned int fb array...
We can just convert the pixels like this.
Then we can scale up using the appropriate SDL blit function.
I could easily have written this routine to do the scale-up while processing pixels but it would be less efficient (assuming a hardware implementation of the SDL blit is used).
// this is in BGRA order (suitable for PC), regardless of native endian order.
const unsigned char colortable[16*4] =
0,0,0,255, // black
255,255,255,255, // white
0,0,135,255, // red
40,240,255,255, // cyan
200,70,200,255, // purple
0,255,0,255, // green
255,0,0,255, // blue
10,220,230,255, // yellow
85,155,230,255, // orange
0,70,100,255, // brown
120,120,255,255, // light red
50,50,50,255, // dark gray
100,100,100,255, // gray
100,255,170,255, // light green
240,160,10,255, // lblue
180,180,180,255, // light grad
// optimized routine for pixel conversion
const unsigned char *pixin = 6502memory + graphix_address; // get the base address of the pixels in the VM
const unsigned int *pal = (const unsigned int *)colortable; // get the palette we'll decode it with
unsigned int *pixout = fb; // get the output address (we have an SDL_Surface whose pixels pointer is this)
for (i = 0;i < 32*32;i++)
pixout[i] = pal[pixin[i]];
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier
More information about the SDL