[Wiki] Using custom screen buffer

The Pokitto has several graphic modes. The most common one is 4 bits per pixel (16 colors) at a resolution of 110×88 pixels (which is currently the fastest mode).
There’s also a 220×176 (high resolution) mode, but the default buffer is restricted to 2 bpp (4 colors).

These modes refresh the whole screen every frame, and if your game doesn’t need to refresh the entire screen every frame you could instead use a custom buffer and draw it directly to the screen, for example:

// set the buffer size
uint8_t buffer[((16*16)/2)+2];
// this is( (width * height) / 2pixels per byte )+2 additional bytes

// set the width and height of the buffer for the direct bitmap
buffer[0] = 16;
buffer[1] = 16;

// set the width and height of the display buffer 
game.display.width = 16;
game.display.height = 16;

// set the custom buffer *important to shift it by 2*
game.display.setFrameBufferTo(buffer+2);

while(game.isRunning()){
   // setting game.update to true will stop it from refreshing the screen
   if(game.update(true)){

        //inside your draw routine or gameloop
        game.display.drawBitmap(0,0,sprite);
        //draw the buffer
        game.display.directBitmap(x,y,buffer,4,1);
   }
}

This enables faster frame rates and the ability to swap out the color palettes, giving you more than 16 colors on the screen.

Scrolling the whole screen is a problem though, and will be slow unless you implement something like adaptive tile refresh

3 Likes

this is why its a wiki page you can edit the mistakes

1 Like

Just made a few spelling/grammar edits.
(By some miracle I managed to resist the urge to change the spelling of colour.)


To be honest I’m not sure the title suits the topic.

Maybe the title should be something like “How to use a custom screen buffer” or “An example of a custom screen buffer”?

1 Like