33#include < iostream>
44#include < functional>
55
6- #include < QtWidgets/QOpenGLWidget>
7- #include < QOpenGLFunctions_4_1_Core> // problem is that this loads GL headers, so we don't load glad, further on
8- #include < QSurfaceFormat>
9- #include < QMouseEvent>
10- #include < QWheelEvent>
6+ class QOpenGLWidget ;
117
128// VisualOwnable is going to be owned by the QOpenGLWidget
139// Define mplot::win_t before #including mplot/VisualOwnableNoMX.h
1410namespace mplot { using win_t = QOpenGLWidget; }
1511#include < mplot/VisualOwnableNoMX.h>
12+
13+ #include < QtWidgets/QOpenGLWidget>
14+ #include < QOpenGLContext>
15+ #include < QSurfaceFormat>
16+ #include < QMouseEvent>
17+ #include < QWheelEvent>
18+
1619// We need to be able to convert from Qt keycodes to mplot keycodes
1720#include < mplot/qt/keycodes.h>
1821
@@ -22,8 +25,16 @@ namespace mplot {
2225 // This must match the QOpenGLFunctions_4_1_Core class you derive from
2326 constexpr int gl_version = mplot::gl::version_4_1;
2427
28+ struct OpenGLProcAddressHelper {
29+ inline static QOpenGLContext *ctx;
30+
31+ static QFunctionPointer getProcAddress (const char *name) {
32+ return ctx->getProcAddress (name);
33+ }
34+ };
35+
2536 // A mplot::VisualOwnable-based widget
26- struct viswidget : public QOpenGLWidget , protected QOpenGLFunctions_4_1_Core
37+ struct viswidget : public QOpenGLWidget
2738 {
2839 // Unlike the GLFW or mplot-in-a-QWindow schemes, we hold the mplot::VisualOwnable
2940 // inside the widget.
@@ -59,7 +70,8 @@ namespace mplot {
5970 void initializeGL () override
6071 {
6172 // Make sure we can call gl functions
62- initializeOpenGLFunctions ();
73+ OpenGLProcAddressHelper::ctx = context ();
74+ v.init_glad (OpenGLProcAddressHelper::getProcAddress);
6375 // Switch on multisampling anti-aliasing (with the num samples set in constructor)
6476 glEnable (GL_MULTISAMPLE);
6577 // Initialise mplot::VisualOwnable
0 commit comments