Building and using SDL2 on the Pandora
So, if you have a Pandora http://openpandora.org and you want to use SDL2 with it, then it might not be clear how to do it.
You will need the dev tools installed. I’m using the PND from here http://repo.openpandora.org/?page=detail&app=codeblocks6022 which has a build of Code::Blocks, the compilers, and loads of other stuff and also a Development command line (which has Mercural/hg, git, etc., installed). You can get this from the PNDStore application - it’s called Code::Blocks :-) …. !!WARNING!! You might want to do this into an ext partition on your SD Card if you have one … read Part 1 below before you install it…
So for building SDL2, I partitioned and created an ext4 partition on my second SD Card. I’m sure an ext2 or ext3 partition would be just as good. (And I sure you can read a lot about which format is better/worst for SD Cards … let’s ignore all that for the moment).
My Code::Blocks and my project are on a FAT partition - so I need to make sure configure works. As far as I can see, there are several approaches to this:
I decided to temporarily move my Code::Blocks PND files across (after a restart, i.e. before running the Dev command line or code blocks, so nothing was mounted and relying on those files). This is what I did:
I restarted after this to ensure everything was scanned properly, although this is probably not necessary. (An alternative is uninstalling code::blocks then reinstalling - although remember your appdata if you have anything important in there...)
It’s possible to move them back (after a restart!) after SDL2 is installed, although this isn’t strictly necessary - they will work in the new ext home.
cd /media/mmcblk1p2
mkdir SDL
mkdir sdl-build
mkdir sdl-install (only if you are installing in a separate location)
So let’s get the code out, as per the instruction here: (http://www.libsdl.org/hg.php) .. .this gets the latest revision, so there might be problems… (alternatively use a stable version as per below).
cd SDL
hg clone http://hg.libsdl.org/SDL
You might alternatively want to download it from specific (stable) build, e.g. http://www.libsdl.org/tmp/download-2.0.php
In the file SDL_test_fuzzer.c, line #39, before #include add
#define __USE_ISOC99
cd ../sdl-build
../configure --prefix=/mnt/utmp/codeblocks/usr/ --disable-haptic --disable-directfb-shared --enable-video-directfb --enable-video-opengles --disable-video-opengl
(The original instructions have --disable-opengles-shared, but this is an unrecognised option … so I’ve removed it).
Here is some explanation, from my naïve point of view, of what those options probably do. The prefix is where is it going to install it - when the dev command line started up you might have seen a line that said “Setting CODEBLOCKS_DATA_DIR to /mnt/utmp/codeblocks” and similar lines which probably explains the slightly weird path here. Haptic is force-feedback, and we don’t want that (might be a build problem - I’ve seen similar elsewhere with SDL), I guess we want a direct frame buffer rather than a shared one, and we definitely want OpenGLES rather than OpenGL, since the chip in the Pandora is a mobile chip.
If you are installing in a separate folder, then the prefix part would become something like --prefix=/media/mmcblk1p2/sdl-install/
Next is:
make
Then:
make install
And surprisingly you are done and now have SDL2 installed.
My Pandora Code::Blocks project just has all the source files put into an empty project (normal setup in the empty project wizard). I also added some source code search directories based on my current folder structure to this project (under ‘Project’ menu -> Build options… -> Search directories -> Compiler).
Now we need to add SDL2 to this project.
Initially I thought that ‘Project’ menu -> Properties… -> Libraries (the ‘Libraries’ tab is off the end of the dialog tab list to the right, press the little right arrow at the end to access that tab) and moving the the sdl2 into the "Libraries used in project" would sort the include and library usage - but apparently not. I’m missing something here … comments welcome.
So instead, for the moment, I just hard-coded the paths.
For the includes (to make #include “SDL.h” works), this was done in ‘Project’ menu -> Build options… -> Search directories -> Compiler and added /mnt/utmp/codeblocks/usr/include/SDL2 as an absolute path.
For the library I guess you can either add the shared object (libSDL2.so) or static libraries. These are added under ‘Project’ menu -> Build options… -> Linker settings -> Link libraries. I used the shared library which is installed in /mnt/utmp/codeblocks/usr/bin/libSDL2.so.
(I’d suggest using the shared library and packaging it up in the PND … that allows replacement with a newer version without rebuilding).
The game runs after I sorted out the problem that it couldn’t find it’s resources.
There are two temporary approaches to the resource problem:
Graphics, keyboard and sound works.
The three issues I see:
I must thank ptitSeb from the OpenPandora boards for help with these instructions. The clever bits are all his work; the stupid bits are mine. He’s also the maintainer of the Code::Blocks PND, and very long list of other PND files http://repo.openpandora.org/?page=all&search=ptitSeb
You will need the dev tools installed. I’m using the PND from here http://repo.openpandora.org/?page=detail&app=codeblocks6022 which has a build of Code::Blocks, the compilers, and loads of other stuff and also a Development command line (which has Mercural/hg, git, etc., installed). You can get this from the PNDStore application - it’s called Code::Blocks :-) …. !!WARNING!! You might want to do this into an ext partition on your SD Card if you have one … read Part 1 below before you install it…
Part 1: Filesystem Notes
For a start, there are problems building SDL2 on a FAT partition an SD Card. The configure process uses a chmod which doesn’t apply to FAT partition. Then if your Code::Blocks files are on a FAT, the ‘make install’ will also have problems when it runs ‘install’. (I’m sure there are ways around this … but below documents the way I did it.)So for building SDL2, I partitioned and created an ext4 partition on my second SD Card. I’m sure an ext2 or ext3 partition would be just as good. (And I sure you can read a lot about which format is better/worst for SD Cards … let’s ignore all that for the moment).
My Code::Blocks and my project are on a FAT partition - so I need to make sure configure works. As far as I can see, there are several approaches to this:
- Copy everything off my main SD card, reformat as ext and copy everything back on.
- Install in a folder on the ext partition and then (in your project) specify a folder where the installed libraries are. (If you read part 2, you’ll see I ended up pointing my project at the include and lib anyway).
- Install in a folder on the ext partition and then manually copy the files across in the Code::Blocks folders.
- Temporally move your Code::Blocks folder to a set of Pandora folders on the ext partition.
I decided to temporarily move my Code::Blocks PND files across (after a restart, i.e. before running the Dev command line or code blocks, so nothing was mounted and relying on those files). This is what I did:
- Created a set of pandora folders on my ext filesystem with ‘Create Pandora SD Card’ (under System in the menu, without formatting)
- Move .PND out of pandora/menu/ (or pandora/apps or pandora/desktop) into the ext filesystem equivalent.
- Move ‘codeblocks’ folder out of pandora/appdata into pandora/appdata on the ext filesystem
I restarted after this to ensure everything was scanned properly, although this is probably not necessary. (An alternative is uninstalling code::blocks then reinstalling - although remember your appdata if you have anything important in there...)
It’s possible to move them back (after a restart!) after SDL2 is installed, although this isn’t strictly necessary - they will work in the new ext home.
Part 2: Building SDL2
So let’s create some directories… let’s assume your ext partition is mounted as ‘mmcblk1p2’.cd /media/mmcblk1p2
mkdir SDL
mkdir sdl-build
mkdir sdl-install (only if you are installing in a separate location)
So let’s get the code out, as per the instruction here: (http://www.libsdl.org/hg.php) .. .this gets the latest revision, so there might be problems… (alternatively use a stable version as per below).
cd SDL
hg clone http://hg.libsdl.org/SDL
You might alternatively want to download it from specific (stable) build, e.g. http://www.libsdl.org/tmp/download-2.0.php
Changes Required:
The source didn't build for me (as of SDL2 revision/Change set 7301 : 3554be091b3b) ... because of something in the tests...In the file SDL_test_fuzzer.c, line #39, before #include
#define __USE_ISOC99
Next...
The normal Unix/Linux build process is configure / make / make install. The ‘configure’ sets up the build process based on your environment and options you specify, ‘make’ does the build and ‘make install’ puts the stuff into the right place. We are going to build it in a separate directory from the main source.cd ../sdl-build
../configure --prefix=/mnt/utmp/codeblocks/usr/ --disable-haptic --disable-directfb-shared --enable-video-directfb --enable-video-opengles --disable-video-opengl
(The original instructions have --disable-opengles-shared, but this is an unrecognised option … so I’ve removed it).
Here is some explanation, from my naïve point of view, of what those options probably do. The prefix is where is it going to install it - when the dev command line started up you might have seen a line that said “Setting CODEBLOCKS_DATA_DIR to /mnt/utmp/codeblocks” and similar lines which probably explains the slightly weird path here. Haptic is force-feedback, and we don’t want that (might be a build problem - I’ve seen similar elsewhere with SDL), I guess we want a direct frame buffer rather than a shared one, and we definitely want OpenGLES rather than OpenGL, since the chip in the Pandora is a mobile chip.
If you are installing in a separate folder, then the prefix part would become something like --prefix=/media/mmcblk1p2/sdl-install/
Next is:
make
Then:
make install
And surprisingly you are done and now have SDL2 installed.
Part 3: Building a game with SDL2
My code (A Gulpman clone) was already building on Mac, Linux, Windows, and iOS (iPhone) against SDL2, using various different tools - none were Code::Blocks.My Pandora Code::Blocks project just has all the source files put into an empty project (normal setup in the empty project wizard). I also added some source code search directories based on my current folder structure to this project (under ‘Project’ menu -> Build options… -> Search directories -> Compiler).
Now we need to add SDL2 to this project.
Initially I thought that ‘Project’ menu -> Properties… -> Libraries (the ‘Libraries’ tab is off the end of the dialog tab list to the right, press the little right arrow at the end to access that tab) and moving the the sdl2 into the "Libraries used in project" would sort the include and library usage - but apparently not. I’m missing something here … comments welcome.
So instead, for the moment, I just hard-coded the paths.
For the includes (to make #include “SDL.h” works), this was done in ‘Project’ menu -> Build options… -> Search directories -> Compiler and added /mnt/utmp/codeblocks/usr/include/SDL2 as an absolute path.
For the library I guess you can either add the shared object (libSDL2.so) or static libraries. These are added under ‘Project’ menu -> Build options… -> Linker settings -> Link libraries. I used the shared library which is installed in /mnt/utmp/codeblocks/usr/bin/libSDL2.so.
(I’d suggest using the shared library and packaging it up in the PND … that allows replacement with a newer version without rebuilding).
Part 4: Does Gulpman work on Pandora?
The game runs after I sorted out the problem that it couldn’t find it’s resources.
There are two temporary approaches to the resource problem:
- Copy the correct resources in to the build folder (either by hand or get Code::Blocks to do it).
- Run the application from your data folder.
Graphics, keyboard and sound works.
The three issues I see:
- At the time of writing the keyboard layout gives warnings (Keyboard layout unknown) but the keyboard works…
- I get ALSA lib pcm.c (snd_pcm_recover) under run occurred,
- The frame-rate is about 30 frames per second - which seems a tiny bit slow.
Thanks:
I must thank ptitSeb from the OpenPandora boards for help with these instructions. The clever bits are all his work; the stupid bits are mine. He’s also the maintainer of the Code::Blocks PND, and very long list of other PND files http://repo.openpandora.org/?page=all&search=ptitSeb
1 Comments:
Thank you for sharing this.
Post a Comment
<< Home