Using OpenGL in immediate mode
We will start with the most basic approach that's called immediate mode. In this mode, no additional setup of OpenGL buffers or shaders is required. You can just supply a bunch of geometric primitives and get the result right away. Immediate mode is now deprecated because it works much slower and is less flexible than more advanced techniques. However, it's so much easier than them that basically every OpenGL tutorial starts with describing the immediate mode calls. In this section, we'll show how to perform some simple OpenGL drawing with very little code. A more modern approach will be covered in the next section of this chapter.
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 Project
group as the template. In the project file, put the following content:
QT = core...