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. Creating a native OpenGL context with QOpenGLContext on a QWidget.

Creating a native OpenGL context with QOpenGLContext on a QWidget.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 4.8k 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.
  • C Offline
    C Offline
    cgcostume
    wrote on last edited by
    #1

    Hello,

    first of all, i'm very happy to see that Qt 5 and especially 5.1.0 starts to allow more and more native OpenGL with all those QOpenGL classes.

    My current problem: I try to provide a QWidget, that can support multiple OpenGL contexts for different APIs (plain, OSG, glut, Qt, etc.). I therefore use QSurface and the QSurfaceFormat for format description and wanted to use QOpenGLContext for native context creation. To provide a QSurface (which is abstract) instance, i have a Surface implmentation that returns the required settings. Only for the surfaceHandle i return nullptr, since the required type QPlatformSurface is not provided by the qt api.

    @QPlatformSurface * Surface::surfaceHandle() const
    {
    return nullptr;
    }
    @

    But with that the following happens on context creation:
    @ // src\gui\kernel\qopenglcontext.cpp
    ...
    bool QOpenGLContext::makeCurrent(QSurface *surface)
    {
    ...
    if (!surface->surfaceHandle())
    return false;
    ...
    @

    My question: Is there a way to provide a valid surfaceHandle? or is there a way to use QOpenGLContext in combination with other Surfaces than offscreen and QWindow (i.e. QWidget)?

    Alternatives?: I think about using QGLWidget again (which i initially discarded in favor for using the newer QOpenGL classes). Or one could use the offscreen surface and blit the target fbo.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cgcostume
      wrote on last edited by
      #2

      I also thought about embedding a QWindow inside a QWidget. But that seems to be far from its intended use cases.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cgcostume
        wrote on last edited by
        #3

        I just found that:

        bq. ... internally QGLWidget creates a QGLContext, and that is in turn implemented in terms of a QOpenGLContext from QtGui. ...
        http://www.kdab.com/opengl-in-qt-5-1-part-1/

        further more, there is this function:
        @
        QOpenGLContext * QGLContext::contextHandle() const
        @

        So i think in the case of the Qt/Native context one could use a QGLWidget instead of the QWidget, then create a QGLContext, that could return the QOpenGLContext which then can be used for further OpenGL rendering.

        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