In this blog entry we’ll build H/W accelerated version of MonoGame.Tetris example for Raspberry PI.
Raspberry PI does not have HW OpenGL libraries for accelerated graphics, instead it has OpenGL ES 2.0 libraries (and ES 1.1 embedded in same libraries) for acceleration. However it’s possible to run OpenGL applications on RPI, but rendering will fallback to software OpenGL renderer (Mesa).
By default MonoGame for Linux uses OpenGL and can be executed with few tricks, but performance is not good.
I’ve baked an experimental MonoGame (based on MonoGame 2.0) for OpenGL ES 2.0 based desktop environments, in practice implementation was only about mixing Android GLES and Linux versions of MonoGame, so I don’t take any credits for this 🙂
There’s now also fork of MonoGame 3d in GitHub. Start observing it, since it’s based on forthcoming release on MonoGame which has a lots of new cool features 🙂
MonoGame 3d for RPI is now out, check out: http://www.youtube.com/watch?v=jwbYe6eoZgE&feature=youtu.be
Running prebuild accelerated Tetris
Here’s a short checklist for running prebuild Tetris which is available as tetris_raspberry.gles2.zip from my Dropbox account.
- Debian Squeeze (debian6-19-04-2012.img) installed on RPI
- Mono Runtime 2.6.9 (apt-get install mono-runtime)
- mesa opengl drivers (apt-get install mesa-common-dev)
After the required software has been installed start X, open terminal, and “cd” into directory that tetris_raspberry_gles2.zip is unpacked and type:
Reason why I’m using the Debian 6 instead of 7/Wheezy is that Mono seems have issues handling floating points on ARMHF (hardware floating point architechture).
Building accelerated Tetris from scratch
I’ve been using MonoDevelop 184.108.40.206 and Windows 7 to build the project.
Make sure build target is set to Net 3.5 in MonoGame and Tetris projects, since Mono 2.6 does not support Net 4.0.
First we need to checkout source code for the modules:
- MonoGame for RPI (git clone https://github.com/noxo/MonoGame)
- OpenTK (git clone https://github.com/mono/opentk) version OpenTK SVN seems not yet work
- MonoGame Samples (git clone https://github.com/CartBlanche/MonoGame-Samples)
Compile MonoGame against OpenTK and then Tetris against MonoGame, if you were lucky there were no errors, just lots of meaningless warnings 🙂
Copy the compiled binaries to Raspberry PI.
We need also to copy VideoCore GPU libraries to folder were compiled binaries are from /opt/vc/lib. Copy libEGL.so and libGLESv2.so.
Wait – small hack needed to VideoCore EGL driver
This step is not needed if you trying prebuild Tetris, since tetris_raspberry_gles2.zip already has patched libEGL.so included.
Default Raspberry PI VideoCore OpenGL ES drivers (/opt/vc/lib) does not support attaching into X11 surface, and we need to tweak one of GLES library (libEGL.so) file to get things working.
- Pull x11-hack-libegl.txt from My Dropbox account to Rasberry PI
- sh x11-hack-libegl.txt
- copy patched libEGL.so from /opt/vc/lib to same directory as compiled Tetris binaries
This hack is not complete since it’s hardcoded to create 800×600 window, so some work is still needed.
Now cross your fingers, and try executing Tetris.exe — works for me 🙂
Stuff needed for sounds
MonoGame sound system is based on OpenAL, so if you plan to use xna.SoundEffect (even without invoking play), the following stuff is needed:
- OpenAL libraries (apt-get install libopenal-dev)
- Load the sound kernel module (modprobe snd_bcm2835)
The last step is not necessarily needed on all distros, since sound module is probably preloaded.
That’s it 🙂