OpenGL-ES

Contents

OpenGL ES

OpenGL ES is an API that allows programmers to draw 3D graphics on mobile and embedded devices. OpenGL ES 1.1 and 2.0 have been available on Maemo devices since the N900.

Books about OpenGL ES

Excellent introductory section covering OpenGL basics. Covers ES 1.1, not ES 2.0.

The 'Gold Book' is hardly in the same league as the above book, or the original 'Red Book' - being aimed at folk who already know their OpenGL lingo. It dives into laborious detail as if trying to spew as much of the ES 2.0 spec onto the page as possible. It assumes a Windows audience and the AMD simulator. You may be better off looking at the PowerVR SDK tutorial code than reading this book, then coming back to it for reference and further code examples.

Other documentation

Imagination Technologies SDK

Other related documentation

OpenGL variants

OpenGL ES is a subset of the full OpenGL standard, and therefore the two APIs are not directly compatible. The following diagram shows the relationship of the major OpenGL versions and variants.

image:Opengl.svg

  • OpenGL 1.0 has fixed shaders and fixed function API to using them
  • OpenGL 2.0 adds programmable shaders, but fixed function pipeline API is still there for backward compatibility
  • OpenGL ES 1.1 is based on OpenGL 1.x with some APIs removed and fixed point integer support added
  • OpenGL ES 2.0 is based on OpenGL 2.0 with the fixed function API removed

Porting between OpenGL variants

  • OpenGL 1.0 application works with OpenGL 2.0 but not vice versa
  • OpenGL 1.0 application can be ported to OpenGL ES 1.1, but needs work if it is using some of the removed APIs
  • OpenGL 2.0 application that only uses programmable shaders is possible to port OpenGL ES 2.0, but may still need some work
  • Porting OpenGL 1.0 or OpenGL ES 1.1 applications to OpenGL ES 2.0 requires a rewrite to replace fixed function API usage with programmable shaders

Most of the desktop Linux OpenGL applications are written using the legacy OpenGL 1.x fixed function pipeline (e.g. usage of glBegin/glEnd and the matrix stack). OpenGL 2.0 introduced programmable shaders, but it still supports the legacy fixed function pipeline. Since in OpenGL ES 2.0 the fixed function pipeline has been completely removed, porting applications from OpenGL 2.0 to OpenGL ES is likely to require a major rewrite of the application's graphics code.

Compiling under scratchbox

An excellent way to familiarize yourself with OpenGL ES 2.0 which is to try the tutorials that can be found in the PowerVR SGX SDK under the TrainingCourse directory.

The SDK libs and headers can be dropped into your X86 environment and run into the Xephyr X11 window - but you'll need to kill the window manager first!

To compile OpenGL ES 2.0 applications you need to have package "libgles2-sgx-img-dev" installed which is part of the nokia-binaries repository. It is as standard, part of Fremantle aplha ARMEL but at the moment it is missing from the x86 version. We try to get the x86 equivalent OpenGL ES2 emulation library available soon.

The examples have their own Makefiles for Linux hosts but you can copy the files to your own directory and try the Makefile below. Reason to use this own Makefile is that the makefiles coming with the SDK compiles examples with x86 libraries part of the SDK and not armel/x86 maemo libraries in scratchbox.

This Makefile at the moment supports the basic and PvrShell examples (01..05) but does not yet support PvrTools examples (06 and above).

To compile some of PoverVR tutorial examples, you can use the following Makefile

CC=g++

CPPFLAGS = -DBUILD_OGLES2
LDLIBS=-lEGL -lX11 -lGLESv2 

all:OGLES2Texturing OGLES2BasicTnL OGLES2IntroducingPVRTools OGLES2HelloTriangle_LinuxX11

OGLES2HelloTriangle_LinuxX11:OGLES2HelloTriangle_LinuxX11.o

OGLES2Texturing: PVRShellOS.o OGLES2Texturing.o  PVRShell.o PVRShellAPI.o

OGLES2BasicTnL: PVRShellOS.o OGLES2BasicTnL.o  PVRShell.o PVRShellAPI.o

OGLES2IntroducingPVRTools: PVRShellOS.o OGLES2IntroducingPVRTools.o  PVRShell.o PVRShellAPI.o

Using with QGLWidget

There is in Qt 4.5 ready made example hellogl_es2 that can be found from examples/opengl/hellogl_es2 directory. There is also equivalent examples for desktop opengl and opengl_es2 .

The example is also good showing what is different between OpenGL versions. The hellogl uses plain desktop "glBegin / glEnd" functions with display lists. Hellogl_es2 uses vertex attribute pointers and shaders instead of glBegin/glEnd. The helloes_gl2 is even more complicated because it uses programmable shaders instead fixed pipeline in both of the previous exaples.

If you try compile yourself unmodified version of hellogl_es2 for maemo, you need to add in void GLWidget::initializeGL ()

Line in beginning
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
and after shaders has been compiled line
 setlocale(LC_ALL, ""); // restore locale

because locale affects in shader compilation even it should not do