Raspbian (PIXEL) with SDL2

UPDATE: SDL performance is very slow. I don’t think it has anything to do with the Raspberry Pi 1 that I’m using. It just can’t be that slow. I believe it has more to do with the fact the libsdl-dev package is not using OpenGL. It’s not compiled for that use. I might have to try build it from source….

Here are the ins

  1. Get Raspbian running
  2. Enable VNC and SSH
  3. sudo apt-get update
  4. sudo apt-get install libsdl2-dev
  5. Run your app

To run without desktop manager:

  1. Edit /home/pi/.config/lxsession/LXDE-pi/autostart
  2. Comment out all lines that start with @ with #
  3. Add your app and precede with @

Source: http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui

To turn off the cursor:

  1. Edit /etc/lightdm/lightdm.conf
  2. Find the line ‘xserver_command’ under [SeatDefaults]
  3. Change it to ‘xserver_command = X -nocursor’



SDL2 on Raspberry 1.0 running Minibian (FAILED)

UPDATE 2: I did the same thing on Raspbian and the compilation worked. See this.

UPDATE 1: This didn’t work, sorry guys. I couldn’t figure it out. Tried everything, running out of time…giving up…I’m going to try to make the game another way.

I have the very first Raspberry Pi, which I believe is a 1.0. I’m trying to make a game with it and I decided to use SDL. The goal is to run SDL without X, ie from console.

The first thing I needed was a lightweight distro for the RPi. I’m using Minibian because I’ve used it before and it works. Instructions for this are pretty simple:

  1. Download Minibian (https://minibianpi.wordpress.com/download/)
  2. Use Rufus to flash it to an SD Card
  3. Run the RPi and resize the partitions (https://minibianpi.wordpress.com/how-to/resize-sd/). Read the instructions carefully especially the part about aligning the partitions.
  4. Install nano
  5. If you need Wifi, install firmware-realtek (assuming you have a Realtek based dongle) and wpasupplicant. For more info visit https://minibianpi.wordpress.com/how-to/wifi/

Next step is to install SDL:

DON’T INSTALL using the package manager, it doesn’t work. You need to compile from scratch.

  1. Install these packages required for compiling SDL (not sure if the mesa libraries are required):
    apt-get install build-essential libfreeimage-dev libopenal-dev libpango1.0-dev libsndfile1-dev libudev-dev libasound2-dev libjpeg-dev libtiff5-dev libwebp-dev automake
    apt-get install libraspberrypi-dev raspberrypi-kernel-headers
    apt-get install libegl1-mesa libegl1-mesa-dev
  2. Get SDL2 (https://www.libsdl.org/release/SDL2-2.0.5.tar.gz)
    mkdir install && cd install
    wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz
    tar zxvf SDL2-2.0.5.tar.gz
    cd SDL2-2.0.5
  3. Configure and build
    ./configure --disable-pulseaudio --disable-esd --disable-video-mir --disable-video-wayland --disable-video-x11
    make install
  4. FAIL!




Raspbmc alternative? Try OpenELEC

Recently my Raspbmc box hasn’t been so great. I found that the Web interface was quite slow, the commands weren’t processed as quickly as they should be from the XBMC remote app on Android. And then there was the crashing 😦 I was sick of it so I decided to look for Raspbmc alternatives and I found OpenELEC. I don’t know too much about the internals of OpenELEC but what I can tell you is that it is some sort of lightweight linux distro which runs XBMC. It is much faster than Raspbmc and works nicely. It was really easy to setup, I just followed these instructions (http://wiki.openelec.tv/index.php?title=Installing_OpenELEC_on_Raspberry_Pi). I did have some issues with setting up the wifi but I believe that was more a problem with USB powered hub I was using.

OpenGL ES on Raspberry Pi

When writing OpenGL ES programs on the Raspberry Pi for the first time, you may encounter these issues:

1) Shaders aren’t working properly; the colors don’t come out correctly.

My Fragment Shader code was this:

precision lowp float;
varying vec3 vv3colour;
void main() {
    gl_FragColor = vec4(vv3colour, 1.0);

My Vertex Shader code was this:

attribute vec4 av4position;
attribute vec3 av3colour;
uniform mat4 mvp;
varying vec3 vv3colour;
void main() {
    vv3colour = av3colour;
    gl_Position = mvp * av4position;

SOLUTION: In my case the EGL_ALPHA_SIZE was not set in the attribList when the call to eglChooseConfig was made. Once I set EGL_ALPHA_SIZE to 8, it worked!

2) You can see X through your application, ie, the background is transparent.

SOLUTION: change the glClearColor line to (0.0f, 0.0f, 0.0f, 1.0f). I don’t understand it but that worked for me.

OpenGL ES on Raspberry Pi without X

Here’s the source link: http://benosteen.wordpress.com/2012/04/27/using-opengl-es-2-0-on-the-raspberry-pi-without-x-windows/

Here are my instructions to build the examples:

mkdir glus
cd glus
wget --no-check-certificate https://github.com/benosteen/opengles-book-samples/tarball/master
tar -xvzf master
cd benosteen-opengles-book-samples-186d0ab
cd Raspi

NOTE: the folder will start with “benosteen-opengles-book-samples…”

Create a new file:

sudo nano /etc/ld.so.conf.d/raspi-opengles-lib.conf

add this line to the file:


Save and exit.

sudo ldconfig

Edit the Makefile:

nano Makefile

add this line to the end of the line starting with INCDIR:


Save and exit.



Here are my instructions to run an example:

cd Chapter_2
cd Hello_Triangle


RPi – Turn of external hard drive when not in use

If you have a Raspberry Pi connected to an external hard drive and you keep it on all the time then you may find that the external hard drive continues to stay spinning, even though you aren’t reading anything from it. I have two problems with that:
1) Waste of energy (negligible but still)
2) Noise

The noise part annoys me the most because I like a little peace and quiet around the home 🙂

Anyway, I’m using a Seagate Expansion External Hard drive (3Tb) and it never stopped spinning…I found a solution! Follow these steps:

1) Run this command

sudo nano /etc/hdparm.conf

This will open the hdparm.conf file for editing.

2) Look for the line “# -B apm setting” and observe the line that follows. My one looked like this:
# apm = x
where x = some value.

3) Remove the # from the start of the line, and change the 127 to 1.

4) Hit Ctrl+X and press Y to save the file.

5) Reboot your RPi

That’s it!

In Linux, the hdparam program is used to get/set hard drive parameter, see http://linux.die.net/man/8/hdparm. You can achieve the above by entering this:

sudo hdparm -B 1 /dev/sda2


/dev/sda2 is the hard drive’s device path

1 means highest power management (254 is lowest power management)

The bad part is that you have to run that command each time you reboot your RPi. However, by editing the /etc/hdparm.conf file, it is automatically applied at boot time and it becomes the default setting for all hard drives.