Programming, Raspberry Pi

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.

Programming

OpenGL ES emulation on Debian guest VM running on Windows 7 host

Here are the instructions to emulating OpenGL ES programs on a Debian (wheezy) VM (using VMware Player) running on a Windows 7 host.

  1. Set up a Debian wheezy VM on VMWare Player. That’s pretty basic stuff so I’m not going through that.
  2. Enable “Accelerate 3D graphics” option in the settings of the VM. This setting is done using VMware Player and it needs to be done with the Debian wheezy VM turned off.
  3. Download the OpenGL ES 2.0 Emulator from http://malideveloper.arm.com/develop-for-mali/tools/opengl-es-2-0-emulator/ (obviously download the one for linux!)
  4. Copy that file into the VM and extract it.
  5. You will find the “bin” folder with the three “so” files inside. Copy these files into /usr/lib.
  6. Run ldconfig (not sure if this is required but do it anyway)

Now you have the required libraries for OpenGL ES emulation. If you want to test it, follow these instructions:

Example 1

(go into the OpenGL ES emulator folder, the one you downloaded in Step 3 above)

cd ARM
cd Mali_Developer_Tools
cd OpenGL_ES_Emulator_1.3.1
cd examples
cd OpenGLES_20
cd cubes
make
./cube

You should be a nice spinning cube! 🙂

Example 2

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 LinuxX11
make
cd Chapter_2
cd Hello_Triangle
./CH02_HelloTriangle

You should see a nice red triangle! 🙂

Programming, Raspberry Pi

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:

/opt/vc/lib

Save and exit.

sudo ldconfig

Edit the Makefile:

nano Makefile

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

-I/opt/vc/include/interface/vmcs_host/linux

Save and exit.

make

Done!


Here are my instructions to run an example:

cd Chapter_2
cd Hello_Triangle
./CH02_Hello_triangle

Done!