OpenGL on Raspberry Pi

My Pi has a cover now!

The VideoCore GPU on the Pi is pretty powerful. It can decode 1080p HD videos @30fps. Besides, it also supports OpenGLES for 3D rendering. I decided to explore how to use OpenGLES on the Pi and was taken aback by the host of libraries listed on RPiHub.


So, OpenGLES is a library used for drawing. But underneath, OpenGLES has to talk to the operating system for displaying anything on the screen! On a regular linux system (maybe an x86 that runs OpenGL and not OpenGLES) writing the talk-to-the-OS code is easy due to the presence of windowing-libraries like GLUT. However, on RPi, the developer has to deal with the low-level API. Here is a block diagram showing three libraries that a user must deal with in order to write a Hello-OpenGL program on a RPi:
OpenGL-ES (version 1 or 2) uses EGL (Embedded-system Graphics Library) to obtain a 'RenderingContext'. EGL is required for creation of a rendering context and managing sync between multiple such contexts. EGL on the other hand, needs to talk to the Broadcom SoC drivers for obtaining a 'NativeWindowSurface'. This API to obtain a native window are present in the bcm_host library. 

Click here to see the HelloGL example. When executed, it paints the screen red! All the methods with signatures vc_dispmanx_* are the ones from bcm_host.

All the VideoCore related includes and libraries (and some examples) are present in /opt/vc on the raspbian image. The hello_triangle and hello_triangle2 examples are related to OpenGLES, version 1 and 2 respectively. Just that, they're not triangles ;).

Comments

Popular posts from this blog

REST over Django

Raspberry Pi: Hello World!