Black screen and normal using QOpenGLContext + QQuickWindow
-
When I use QOpenglContext with QQuickWindow, the screen gets dark for a frame e gets normal render (opengl partial view + QT Controls). Is there anything I am missing? I call swapBuffer and after that I call makeCurrent.
I saw everything is only one thread.
When I initialize the app I also call makeCurrent.Can anybody help me?
-
Hi,
Without showing your code, it's only going to be guess work. Please show what you are currently using.
-
Hi SGaist!
I found out that after I call swapBuffer, when I call any opengl funcion (e.g glGetError), the screen gets black for a frame and normal to another frame.
The code of the end of the my render function:
QOpenGLContext* glContext = QOpenGLContext::currentContext(); if (glContext == nullptr) return; glContext->makeCurrent(w); glContext->swapBuffers(w); GLenum error = glGetError(); // the error alternates for each frame (double buffer)
It seems like one buffer is completely empty, but I am always rendering every frame.
- BUT the OpenGL content area is always renderer. It happens just with the remaining area of the Window where the QT Controls is shown.
It seems that the window is not updated (painted) ... I do not known!
The imageS below shows the behavior. The images gets alternated on the screen. (the right side where the QT controls are, is not shown all the time)[alt text](
image url)
-
I might be wrong, but I think you might be using that class wrongly. It looks like you want to proceed a "classic" OpenGL operations. Shouldn't you be using QOpenGLWindow ?
-
QOpenGLWindow has the controls of main looping. The "render" function (called paint) must be overriden.
This project already have infrastructure to support GLFW, native Window and now QT support.
I settle on change to QT because it has lots of UI controls and nice features.In my main looping, I call QCoreApplication::processEvents() and the swapBuffer manually.
-
So nothing QtQuick related ?
-
Sorry, I meant: are you doing anything QtQuick related in your application ?
Threads can be involved, it's explained in the Rendering part of the QQuickWindow documentation.
-
Hi @Tom_H
I changed the code in order to use QOpenGLWindow.
It seems working. Now I want to test adding a QWidget on the screen aside OpenGL frame using the following code:MainWindow::MainWindow(QWidget *parent)
{
...
parent->layout()->addWidget( component ... );
} -
@BrunoGSA said in Black screen and normal using QOpenGLContext + QQuickWindow:
parent->layout()->addWidget( component ... );
That's a wrong thing to do. Parent might be nullptr, might not have any layout, etc.
Child widget should not know nor care about their parents. It's not their role to modify them.
-
@SGaist you are completely right. That did not work.
I solved with a big workaround.
I create another window (QWidget) and set ("no-header", transparent backgound, "always on top") in order to simulate the maind window with opengl renderer and the Controls on the surface (QWidget).It was the best option I found out using QT, unfortunately.
-
@BrunoGSA I'm not sure what exactly you're doing, but it sounds like you're doing it the hard way. There are several ways to do OpenGL and QtQuick, as described in this video:
The easiest is shown in the example
openglunderqml
, and is the first method described in the video. It's also the method I'm currently using. -
You're welcome !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum members may know solution has been found :)