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. Opengl functions outside QWindow

Opengl functions outside QWindow

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views
  • 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.
  • M Offline
    M Offline
    mattlikens
    wrote on last edited by
    #1

    I have a QWidget based program with a OpenGL window inherited from QWindow and QOpenGLFunctions_3_0:
    @class OpenGLWindow : public QWindow, protected QOpenGLFunctions_3_0
    {...}
    @

    Much like the "OpenGL Window Example":http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html I have a class that is subclassed from OpenGLWindow to do my particular OpenGL stuff. Let's call this class glWindow. The glWindow is contained in a QWidget using QWidget::createWindowContainer(glWindow);

    glWindow is getting cluttered and I would like to break out functionality in member classes. For example:
    @class glWindow : public OpenGLWindow
    {
    ...
    public:
    void render();
    private:
    customClass *m_cClass;
    }
    ...
    void glWindow::render()
    {
    m_cClass->render();
    }
    @

    How can I get the glfunctions to be available in the customClass?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      A couple of options spring to mind:

      1. Don't inherit and instead get a pointer to the functions object from QOpenGLContext::versionFunctions<QOpenGLFunctions_3_0>(). Pass thsi pointer around.

      2. Just get another pointer to the functions object wherever you need it by first getting the current context and then using the function mentioned above.

      When you call the QOpenGLContext::versionFunctions() function the context retains ownership of the functions object so that it can be cached.

      So something like this will do the job:

      @
      QOpenGLContext *ctx = QOpenGLContext::currentContext();
      m_funcs = ctx->versionFunctions<QOpenGLFunctions_3_0>();
      m_funcs->initializeOpenGLFunctions();
      @

      the last call is a noop if the functions have already been resolved.

      Hope this helps.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mattlikens
        wrote on last edited by
        #3

        Ah! QOpenGLContext::currentContext(); Great!

        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