We have a QWidget-based application that previously used QWindow to render OpenGL. To match this window in our application, we had to use
QWidget QWidget::createWindowContainer(QWindow);
Previously, we used only external Qt OpenGL libraries for rendering.
We want to switch from QWindow to some QWidget for compatibility with touch gestures and, as a rule, is better compatible with the rest of our application. The latest recommended OpenGL compatible QWidget seems to be QOpenGLWidget, so we are trying to use it.
glContext is the OpenGLContext that we control.
Now the problem is that QOpenGLWidget is not a QSurface, so I cannot call
glContext->makeCurrent(this);
to make the context as relevant to my custom QOpenGLWidget as we could before using our custom QWindow and our own OpenGLContext.
If I try to use QOpenGLWidget::makeCurrent(); , then this uses the wrong context and tries to do something with some kind of magical QT processed context or something that I donβt understand.
As a result, we create our OpenGLContext when we try to call
glFunctions = glContext->versionFunctions<QOpenGLFunctions_3_3_Core>(); if(!glFunctions->initializeOpenGLFunctions()) printf("Could not initialize OpenGL functions.");
It always cannot initialize OpenGL functions.
I read all the other resources that I can find on this issue, and came across this old stack overflow question that looked like: QOpenGLWidget with a common OpenGL context
The answer to this question did not solve my problem, because we are using QApplication, not QGuiApplication, since this is a QWidget based application. QGuiApplicationPrivate::init() never called, and QOpenGLContext::globalShareContext() returns a null pointer because it is not initialized.
Unfortunately, I canβt wait for QOpenGLWidget::initializeGL() to be initialized to initialize the QT- OpenGLContext , since we already have many OpenGL resources for different classes that are trying to initialize before that.
Anyone else run into this issue?
Any suggestions?