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
Forum Updated to NodeBB v4.3 + New Features

Opengl functions outside QWindow

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 1 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.
  • M Offline
    M Offline
    mattlikens
    wrote on 17 Nov 2013, 21:24 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 21 Nov 2013, 16:48 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 21 Nov 2013, 17:39 last edited by
        #3

        Ah! QOpenGLContext::currentContext(); Great!

        1 Reply Last reply
        0

        1/3

        17 Nov 2013, 21:24

        • Login

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