Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling OpenGL functions outside InitializeGL / PaintGL
Forum Updated to NodeBB v4.3 + New Features

Calling OpenGL functions outside InitializeGL / PaintGL

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.1k Views 2 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.
  • A Offline
    A Offline
    asaf-wa
    wrote on last edited by
    #1

    I'm using a 3rd party rendering library, and when I try to load a model from the menu bar, it crashes.

    The way I'm set up is having a QMainWindow as the main window of the application. Inside this window, I have both the menu bar, and a QDockWidget that contains a QOpenGLWidget.
    The QOpenGLWidget handles GL initialization and painting via initializeGL and paintGL, respectively.

    If I place my model loading code manually inside either of these functions (initializeGL and paintGL), then everything works correctly.
    However, if I bind the model load function to the QMainWindow via the creation of a corresponding QMenu and QAction, then the application crashes.
    In fact, placing the model loading code anywhere outside initializeGL or paintGL functions, the application crashes.

    Is there a way to load a model outside the QOpenGLWidget without restructuring the entire application and 3D engine?
    Alternatively, how would I go about restructuring the application while retaining the functionality of having my 3D viewport inside a QDockWidget, and still be able to call GL functions?

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

      Hi and welcome to devnet,

      When these methods are called you have a valid OpenGL context to work with, which is not the case otherwise.

      When exactly would you like to load your 3D models ?

      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
      1
      • A Offline
        A Offline
        asaf-wa
        wrote on last edited by
        #3

        For example, from a QAction in a QMenu, for example, an Edit menu with a Load Model action.
        Since the QMenuBar and it's subsequent QMenu and QAction children use the signal connect syntax, I can't connect them to a GL function on the QOpenGLWidget.

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

          Then what about setting a flag stating that there's a new model to load, then in paintGL check that flag, load the model and clear it once done ?

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

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Then what about setting a flag stating that there's a new model to load, then in paintGL check that flag, load the model and clear it once done ?

            A Offline
            A Offline
            asaf-wa
            wrote on last edited by
            #5

            @SGaist said in Calling OpenGL functions outside InitializeGL / PaintGL:

            Then what about setting a flag stating that there's a new model to load, then in paintGL check that flag, load the model and clear it once done ?

            Yes, that is definitely one approach to consider.
            Is it not possible to do it any other way?
            I'd much prefer if it was somehow possible to call GL functions outside of these 2 specific functions, but if impossible I'd fall back to the method you suggested.

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

              You can't call OpenGL function at any time you want but that's not Qt specific. You have have to have a valid context and make it current. You can take a look at the Qt OpenGL examples in the sources to get more ideas.

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

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                You can't call OpenGL function at any time you want but that's not Qt specific. You have have to have a valid context and make it current. You can take a look at the Qt OpenGL examples in the sources to get more ideas.

                A Offline
                A Offline
                asaf-wa
                wrote on last edited by
                #7

                @SGaist
                Thanks. I was hoping it's possible, but I guess I'll have to make do with this workaround.

                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