How it works...

The OpenGL module must be added to the project file (.pro) in order to access header files that are related to OpenGL, such as QtOpenGL and QOpenGLFunctions. We used the QOpenGLWindow class instead of QMainWindow for the main window because it is designed to easily create windows that perform OpenGL rendering, and it offers better performance compared to QOpenGLWidget due to the fact that it has no dependencies in its widget module.

We must call setSurfaceType(QWindow::OpenGLSurface) to tell Qt we prefer to use OpenGL to render the images to screen instead of QPainter. The QOpenGLWindow class provides several virtual functions (initializeGL(), resizeGL(), paintGL(), and so on) for us to conveniently set up OpenGL and perform graphics rendering. We will be learning how to use these functions in the following example.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset