mathr / blog / #

Puzzle on Raspberry Pi

Back in 2008 I made a patch with Pure-data, Gem, and PdLua that took the form of a sliding tile puzzle with generative ambient drones. You can see a video in my 2009 blog post. In 2013 I updated it with extra features (tiles that spin and flip over occasionally, plus black borders, and sound based on rhythms) but never published the changes. I recently got given a Raspberry Pi 3 B, and thought this would be a nice project to test out its graphics capabilities.

I installed the Raspbian Jessie full image on a 32GB SD card, and installed a few additions. Installing mesa-utils and running glxgears was very disappointing - 40fps with a tiny window and very high CPU load, with glxinfo reporting OpenGL 3.0 via Gallium llvmpipe. Some searching of the internet later I found the hint to sudo raspi-config and enable the experimental OpenGL driver in the advanced settings. Then glxgears ran at 60fps with no load, and glxinfo reported OpenGL 2.1 via Broadcom.

I uncommented the deb-src line in /etc/apt/sources.list so I could run

sudo apt-get update
sudo apt-get build-dep puredata
sudo apt-get build-dep gem
sudo apt-get install liblua5.2-dev subversion

Then I got Pd source from git, Gem source from git, and pdlua source from svn (note: I got the whole trunk repository as the build system there is not self-contained):

mkdir ~/opt/src
cd ~/opt/src
git clone git://git.code.sf.net/p/pure-data/pure-data pure-data-git
git clone git://git.code.sf.net/p/pd-gem/gem gem-git
svn checkout svn://svn.code.sf.net/p/pure-data/svn/trunk pure-data-svn

I applied a small patch to force generating mipmaps in Gem's pix_snap2tex (hopefully in the future this patch won't be necessary) and compiled everything like this:

export CFLAGS="-g -O3 -mfloat-abi=hard -mfpu=neon"
export CXXFLAGS="${CFLAGS}"
cd pure-data-git
./autogen.sh
./configure --prefix=${HOME}/opt --enable-jack
make -j 4
make install
cd ..
cd pure-data-svn/externals/loaders/pdlua
make prefix=${HOME}/opt objectsdir=${HOME}/opt/lib/pd/extra \
  pkglibdir=${HOME}/opt/lib/pd/extra \
  CFLAGS="${CFLAGS} -Wall -W -g -I/usr/include/lua5.2" \
  ALL_LIBS="-llua5.2 -lc"
make prefix=${HOME}/opt objectsdir=${HOME}/opt/lib/pd/extra \
  pkglibdir=${HOME}/opt/lib/pd/extra \
  CFLAGS="${CFLAGS} -Wall -W -g -I/usr/include/lua5.2" \
  ALL_LIBS="-llua5.2 -lc" install
cd ../../../..
cd gem-git
./autogen.sh
./configure --prefix=${HOME}/opt
make -j 4
make install
cd ..

Building Gem especially takes a while (37mins on the quad core Pi). Finally I tried running the Puzzle:

qjackctl &  # configure and start JACK
git clone https://code.mathr.co.uk/puzzle.git
cd puzzle
./start-simple.sh

It works very comfortably at 512x512 window size, but (WARNING) I did try it at 1024x1024 and after a minute or so of struggling to keep up it eventually locked up my Pi hard and I had to cut the power. Luckily on next boot it seems everything is fine (no data loss). Here's a grab of the smaller size:

Puzzle on Raspberry Pi

Fun!