Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Black screen and normal using QOpenGLContext + QQuickWindow
Forum Updated to NodeBB v4.3 + New Features

Black screen and normal using QOpenGLContext + QQuickWindow

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
16 Posts 3 Posters 3.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BrunoGSAB Offline
    BrunoGSAB Offline
    BrunoGSA
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Without showing your code, it's only going to be guess work. Please show what you are currently using.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • BrunoGSAB Offline
        BrunoGSAB Offline
        BrunoGSA
        wrote on last edited by BrunoGSA
        #3

        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](0_1549233122400_opengl-qt.png image url)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          BrunoGSAB 1 Reply Last reply
          0
          • SGaistS SGaist

            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 ?

            BrunoGSAB Offline
            BrunoGSAB Offline
            BrunoGSA
            wrote on last edited by
            #5

            @SGaist

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              So nothing QtQuick related ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              BrunoGSAB 1 Reply Last reply
              0
              • SGaistS SGaist

                So nothing QtQuick related ?

                BrunoGSAB Offline
                BrunoGSAB Offline
                BrunoGSA
                wrote on last edited by
                #7

                @SGaist
                No. It just happens with QQuickWindow.
                It seems QQuickWindow also update (repaints) the screen in another thread.

                T 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  BrunoGSAB 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    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.

                    BrunoGSAB Offline
                    BrunoGSAB Offline
                    BrunoGSA
                    wrote on last edited by
                    #9

                    @SGaist if I use QOpenGLWindow, how do I put QTQuickControls on the window? Is it possible?

                    1 Reply Last reply
                    0
                    • BrunoGSAB BrunoGSA

                      @SGaist
                      No. It just happens with QQuickWindow.
                      It seems QQuickWindow also update (repaints) the screen in another thread.

                      T Offline
                      T Offline
                      Tom_H
                      wrote on last edited by
                      #10

                      @BrunoGSA QQuickWindow clears the color buffer before rendering. Try calling setClearBeforeRendering(false) on your QQuickWindow.

                      BrunoGSAB 1 Reply Last reply
                      0
                      • T Tom_H

                        @BrunoGSA QQuickWindow clears the color buffer before rendering. Try calling setClearBeforeRendering(false) on your QQuickWindow.

                        BrunoGSAB Offline
                        BrunoGSAB Offline
                        BrunoGSA
                        wrote on last edited by
                        #11

                        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 ... );
                        }

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @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.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          BrunoGSAB 1 Reply Last reply
                          1
                          • SGaistS SGaist

                            @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.

                            BrunoGSAB Offline
                            BrunoGSAB Offline
                            BrunoGSA
                            wrote on last edited by
                            #13

                            @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.

                            T 1 Reply Last reply
                            0
                            • BrunoGSAB BrunoGSA

                              @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.

                              T Offline
                              T Offline
                              Tom_H
                              wrote on last edited by
                              #14

                              @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:

                              https://youtu.be/D-7fVGIBz6k

                              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.

                              1 Reply Last reply
                              2
                              • BrunoGSAB Offline
                                BrunoGSAB Offline
                                BrunoGSA
                                wrote on last edited by
                                #15

                                I changed to use QOpenglWidget. I have seen it is not deprecated and meet my requirements.

                                Now I can open a window with QT controls and render opengl frames as part of the screen.

                                Thank you everyone!

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  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 :)

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved