Time for action – drawing a triangle using Qt and OpenGL
For the first exercise, we will create a subclass of
QOpenGLWindow
that renders a triangle using simple OpenGL calls. Create a new project starting with Empty qmake Project from the Other Projects group as the template. In the project file, put the following content:
QT = core gui TARGET = triangle TEMPLATE = app
Having the basic project setup ready, let's define a SimpleGLWindow
class as a subclass of QOpenGLWindow
and override the initializeGL()
method to set white as the clear color of our scene. We do this by calling an OpenGL function called glClearColor
. Qt provides a convenience class called QOpenGLFunctions
that takes care of resolving most commonly used OpenGL functions in a platform-independent way. This is the recommended approach to access OpenGLES functions in a platform-independent manner. Our window is going to inherit not only QOpenGLWindow
but also QOpenGLFunctions
. However, since we don't want to allow external access...