Raspberry Pi and SDL

A brief note on using SDL on the Raspberry Pi

Just a few notes to highlight some of the issues I’ve had with the Simple Direct Media (SDL) libraries and the Raspberry Pi. Most of this is to do with using it in direct framebuffer mode, but also applicable to running under X.

The first, which seems obvious is that the Pi has a 16 bit per pixel framebuffer (although I understand this can be changed somehow). So when I ported my application (BASIC) to the Pi, it worked fine, but was slow! Presumably due to SDL doing the conversion from 32bpp to 16bpp for every SD_FLip() or SDL_UpateRect() call.

Once I switched to 16bpp, then things started to move a lot faster!

The other issue appears to be with running in SDL_HWSURFACE and/or SDL_DOUBLEBUF modes. On the console these appear to either crash the Pi, or cause writes to NOT be double buffered, but to go directly to the visible framebuffer memory!

It’s possible this is due to a bug in the SDL driver, a bug in the Raspbrtty Pi framebuffer driver, or a combination of both. It’s also possible it’s something else, but tracking it down is going to be time consuming.

Another issue is the actual screen size on the Pi. It’s variable. Very variable, so important to do a

videoInfo  = SDL_GetVideoInfo () ;

then to use use the videoInfo->current_w, videoInfo->current_h and videoInfo->vfmt->BitsPerPixel values.

But do check when running under X – in this case I’m using a default X and Y size.

Comments

Raspberry Pi and SDL — 6 Comments

  1. “The other issue appears to be with running in SDL_HWSURFACE and/or SDL_DOUBLEBUF modes. On the console these appear to either crash the Pi, or cause writes to NOT be double buffered, but to go directly to the visible framebuffer memory!”

    Do you get the same problems running with SDL_SWSURFACE, or is it purely with SDL_HWSURFACE?

  2. Hi Gordon,

    You said “Once I switched to 16bpp, then things started to move a lot faster!” – how did you do this? I’m trying to get some nice, smooth fading of images using PyGame. I have the fading working very nicely on a 32bpp display, but run it on the Pi and the 16bpp becomes evident and quite nasty.

    • Fetch the source code for my BASIC interpreter and have a look at screenKeyboard.c. It’s all in there.

      -Gordon

      • I switched my depth to 16 and things sped up a little, thanks for the tip… but my png’s are probably 32bit.. does this matter?

        • It probably doesn’t matter, but something, somewhere will be converting PNGs into 16-bit format which may add in a bit of slowness..

          -Gordon