Hello world!
In this recipe, we will learn about the pipeline of OpenGL and how to render a simple shape to the window. We will continue from the example project used in the previous recipe.
How to do it…
- First of all, go to
mainwindow.hand add the following headers at the top of the source code:#include <QSurfaceFormat> #include <QOpenGLFunctions> #include <QtOpenGL> #include <GL/glu.h>
- Next, declare two private variables in
mainwindow.h:private: QOpenGLContext* context; QOpenGLFunctions* openGLFunctions;
- After that, move over to
mainwindow.cppand set the surface format to compatibility profile. We also set the OpenGL version to 2.1 and create the OpenGL context using the format we just declared. Then, use the context we just created to access the OpenGL functions that are relevant only to the OpenGL version we have just set, by callingcontext->functions():MainWindow::MainWindow(QWidget *parent) { setSurfaceType(QWindow::OpenGLSurface); QSurfaceFormat...
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime