SDL is a library for writing cross-platform programs that make use of graphics and other multimedia elements.

While, working on an SDL2-based program, I updated the Raspberry Pi to used SDL 2.0.5. The one that came with the Pi seems to want to run under X11, whereas I wanted my app to run directly from the console. Also, SDL 2.0.5 uses hardware-accelerated OpenGL ES2 rendering for the frame buffer.

You probably won't need this if using Raspbian Stretch as it already bundles SDL 2.0.5.

I based my notes from the great instructions here http://choccyhobnob.com/tutorials/sdl2-2-0-5-on-raspberry-pi/.

  • Remove distro's SDL2 (which is SDL2-2.0.2)
    • sudo apt-get remove -y --force-yes libsdl2-dev
    • sudo apt-get autoremove -y
  • Build Environment
    • sudo apt-get update
    • sudo apt-get install libfontconfig-dev qt5-default automake mercurial libtool libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile-dev libudev-dev libtiff5-dev libwebp-dev libasound2-dev libaudio-dev libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxss-dev libesd0-dev freeglut3-dev libmodplug-dev libsmpeg-dev
  • Build SDL2 2.05
    • cd ~/src
    • wget http://www.libsdl.org/release/SDL2-2.0.5.tar.gz
    • tar zxvf SDL2-2.0.5.tar.gz
    • cd SDL2-2.0.5
    • bash ./autogen.sh
    • Note:
      • for below "--host=armv7l-raspberry-linux-gnueabihf" is for ARM7 (Pi2 or Pi3)
      • Remove --prefix=/usr if you want to install into /usr/local
    • If you want SDL with X11:
      • ./configure --prefix=/usr --host=armv7l-raspberry-linux-gnueabihf -disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-opengl
    • Otherwise:
      • ./configure --prefix=/usr --host=armv7l-raspberry-linux-gnueabihf --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11 --disable-video-opengl --disable-static
      • SDL2 Configure Summary:
        • Building Shared Libraries
        • Building Static Libraries
        • Enabled modules : atomic audio video render events joystick haptic power filesystem threads timers file loadso cpuinfo assembly
        • Assembly Math :
        • Audio drivers : disk dummy oss alsa(dynamic) nas(dynamic)
        • Video drivers : rpi dummy opengl_es1 opengl_es2
        • Input drivers : linuxev linuxkd
        • Using libudev : YES
        • Using dbus : YES
        • Using ime : YES
        • Using ibus : NO
        • Using fcitx : NO
    • make -j4
    • sudo make install
    • cd ..
  • Download Others
    • cd ~/src
    • wget http://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz
    • wget http://www.libsdl.org/projects/smpeg/release/smpeg2-2.0.0.tar.gz
    • wget http://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.tar.gz
    • wget http://www.libsdl.org/projects/SDL_net/release/SDL2_net-2.0.1.tar.gz
    • wget http://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz
  • Uncompress
    • tar zxvf SDL2_image-2.0.1.tar.gz
    • tar zxvf smpeg2-2.0.0.tar.gz
    • tar zxvf SDL2_mixer-2.0.1.tar.gz
    • tar zxvf SDL2_net-2.0.1.tar.gz
    • tar zxvf SDL2_ttf-2.0.14.tar.gz
  • Build Image Library
    • cd SDL2_image-2.0.1
    • ./autogen.sh
    • ./configure --prefix=/usr
    • make -j4
    • sudo make install
    • cd ..
  • Build MPEG Decoder
    • cd smpeg2-2.0.0
    • ./autogen.sh
    • ./configure --prefix=/usr
    • make -j4
    • sudo make install
    • cd ..
  • Build AudioMixer
    • cd SDL2_mixer-2.0.1
    • ./autogen.sh
    • ./configure --prefix=/usr
    • make -j4
    • sudo make install
    • cd ..
  • Build Networking Library
    • cd SDL2_net-2.0.1
    • ./autogen.sh
    • ./configure --prefix=/usr
    • make -j4
    • sudo make install
    • cd ..
  • Build TrueType Font Library
    • cd SDL2_ttf-2.0.14
    • ./autogen.sh
    • ./configure --prefix=/usr
    • make -j4
    • sudo make install
    • cd ..

  • To compile an app locally:
    • g++ -std=c++11 -Wall -pedantic sdl2_test.cpp -o sdl2_test `sdl2-config --cflags --libs`
  • "sdl2-config --cflags --libs" has the following output:
    • -I/usr/include/SDL2 -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -D_REENTRANT
    • -L/usr/lib -Wl,-rpath,/usr/lib -Wl,--enable-new-dtags -lSDL2
  • files installed:
    • /usr/include:
      • /usr/include/SDL2
      • /usr/include/SDL2/SDL_opengles2.h
      • /usr/include/SDL2/SDL_joystick.h
      • /usr/include/SDL2/SDL_timer.h
      • /usr/include/SDL2/SDL.h
      • /usr/include/SDL2/SDL_mutex.h
      • /usr/include/SDL2/SDL_blendmode.h
      • /usr/include/SDL2/SDL_opengles2_khrplatform.h
      • /usr/include/SDL2/SDL_test_assert.h
      • /usr/include/SDL2/SDL_scancode.h
      • /usr/include/SDL2/SDL_opengles2_gl2ext.h
      • /usr/include/SDL2/SDL_types.h
      • /usr/include/SDL2/SDL_keyboard.h
      • /usr/include/SDL2/SDL_gesture.h
      • /usr/include/SDL2/SDL_quit.h
      • /usr/include/SDL2/SDL_revision.h
      • /usr/include/SDL2/SDL_keycode.h
      • /usr/include/SDL2/SDL_atomic.h
      • /usr/include/SDL2/SDL_audio.h
      • /usr/include/SDL2/close_code.h
      • /usr/include/SDL2/SDL_rect.h
      • /usr/include/SDL2/SDL_error.h
      • /usr/include/SDL2/SDL_gamecontroller.h
      • /usr/include/SDL2/SDL_endian.h
      • /usr/include/SDL2/SDL_syswm.h
      • /usr/include/SDL2/SDL_power.h
      • /usr/include/SDL2/SDL_test_font.h
      • /usr/include/SDL2/SDL_opengles.h
      • /usr/include/SDL2/SDL_opengles2_gl2platform.h
      • /usr/include/SDL2/SDL_image.h
      • /usr/include/SDL2/SDL_platform.h
      • /usr/include/SDL2/SDL_test_log.h
      • /usr/include/SDL2/SDL_log.h
      • /usr/include/SDL2/SDL_opengles2_gl2.h
      • /usr/include/SDL2/SDL_test_crc32.h
      • /usr/include/SDL2/SDL_system.h
      • /usr/include/SDL2/SDL_egl.h
      • /usr/include/SDL2/SDL_test_common.h
      • /usr/include/SDL2/SDL_mouse.h
      • /usr/include/SDL2/SDL_shape.h
      • /usr/include/SDL2/SDL_pixels.h
      • /usr/include/SDL2/SDL_ttf.h
      • /usr/include/SDL2/SDL_rwops.h
      • /usr/include/SDL2/SDL_thread.h
      • /usr/include/SDL2/SDL_opengl_glext.h
      • /usr/include/SDL2/SDL_clipboard.h
      • /usr/include/SDL2/SDL_render.h
      • /usr/include/SDL2/SDL_net.h
      • /usr/include/SDL2/SDL_touch.h
      • /usr/include/SDL2/SDL_filesystem.h
      • /usr/include/SDL2/SDL_main.h
      • /usr/include/SDL2/SDL_stdinc.h
      • /usr/include/SDL2/SDL_messagebox.h
      • /usr/include/SDL2/SDL_assert.h
      • /usr/include/SDL2/SDL_test_md5.h
      • /usr/include/SDL2/SDL_config.h
      • /usr/include/SDL2/SDL_version.h
      • /usr/include/SDL2/SDL_test_random.h
      • /usr/include/SDL2/begin_code.h
      • /usr/include/SDL2/SDL_surface.h
      • /usr/include/SDL2/SDL_mixer.h
      • /usr/include/SDL2/SDL_test_fuzzer.h
      • /usr/include/SDL2/SDL_video.h
      • /usr/include/SDL2/SDL_test_images.h
      • /usr/include/SDL2/SDL_name.h
      • /usr/include/SDL2/SDL_loadso.h
      • /usr/include/SDL2/SDL_test_compare.h
      • /usr/include/SDL2/SDL_events.h
      • /usr/include/SDL2/SDL_test_harness.h
      • /usr/include/SDL2/SDL_cpuinfo.h
      • /usr/include/SDL2/SDL_test.h
      • /usr/include/SDL2/SDL_bits.h
      • /usr/include/SDL2/SDL_hints.h
      • /usr/include/SDL2/SDL_haptic.h
      • /usr/include/SDL2/SDL_opengl.h
      • /usr/include/smpeg2
      • /usr/include/smpeg2/smpeg.h
      • /usr/include/smpeg2/MPEGvideo.h
      • /usr/include/smpeg2/MPEGsystem.h
      • /usr/include/smpeg2/MPEGframe.h
      • /usr/include/smpeg2/MPEG.h
      • /usr/include/smpeg2/MPEGaudio.h
      • /usr/include/smpeg2/MPEGlist.h
      • /usr/include/smpeg2/MPEGstream.h
      • /usr/include/smpeg2/MPEGerror.h
      • /usr/include/smpeg2/MPEGring.h
      • /usr/include/smpeg2/MPEGaction.h
    • /usr/local/lib:
      • /usr/local/lib/libSDL2_net-2.0.so.0
      • /usr/local/lib/libSDL2.a
      • /usr/local/lib/libSDL2_test.a
      • /usr/local/lib/libSDL2_ttf.a
      • /usr/local/lib/libSDL2_ttf.so
      • /usr/local/lib/libSDL2_ttf-2.0.so.0.14.0
      • /usr/local/lib/libSDL2_net.la
      • /usr/local/lib/libsmpeg2-2.0.so.0.0.0
      • /usr/local/lib/cmake
      • /usr/local/lib/cmake/SDL2
      • /usr/local/lib/cmake/SDL2/sdl2-config.cmake
      • /usr/local/lib/libSDL2_image-2.0.so.0
      • /usr/local/lib/libSDL2_image-2.0.so.0.0.1
      • /usr/local/lib/libSDL2_net.a
      • /usr/local/lib/libSDL2_mixer-2.0.so.0
      • /usr/local/lib/libsmpeg2.a
      • /usr/local/lib/libSDL2-2.0.so.0
      • /usr/local/lib/libsmpeg2.so
      • /usr/local/lib/libsmpeg2-2.0.so.0
      • /usr/local/lib/libSDL2.la
      • /usr/local/lib/libSDL2_mixer.so
      • /usr/local/lib/libSDL2_image.so
      • /usr/local/lib/libSDL2.so
      • /usr/local/lib/pkgconfig
      • /usr/local/lib/pkgconfig/SDL2_image.pc
      • /usr/local/lib/pkgconfig/SDL2_net.pc
      • /usr/local/lib/pkgconfig/sdl2.pc
      • /usr/local/lib/pkgconfig/SDL2_mixer.pc
      • /usr/local/lib/pkgconfig/SDL2_ttf.pc
      • /usr/local/lib/libSDL2_image.a
      • /usr/local/lib/libSDL2_net-2.0.so.0.0.1
      • /usr/local/lib/libSDL2_mixer-2.0.so.0.0.1
      • /usr/local/lib/libSDL2_ttf.la
      • /usr/local/lib/libSDL2_net.so
      • /usr/local/lib/libsmpeg2.la
      • /usr/local/lib/libSDL2_mixer.a
      • /usr/local/lib/libSDL2_ttf-2.0.so.0
      • /usr/local/lib/libSDL2-2.0.so.0.4.1
      • /usr/local/lib/libSDL2_image.la
      • /usr/local/lib/libSDL2main.a
      • /usr/local/lib/libSDL2_mixer.la
    • /usr/bin:
      • /usr/bin/plaympeg
      • /usr/bin/sdl2-config
      • /usr/bin/smpeg2-config

  • When cross-compiling on Ubuntu:
    • You may need to add the following libraries (see what it complains about):
      • SDL2
      • SDL2_ttf
      • freetype
      • z
      • png12
    • also add following libraries:
      • pthread
      • vchiq_arm
      • vcos
      • bcm_host
    • make sure you have {sysroot}/opt/vc/lib on library search path


UPDATE 2018-01-01

Well Raspbian Stretch has been out for quite a while now; it turns out it ships with a libSDL2 only for X-Windows, and not for the framebuffer console.

The above steps should still work (you can bump the version up to the current one which is 2.0.7).

I've made some pre-built .debs which may be useful, see the README at https://github.com/dotsha747/libsdl2-rpifb. I'm not sure if it's even accelerated at all at this point, as I just need enough of SDL2 to draw TTF onscreen.