Hello GLES3 Example#

Demonstrates OpenGL ES 3.0 functions via QOpenGLExtraFunctions.



This example demonstrates easy, cross-platform usage of OpenGL ES 3.0 functions via QOpenGLExtraFunctions in an application that works identically on desktop platforms with OpenGL 3.3 and mobile/embedded devices with OpenGL ES 3.0.

This example has no QWidget dependencies, it uses QOpenGLWindow , a convenience subclass of QWindow that allows easy implementation of windows that contain OpenGL-rendered content. In this sense it complements the OpenGL Window Example , which shows the implementation of an OpenGL-based QWindow without using the convenience subclass.

The Qt logo shape implementation is included from the Hello GL2 Example .

In other aspects pertaining to using OpenGL there are the following differences.

  • The OpenGL context creation has to have a sufficiently high version number for the features that are in use.

  • The shader’s version directive is different.

Setting up in main.cpp#

Here we instantiate our QGuiApplication, QSurfaceformat and set its depth buffer size:

We request an OpenGL 3.3 core or OpenGL ES 3.0 context, depending on QOpenGLContext::openGLModuleType():

We set the default surface format and instantiate our GLWindow glWindow.

Implementing GLWindow#

This class delivers the features of the example application.

To start, GLWindow is declared by implementing a subclass of QOpenGLWindow :

The following properties are declared using Q_PROPERTY:

The following public functions are declared:

The following private objects are declared:

On the implementation side, those functions that are not declared inline are implemented (or re-implemented) in glwindow.cpp. The following selections will cover implementation particulars pertaining to the use of OpenGL ES 3.0.


The following code pertains to the animations, and won’t be explored here:

For more information see the documentation for QPropertyAnimation, QSequentialAnimationGroup.


The shaders are defined like so:


These are OpenGL version agnostic. We take this and append the version like so:

Initializing OpenGL#

Initializing the shader program in handled by initializeGL():

Now the OpenGL version is prepended and the various matrices and light position is set:

While not strictly required for ES 3, a vertex array object is created.

Resizing the window#

The perspective needs to be aligned with the new window size as so:


We use QOpenGLExtraFunctions instead of QOpenGLFunctions as we want to do more than what GL(ES) 2.0 offers:

We clear the screen and buffers and bind our shader program and texture:

Logic for handling an initial paintGL() call or a call after a resizeGL() call is implemented like so:

Last, we demonstrate a function introduced in OpenGL 3.1 or OpenGL ES 3.0:

This works because we earlier requested 3.3 or 3.0 context.

Example project @ code.qt.io