Updated: 2017.11.30 to cover SDL2 2.0.8 and the latest versions of the utility libraries
With the release of Raspbian Stretch, quite a lot has changed. One of those things is the default graphics drivers for the VC4. This matters to us because with the release of Stretch they have finally removed the old drivers which have been been installed by default as well.
SDL2 is now installed by default but it is compiled for desktop users with support for X and OpenGL, neither of which we can take advantage of in a framebuffer and it will just confuse MAME if you try to compile using it. Just as a test I compiled a minimal MAME 0.188 using the default SDL2 and running on the Desktop I got ~3fps running Gridlee in a window.
So first things first you will need to get rid of the default SDL2
sudo apt-get remove -y --force-yes libsdl2-dev sudo apt-get autoremove -y
Next we need to set up the build environment; so add a few needed packages
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 libjpeg-dev
I’m going to assume you use some form of ‘code’ or ‘develop’ type folder structure for your programming efforts (I use ‘code’, just substitute your development directory structure for mine)
cd mkdir code cd code
Now we have need to get the latest build of from the libsdl mercurial by typing:-
hg clone http://hg.libsdl.org/SDL cd SDL
You will end up with a copy of the SDL2 source code and leave yourself in the source folder.
Now we need to actually build it.
./autogen.sh ./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-opengl --host=arm-raspberry-linux-gnueabihf make sudo make install
That will take a little while but when it’s done if you type
sdl2-config --version it should say
Next up we will build all the utility libraries, starting by downloading them all.
cd cd code wget http://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.2.tar.gz wget http://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.2.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 them all
tar zxvf SDL2_image-2.0.2.tar.gz tar zxvf SDL2_mixer-2.0.2.tar.gz tar zxvf SDL2_net-2.0.1.tar.gz tar zxvf SDL2_ttf-2.0.14.tar.gz
Build the Image file loading library
cd SDL2_image-2.0.2 ./autogen.sh ./configure make sudo make install cd ..
Build the Audio mixer library
cd SDL2_mixer-2.0.2 ./autogen.sh ./configure make sudo make install cd ..
Build the Networking library
cd SDL2_net-2.0.1 ./autogen.sh ./configure make sudo make install cd ..
Build the Truetype font library
cd SDL2_ttf-2.0.14 ./autogen.sh ./configure make sudo make install cd ..
All done. Any program that uses SDL2 to draw to the framebuffer should now be doing it in hardware on the raspberry pis videocore4 using opengles2!