[ THIS POST is outdated, There are newer versions of OpenFL. Go here:
http://www.gepatto.nl/openfl-4-7-on-a-raspberry-pi-2-or-3/ ]
[ 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.
1 |
mkdir -p ~/Development/haxe/{dev,lib,source} |
this creates the following structure in /home/pi/:
Development
— haxe
—- dev
—- lib
—- source
before we grab neko and haxe, let’s install some dependencies that you will need to compile them.
1 2 3 4 5 6 7 |
sudo apt-get install libgc-dev libpcre3-dev sudo apt-get install build-essential git cmake sudo apt-get install libudev-dev sudo apt-get install ocaml ocaml-native-compilers libpcre-ocaml-dev sudo apt-get install sqlite3 libsqlite3-dev sudo apt-get install libmysqlclient-dev sudo apt-get install libasound2-dev |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
cd ~/Development/haxe/source wget -c http://www.openfl.org/builds/neko/neko-2.0.0-rpi.zip sudo mkdir -p /usr/lib/neko sudo rm -rf /usr/lib/neko/neko sudo rm -rf /usr/lib/neko/nekotools sudo unzip -o neko-2.0.0-rpi.zip -d /usr/lib/neko/ sudo cp -r /usr/lib/neko/bin/* /usr/lib/neko sudo rm -rf /usr/lib/neko/bin sudo rm -rf /usr/bin/neko sudo rm -rf /usr/bin/nekoc sudo rm -rf /usr/bin/nekotools sudo rm -rf /usr/lib/libneko.so sudo ln -s /usr/lib/neko/libneko.so /usr/lib/libneko.so sudo ln -s /usr/lib/neko/neko /usr/bin/neko sudo ln -s /usr/lib/neko/nekoc /usr/bin/nekoc sudo ln -s /usr/lib/neko/nekotools /usr/bin/nekotools rm neko-2.0.0-rpi.zip |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
cd ~/Development/haxe/source wget http://nekovm.org/media/neko-2.0.0.tar.gz tar xvzf neko-2.0.0.tar.gz rm neko-2.0.0.tar.gz cd neko-2.0.0/ make sudo mkdir -p /usr/lib/neko sudo rm -rf /usr/lib/neko/neko sudo rm -rf /usr/lib/neko/nekotools sudo cp -R bin/ /usr/lib/neko/ sudo cp -r /usr/lib/neko/bin/* /usr/lib/neko sudo rm -rf /usr/lib/neko/bin sudo rm -rf /usr/bin/neko sudo rm -rf /usr/bin/nekoc sudo rm -rf /usr/bin/nekotools sudo rm -rf /usr/lib/libneko.so sudo ln -s /usr/lib/neko/libneko.so /usr/lib/libneko.so sudo ln -s /usr/lib/neko/neko /usr/bin/neko sudo ln -s /usr/lib/neko/nekoc /usr/bin/nekoc sudo ln -s /usr/lib/neko/nekotools /usr/bin/nekotools |
you can test if neko was installed by running
1 |
neko |
Now lets get the haxe-3.2.1 source
We will checkout out a specific branch
1 2 3 4 5 6 |
cd ~/Development/haxe/source git clone --recursive https://github.com/HaxeFoundation/haxe -b 3.2.1 cd haxe make make tools sudo make install install_tools |
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
1 2 |
cd /home/pi/Development/haxe/ haxelib setup lib/ |
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.
1 2 3 |
haxelib install openfl haxelib run openfl setup haxelib install format |
(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
1 2 3 |
cd /home/pi/Development/haxe/dev/ git clone --recursive https://github.com/openfl/lime/ git clone --recursive https://github.com/openfl/openfl/ |
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
1 2 |
cd /home/pi/Development/haxe/dev/lime/project/ nano Build.xml |
now uncomment line 357 (approximately) so that it reads:
1 |
<lib name="-lbcm_host" /> |
And add the following line after line 361 (approximately)
1 |
<lib name="-L/opt/vc/lib" /> |
and add this section right after line 190 (approximately) : the closing section xml tag for the emscripten section
1 2 3 4 5 6 7 8 |
<section if="rpi"> <compilerflag value="-I/opt/vc/include"/> <compilerflag value="-I/opt/vc/include/interface/vcos/pthreads"/> <compilerflag value="-I/opt/vc/include/interface/vmcs_host/linux"/> <compilerflag value="-lGLESv2" /> <compilerflag value="-lEGL" /> <compilerflag value="-Wl,–no-undefined -lm -L/opt/vc/lib -lbcm_host -ldl -lpthread -lrt"/> </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
1 2 3 4 5 |
cd /home/pi/Development/haxe/dev/lime/project/lib/ mv sdl sdl_dist git clone https://github.com/gepatto/sdl -b touchscreen_as_multitouch cd /home/pi/Development/haxe/dev/ haxelib dev lime 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.
1 2 3 |
lime rebuild hxcpp linux -rpi lime rebuild hxcpp linux -rpi -static lime rebuild lime linux -rpi -v |
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.
1 2 3 4 |
cd /home/pi/Development/haxe/dev/ haxelib dev openfl openfl cd /home/pi/Development/haxe/dev/openfl/openfl/_internal/renderer/opengl/shaders2/ nano DefaultShader.hx |
now change line 28 to
1 |
' ${Varying.Color} = vec4(${Attrib.Color}.bgr * ${Attrib.Color}.a, ${Attrib.Color}.a + 0.00001);', |
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
1 2 3 4 5 6 |
cd /home/pi/Development/ mkdir openfl cd openfl openfl create PiratePig cd PiratePig/Source/piratepig/ nano PiratePig.hx |
now add the eventlistener to the ‘public function new () ‘ function right after the onResize listener
1 |
stage.addEventListener( KeyboardEvent.KEY_DOWN, stage_onKeyDown ); |
add an import statement for the Keyboard constants (after line 8 i.e.)
1 |
import openfl.ui.Keyboard; |
and add the callback after the onResize Callback
1 2 3 4 5 6 7 |
private function stage_onKeyDown (event:KeyboardEvent):Void { switch (event.keyCode) { case Keyboard.F4 | Keyboard.ESCAPE: openfl.system.System.exit(0); } } |
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!
1 2 |
cd ../../ openfl test linux -rpi -v |
I think you should be looking at pirate-pigs, pandas and more!
ow, and you should be able to use your fingers if you own a raspberry touchscreen !