Load OpenGL function pointers using glad withing a QOpenGLWidget

Viewed 1677

So I am reading up on some OpenGL and I want to use the QOpenGLWidget for drawing to maybe create some other helpful UI elements later. I am using glad for resolving the function pointers to OpenGL but I have no idea how to use Qt's getProcAddress function!

Inside my QOpenGLWidget subclass' initializeGL() function I have tried:

if(gladLoadGLloader((GLADloadproc) currentContext()->getProcAddress) {}

but that did not work out since Qt's function is overloaded. When I use

if(gladLoadGL()) {}

it doesn't work either. My includes are:

#include <glad\glad.h>
#include "OpenGLViewport.h"
#include <QDebug>
#include <QOpenGLContext>

I have searched Mr. Google and I've had a diligent look through the Qt documentation and found nothing. I want to use GLAD just so my rendering code is not bound to Qt too tightly, in case I want to switch later.

EDIT: I am aiming to use the noninstanced OpenGL functions with Qt (though the documentation recommends otherwise if I recall correctly). Because then I'd be able to seemlessly switch to GLFW for providing a window etc.

1 Answers
Related