OpenGL-ES

(Qt Example)
 
(19 intermediate revisions not shown)
Line 1: Line 1:
-
[[Category:Development]]
 
== OpenGL ES  ==
== 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.
+
OpenGL ES is an API that allows programmers to draw 3D graphics on mobile and embedded devices. Hardware accelerated OpenGL ES 1.1 and 2.0 are available on Maemo devices beginning with the [[Nokia N900|N900]].
-
 
+
-
=== Books about OpenGL ES ===
+
-
 
+
-
* [http://www.amazon.com/Mobile-3D-Graphics-Kaufmann-Computer/dp/0123737273/ref=sr_1_1?ie=UTF8&s=books&qid=1235944663&sr=8-1 Mobile 3D graphics with OpenGL ES and M3G]
+
-
 
+
-
Excellent introductory section covering OpenGL basics. Covers ES 1.1, not ES 2.0.
+
-
 
+
-
* [http://www.amazon.com/OpenGL%20ES-2-0-Programming-Guide/dp/0321502795/ref=sr_1_1?ie=UTF8&s=books&qid=1235944783&sr=1-1 OpenGL ES 2.0 programming guide]
+
-
 
+
-
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 ===
+
-
 
+
-
* [http://www.khronos.org/opengles/2_X/ Khronos OpenGL ES documentation and specifications]
+
-
 
+
-
=== Imagination Technologies SDK ===
+
-
 
+
-
* [http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES2xSGX.asp OpenGL ES SDK]
+
-
 
+
-
=== Other related documentation ===
+
-
 
+
-
* [http://blogs.forum.nokia.com//data/blogs/resources/300003/fremantle_bossa_2009.pdf Kate's presentation in Bossa 2009 conference] about Fremantle and section about OpenGL ES 2.0
+
=== OpenGL variants ===
=== OpenGL variants ===
Line 32: Line 9:
[[image:Opengl.svg]]
[[image:Opengl.svg]]
-
* OpenGL 1.0 has fixed shaders and fixed function API to using them
+
OpenGL 1.0 has fixed shaders and fixed function API for using them. OpenGL 2.0 adds programmable shaders, but fixed function pipeline API is still supported for backward compatibility.
-
* 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
+
In contrast, 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.
-
* OpenGL ES 2.0 is based on OpenGL 2.0 with the fixed function API removed
+
=== Porting between OpenGL variants ===
=== Porting between OpenGL variants ===
-
* OpenGL 1.0 application works with OpenGL 2.0 but not vice versa
+
All versions and variants of OpenGL are not directly compatible, so a certain amount of changes are needed when moving applications from one variant to another. The following diagram summarizes these changes for major OpenGL versions.
-
* 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.
+
[[image:Opengl-porting.svg]]
-
=== Compiling under scratchbox ===
+
OpenGL 1.0 applications work with OpenGL 2.0 but not vice versa. OpenGL 1.0 applications can be ported to OpenGL ES 1.1, but need changes if they are 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 due to , e.g., differences in the shading language versions. Finally, 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.
-
An excellent way to familiarize yourself with OpenGL ES 2.0 which is to try the tutorials that can be found in the [http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES2xSGX.asp PowerVR SGX SDK] under the TrainingCourse directory.
+
Most 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.
-
The SDK libs and headers can be dropped into your X86 environment and run into
+
== Getting started ==
-
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.
+
An excellent way to familiarize yourself with OpenGL ES 2.0 is to try the tutorials that can be found in the [http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES2xSGX.asp PowerVR SGX SDK] under the TrainingCourse directory.
-
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
+
The SDK libs and headers can be dropped into your Scratchbox X86 environment and run inside the Xephyr X11 window - but you'll need to kill the window manager first!
-
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
+
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.  
-
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
+
This Makefile at the moment supports the basic and PvrShell examples (01..05) but does not yet support PvrTools examples (06 and above). 
-
<pre>
+
 
 +
To compile some of PowerVR tutorial examples, you can use the following Makefile
 +
<source lang="make">
CC=g++
CC=g++
Line 80: Line 49:
OGLES2IntroducingPVRTools: PVRShellOS.o OGLES2IntroducingPVRTools.o  PVRShell.o PVRShellAPI.o
OGLES2IntroducingPVRTools: PVRShellOS.o OGLES2IntroducingPVRTools.o  PVRShell.o PVRShellAPI.o
-
</pre>
+
</source>
-
=== Using with QGLWidget ===
+
=== Installation ===
-
There is in Qt 4.5 ready made example hellogl_es2 that can be found from
+
You can compile OpenGL ES applications with Scratchbox. The ESBox IDE makes it much easier to execute the application on the device. It automates copying the binary onto the device and execution.
-
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.
+
Firstly you want to install the following packages in Scratchbox.
-
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,
+
[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install libgles2-sgx-img-dev
-
you need to add in <b>void GLWidget::initializeGL ()</b>
+
 
 +
This installs the OpenGL ES 2.0 development files required for compiling.
 +
 
 +
[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install opengles-sgx-img-common-dev
 +
 
 +
This installs the EGL library (used for portable context creation, see the documentation) and PowerVR development files. It also includes some simple demos.
 +
 
 +
If you want OpenGL ES 1.x compatibility then install the following package in Scratchbox:
 +
 
 +
[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install libgles1-sgx-img-dev
 +
 
 +
Now install the required libraries on the N900:
 +
 
 +
Nokia-N900-42-11:~# apt-get install libgles1-sgx-img libgles2-sgx-img opengles-sgx-img-common
 +
 
 +
== Library support ==
 +
 
 +
This section includes a partial list of library options for using OpenGL ES.
 +
 
 +
=== SDL 1.2 + SDL-GLES ===
 +
 
 +
The N900 ships with SDL 1.2. You can use that and a external library, [[User:Javispedro/SDL-GLES|SDL-GLES]] (available in extras), to create simple OpenGL ES 1.1 and 2.0 applications.
 +
 
 +
[http://maemo.org/packages/view/nehegles/ NeHeGLES] is a port of several of the famous [http://nehe.gamedev.net/ NeHe OpenGL lessons] to Maemo5/SDL-GLES.
 +
 
 +
=== SDL 1.3 ===
 +
 
 +
SDL 1.3 supports OpenGL ES 1.x. This does not seem to work in the N900 as of now.
 +
 
 +
=== OpenGL ES 1.x utilies ===
 +
Information:
 +
: http://www.unrealvoodoo.org/hiteck/projects/maemo/
 +
Git repositories:
 +
: http://www.unrealvoodoo.org/git/
 +
 
 +
Sami Kyöstilä has developed a number of utilities. This includes SDL with OpenGL ES 1.x support, libglutes, python-opengles and several translators to convert OpenGL ES and OpenGL. Note that these utilities are designed for the [[Nokia N810]] and OpenGL ES 1.x.
 +
 
 +
=== Qt ===
 +
 
 +
You can use [[Qt-Maemo|Qt]] with OpenGL ES 2.x on the N900.
 +
 
 +
=== Clutter ===
 +
 
 +
libclutter supports OpenGL ES 2.x and OpenGL ES 1.1. It is oriented towards toolkits and applications with user interface elements.
 +
 
 +
=== Xlib (X11) ===
 +
 
 +
You can use Xlib (X11) and utilize the EGL library for context creation along with OpenGL ES. This is what the [http://maemo.nokia.com/maemo-select/applications/bounce-evolution Bounce Evolution] game uses.
 +
 
 +
You can use OpenGL ES version 1 or 2 directly without worrying about the version that is supported by the library.
 +
 
 +
See below for [[#Xlib Examples|an example Xlib application]].
 +
 
 +
=== PVRShell ===
 +
 
 +
The Khronos OpenGL ES 2.0 SDK includes a simple API for window creation called PVRShell. They also include additional tools for more advanced computer graphics applications. It is much simpler to create an OpenGL ES 2.0 application using PVRShell. It doesn't seem to have much support for handling events.
 +
 
 +
== Examples ==
 +
 
 +
=== Qt Example ===
 +
 
 +
You need to install libqt4-opengl-dev:
 +
<pre>[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install libqt4-opengl-dev</pre>
 +
 
 +
There is an example application called hellogl_es2. There is also equivalent examples for desktop opengl and opengl_es2. Get it here:
 +
: http://qt.gitorious.org/qt/qt/trees/4.5/examples/opengl/hellogl_es2
 +
 
 +
This example shows how to use OpenGL ES embedded in a QtWidget. The example is also good showing what is different between OpenGL versions. hellogl uses plain desktop "glBegin / glEnd" functions with display lists. hellogl_es2 uses vertex attribute pointers and shaders instead of glBegin/glEnd. helloes_gl2 is even more complicated because it uses programmable shaders instead of fixed pipeline in both of the previous examples.
 +
 
 +
If you try to compile the unmodified version of hellogl_es2 for Maemo, you need to add in <code>void GLWidget::initializeGL ()</code>. Modify glwidget.h and change <code>#include <QGLWidget></code> to <code>#include <QtOpenGL/QGLWidget></code>.
Line in beginning  <pre>setlocale(LC_NUMERIC, "C"); // Reset locale for compilation</pre>
Line in beginning  <pre>setlocale(LC_NUMERIC, "C"); // Reset locale for compilation</pre>
and after shaders has been compiled line <pre> setlocale(LC_ALL, ""); // restore locale</pre>
and after shaders has been compiled line <pre> setlocale(LC_ALL, ""); // restore locale</pre>
-
because locale affects in shader compilation even it should not do
+
because locale affects in shader compilation even it should not do.
 +
 
 +
Edit <code>hellogl_es2.pro</code> and add:
 +
 
 +
<pre>QT += opengl</pre>
 +
 
 +
Then run:<pre>qmake -project
 +
qmake
 +
make
 +
</pre>
 +
 
 +
Which will (hopefully) compile hellogl_es2. Then you can copy the binary to the device and run it.
 +
 
 +
=== Xlib Examples ===
 +
 
 +
You can usually compile any Xlib example with a simple Makefile like:
 +
<source lang="make">
 +
CC=g++
 +
LDLIBS=-lEGL -lX11 -lGLESv2
 +
all: main
 +
main: main.o
 +
</source>
 +
In the PowerVR SDK TrainingCourse directory there are a number of examples. The first two use only Xlib. The rest make use of PowerVR libraries which have to be linked in with the program.
 +
 
 +
There is a [[SimpleGL example | simple Xlib example]] in a separate article.
 +
 
 +
=== SDL-GLES Example ===
 +
 
 +
The NeHeGLES examples are available from extras-devel. Within armel-scratchbox, a simple
 +
 
 +
<pre>fakeroot apt-get build-dep nehegles</pre>
 +
 
 +
will install all the necessary libraries. An additional
 +
 
 +
<pre>fakeroot apt-get source nehegles</pre>
 +
 
 +
will then install the sourcecode of the nehegles lessons. A "make" in the nehegles root directory builds all the included lessons as well as the gui. Individual lessons can be recompiled by a simple "make" in their respective directories.
 +
 
 +
=== Python example ===
 +
On [http://orgetik.de/wp/wordpress/?tag=opengl-n900&lang=en] you can find xlib_wrapper.py and opengltest.py (port of SimpleGL example).
 +
 
 +
== Notes ==
 +
 
 +
* WARNING: If you try to run an OpenGL application with scratchbox then it will most likely work. This is because it uses the native operating system OpenGL libraries to execute. However, if you try and run it on the device it will not work as it only has OpenGL ES libraries.
 +
 
 +
* OpenGL ES does not run natively on a desktop computer. It is possible to get some kind of emulation library from the PowerVR Insider SDK [http://www.imgtec.com/powervr/insider/powervr-sdk.asp] so that you can test on a desktop computer. The OpenGL ES 2.0 emulation library was packaged for use inside the FREMANTLE_X86 scratchbox target (package libgles2-dev, extras-devel non-free repository).
 +
 
 +
* If you require any kind of performance in Maemo 5, you need to make your window full screen.
 +
 
 +
== Further reading ==
 +
 
 +
Here are some useful resources.
 +
 
 +
* http://www.unrealvoodoo.org/hiteck/projects/maemo/ - Maemo Experiments
 +
* http://qt.gitorious.org/qt/qt/trees/4.5/examples/opengl/hellogl_es2 - hellogl_es2 example for Qt 4.5
 +
* http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES2xSGX.asp - Khronos OpenGL ES 2.0 SDK has useful examples
 +
* http://talk.maemo.org/showthread.php?t=37356 - Thread discussing performance of OpenGL ES
 +
* [[Game_development]] - Page describing game development on Maemo. More oriented towards 2D games but has some useful information
 +
* http://www.forum.nokia.com/info/sw.nokia.com/id/0ea5ec64-2d35-4363-94c0-dd2560c6524b/Get_started_with_Maemo_5.html - If you don't know how to start with Maemo development in general then look here
 +
* http://repository.maemo.org/ - Information about repositories
 +
* http://www.khronos.org/opengles/sdk/docs/man/ - OpenGL ES 2.0 Reference Page
 +
* http://www.khronos.org/opengles/sdk/1.1/docs/man/ - OpenGL ES 1.1 Reference Page. It also has information about EGL
 +
* http://n2.nabble.com/Fremantle-OpenGL-wrapper-td3013572.html - Thread discussing ideas about OpenGL and Maemo
 +
* [http://blogs.forum.nokia.com//data/blogs/resources/300003/fremantle_bossa_2009.pdf Kate Alhola's presentation in Bossa 2009 conference] about Fremantle and section about OpenGL ES 2.0
 +
 
 +
=== Books ===
 +
 
 +
* [http://www.amazon.com/Mobile-3D-Graphics-Kaufmann-Computer/dp/0123737273/ref=sr_1_1?ie=UTF8&s=books&qid=1235944663&sr=8-1 Mobile 3D graphics with OpenGL ES and M3G] &ndash; Excellent introductory section covering OpenGL basics. Covers OpenGL ES 1.1, not 2.0.
 +
* [http://www.amazon.com/OpenGL%20ES-2-0-Programming-Guide/dp/0321502795/ref=sr_1_1?ie=UTF8&s=books&qid=1235944783&sr=1-1 OpenGL ES 2.0 programming guide] &ndash; This '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.
 +
 
 +
 
 +
[[Category:Development]]
 +
[[Category:N900]]

Latest revision as of 14:04, 10 October 2010

Contents

[edit] OpenGL ES

OpenGL ES is an API that allows programmers to draw 3D graphics on mobile and embedded devices. Hardware accelerated OpenGL ES 1.1 and 2.0 are available on Maemo devices beginning with the N900.

[edit] 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 for using them. OpenGL 2.0 adds programmable shaders, but fixed function pipeline API is still supported for backward compatibility.

In contrast, 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.

[edit] Porting between OpenGL variants

All versions and variants of OpenGL are not directly compatible, so a certain amount of changes are needed when moving applications from one variant to another. The following diagram summarizes these changes for major OpenGL versions.

image:Opengl-porting.svg

OpenGL 1.0 applications work with OpenGL 2.0 but not vice versa. OpenGL 1.0 applications can be ported to OpenGL ES 1.1, but need changes if they are 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 due to , e.g., differences in the shading language versions. Finally, 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 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.

[edit] Getting started

An excellent way to familiarize yourself with OpenGL ES 2.0 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 Scratchbox X86 environment and run inside the Xephyr X11 window - but you'll need to kill the window manager first!

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 PowerVR 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

[edit] Installation

You can compile OpenGL ES applications with Scratchbox. The ESBox IDE makes it much easier to execute the application on the device. It automates copying the binary onto the device and execution.

Firstly you want to install the following packages in Scratchbox.

[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install libgles2-sgx-img-dev

This installs the OpenGL ES 2.0 development files required for compiling.

[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install opengles-sgx-img-common-dev

This installs the EGL library (used for portable context creation, see the documentation) and PowerVR development files. It also includes some simple demos.

If you want OpenGL ES 1.x compatibility then install the following package in Scratchbox:

[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install libgles1-sgx-img-dev

Now install the required libraries on the N900:

Nokia-N900-42-11:~# apt-get install libgles1-sgx-img libgles2-sgx-img opengles-sgx-img-common

[edit] Library support

This section includes a partial list of library options for using OpenGL ES.

[edit] SDL 1.2 + SDL-GLES

The N900 ships with SDL 1.2. You can use that and a external library, SDL-GLES (available in extras), to create simple OpenGL ES 1.1 and 2.0 applications.

NeHeGLES is a port of several of the famous NeHe OpenGL lessons to Maemo5/SDL-GLES.

[edit] SDL 1.3

SDL 1.3 supports OpenGL ES 1.x. This does not seem to work in the N900 as of now.

[edit] OpenGL ES 1.x utilies

Information:

http://www.unrealvoodoo.org/hiteck/projects/maemo/

Git repositories:

http://www.unrealvoodoo.org/git/

Sami Kyöstilä has developed a number of utilities. This includes SDL with OpenGL ES 1.x support, libglutes, python-opengles and several translators to convert OpenGL ES and OpenGL. Note that these utilities are designed for the Nokia N810 and OpenGL ES 1.x.

[edit] Qt

You can use Qt with OpenGL ES 2.x on the N900.

[edit] Clutter

libclutter supports OpenGL ES 2.x and OpenGL ES 1.1. It is oriented towards toolkits and applications with user interface elements.

[edit] Xlib (X11)

You can use Xlib (X11) and utilize the EGL library for context creation along with OpenGL ES. This is what the Bounce Evolution game uses.

You can use OpenGL ES version 1 or 2 directly without worrying about the version that is supported by the library.

See below for an example Xlib application.

[edit] PVRShell

The Khronos OpenGL ES 2.0 SDK includes a simple API for window creation called PVRShell. They also include additional tools for more advanced computer graphics applications. It is much simpler to create an OpenGL ES 2.0 application using PVRShell. It doesn't seem to have much support for handling events.

[edit] Examples

[edit] Qt Example

You need to install libqt4-opengl-dev:

[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install libqt4-opengl-dev

There is an example application called hellogl_es2. There is also equivalent examples for desktop opengl and opengl_es2. Get it here:

http://qt.gitorious.org/qt/qt/trees/4.5/examples/opengl/hellogl_es2

This example shows how to use OpenGL ES embedded in a QtWidget. The example is also good showing what is different between OpenGL versions. hellogl uses plain desktop "glBegin / glEnd" functions with display lists. hellogl_es2 uses vertex attribute pointers and shaders instead of glBegin/glEnd. helloes_gl2 is even more complicated because it uses programmable shaders instead of fixed pipeline in both of the previous examples.

If you try to compile the unmodified version of hellogl_es2 for Maemo, you need to add in void GLWidget::initializeGL (). Modify glwidget.h and change #include <QGLWidget> to #include <QtOpenGL/QGLWidget>.

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.

Edit hellogl_es2.pro and add:

QT += opengl
Then run:
qmake -project
qmake
make

Which will (hopefully) compile hellogl_es2. Then you can copy the binary to the device and run it.

[edit] Xlib Examples

You can usually compile any Xlib example with a simple Makefile like:

 CC=g++
 LDLIBS=-lEGL -lX11 -lGLESv2 
 all: main
 main: main.o

In the PowerVR SDK TrainingCourse directory there are a number of examples. The first two use only Xlib. The rest make use of PowerVR libraries which have to be linked in with the program.

There is a simple Xlib example in a separate article.

[edit] SDL-GLES Example

The NeHeGLES examples are available from extras-devel. Within armel-scratchbox, a simple

fakeroot apt-get build-dep nehegles

will install all the necessary libraries. An additional

fakeroot apt-get source nehegles

will then install the sourcecode of the nehegles lessons. A "make" in the nehegles root directory builds all the included lessons as well as the gui. Individual lessons can be recompiled by a simple "make" in their respective directories.

[edit] Python example

On [1] you can find xlib_wrapper.py and opengltest.py (port of SimpleGL example).

[edit] Notes

  • WARNING: If you try to run an OpenGL application with scratchbox then it will most likely work. This is because it uses the native operating system OpenGL libraries to execute. However, if you try and run it on the device it will not work as it only has OpenGL ES libraries.
  • OpenGL ES does not run natively on a desktop computer. It is possible to get some kind of emulation library from the PowerVR Insider SDK [2] so that you can test on a desktop computer. The OpenGL ES 2.0 emulation library was packaged for use inside the FREMANTLE_X86 scratchbox target (package libgles2-dev, extras-devel non-free repository).
  • If you require any kind of performance in Maemo 5, you need to make your window full screen.

[edit] Further reading

Here are some useful resources.

[edit] Books

  • Mobile 3D graphics with OpenGL ES and M3G – Excellent introductory section covering OpenGL basics. Covers OpenGL ES 1.1, not 2.0.
  • OpenGL ES 2.0 programming guide – This '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.