QOpenGLWidget with QApplication?

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?

+3
source share
1 answer

I do a little work here.

Your OpenGL probably does ANGLE by default. And your previous applications, OpenGL calls are platform specific OpenGL APIs.

try setting the attribute below for your QApplication object.

 appObject->setAttribute(Qt::AA_UseDesktopOpenGL, true); 

then try calling

 QOpenGLWidget::makeCurrent(); 

If still not working, set up your QT libraries for the OpenGL desktop.

 configure -opengl desktop 

the link below gives you some information about Qt's approach to OpenGL. http://doc.qt.io/qt-5/windows-requirements.html

Insert comments, if this does not help you, delete the answer.

0
source

Source: https://habr.com/ru/post/990011/


All Articles