Setting up OpenGL in Qt
In this recipe, we will learn how to set up OpenGL in Qt 6.
How to do it…
Follow these steps to learn how to set up OpenGL in Qt:
- Create a new Qt Widgets Application by going to File | New Project. Uncheck the Generate form option to avoid generating the 
mainwindow.ui,mainwindow.h, andmainwindow.cppfiles. - Open up your project file (
.pro) and add the OpenGL module to your project by adding anopenglkeyword behindQT +=; after that, runqmaketo reload the project modules:QT += core gui opengl
 - You also need to add another line in your project file so that it will load both the OpenGL and OpenGL Utilities (GLU) libraries during startup. Without these two libraries, your program will not be able to run:
LIBS += -lopengl32 -lglu32
 - Open up 
main.cppand replacemainwindow.hwith theQtOpenGLheader:#include <QtOpenGL>
 - Remove all of the code related to the 
MainWindowclass from yourmain.cppfile and replace it with the code...