Get PiratePig Running on a Raspberry Pi 2 with Raspbian Jessie


[ THIS POST is outdated, There are newer versions of OpenFL. Go here: ]

[ UPDATE 20-03-2106:  This guide also works on Ubuntu Mate 15.10.3 ]

A while ago I wrote an article on how to use hardware accelerated openfl  on the rassberry pi 2.
Since then there's been some changes to openfl and lime as they are now using haxe 3.2.1and work has been done on how things are rendered.

So here is write up on how to get version 3.2.1 of haxe and the git-versions of openfl and lime running on your Raspberry Pi 2. I'm pulling in lime and openfl from github because we need to make some changes to the source at the moment.
Hopefully in the near future we can build some binaries.

I will show you how to build everything from source, but give an alternative for neko

Grab yourself a thermos with coffee and a couple of hours, this is going to take a while!

I am assuming you are using Raspbian Jessie, I tested everything below on a fresh raspbian image with release date 2016-02-09

First of all I like to have all my stuff in a Development directory in the home directory so let's create it along with some directories inside it.

this creates the following structure in /home/pi/:
-- haxe
---- dev
---- lib
---- source

before we grab neko and haxe, let's install some dependencies that you will need to compile them.

Now let's grab neko, you can either build from source or use a binary from openfl.
If you would like to use the binary do the following

or you can build from source.
you can skip libraries when it asks you to, I'm not using the neko apache and gtk and mysql4 modules on the Pi

you can test if neko was installed by running

Now lets get the haxe-3.2.1 source
We will checkout out a specific branch

You should now have a working version of haxe and haxelib
so we'll setup haxelib next
Earlier we made directories for haxelib libraries (/home/pi/Develeopment/haxe/lib) and libraries you build yourself or checkout from git (/home/pi/Develeopment/haxe/) this is how I do it but feel free to do otherwise

now to make things easer further along the road we will install and setup openfl eventhough it will not work right away
it will install some libraries we'll need anyway. Maybe in the future this WILL be all you need to do.

(choose yes to install the openfl command)

you should now be able to run the openfl command and the lime command
but we'll be checking out the source versions of both lime and openfl now in the dev directory

Because the Raspberry Pi has it's OpenGLES2 libraries in a different place from other linux-distributions
adding paths to these libraries in the Build.xml file of lime/project and submitting to the repository will crash the buildserver that is based on linux but doesn't have these paths. So we will have to do this manually for now.

edit the file lime/project/Build.xml, for instance with nano

now uncomment line 357 (approximately) so that it reads:

And add the following line after line 361 (approximately)

and add this section right after line 190 (approximately) : the closing section xml tag for the emscripten section

or you can use this patch file for Build.xml
[ or alternatively here's a GIST with the contents of my Build.xml ]

[IMPORTANT UPDATE:  the patch and GIST do not work with the latest commit of lime (anything later then Feb 20, 2016 ),
because in that commit the Build.xml file was modified
So it's better to manually edit the existing Build.xml as described above ]


Now you should almost be able to compile lime but there's still a few bugs in SDL for the raspberry pi.
I have tried to come up with a fix and have made a clone of the SDL-submodule within limeThe master  just fixes SDL-config file so that it uses the correct video-driver and fixes the mouse-cursor.
There's also a branch that has experimental support for the raspberry pi touchscreen.

So we are going to replace the sdl directory in the lime source (we'll rename the old sdl directory)
unfortunately these changes will break the ability to pull changes from the repo
I will use the branch that has the support for the touchscreen (mouse support should work even without a touchscreen)
and then we'll rebuild lime

before we can rebuild lime we have to rebuild hxcpp normal and static
Note: the first line may give an error: g++: error: unrecognized command line option ‘-m32’
if it does just run the first line again.

Now let's go make a minor change to the DefaultShader in openfl.
Don't forget to set haxelib dev to the openfl folder in dev!! (I just did while making this post 😉
For reasons still unknown the alpha-component in the defaultShader is crashing on the Raspberry Pi.
A temporary fix is to add a tiny fraction to the alpha component in the Vertex-Shader.

now change line 28 to

now it's time to compile Pirate-pig
I'll make a directory for openfl projects and create the PiratePig Example here.
Then we'll make a small change to the PiratePig Example.
This is because the application is not show in a window and therefore you have no way to close the application.
We'll just add a keydown EventListener on the stage, choose a key combo and issue the quit command

now add the eventlistener to the 'public function new () ' function right after the onResize listener

add an import statement for the Keyboard constants (after line 8 i.e.)

and add the callback after the onResize Callback

now you will be able to quit the app with f4

Then there is just one thing left to do
time for another coffee and maybe eat something!

I think you should be looking at pirate-pigs, pandas and more!

game_panda game_piratePig

ow, and you should be able to use your fingers if you own a raspberry touchscreen !