QtQuick into an SDL2 window

  • Hello gentlemen

    Given an existing SDL_GLContext, what's the best approach to render QtQuick components into it?
    I see there's a QQuickRenderControl class which I can initialize with a QOpenGLContext, but I fail to see how to convert the SDL_GLContext into a QOpenGLContext.

  • @Illogica Hi! There is this nice Scene Graph - OpenGL Under QML example; might be helpful.

  • Thanks @Wieland for the response,
    all the examples I see show how to render into a Qt widget.
    What I want to do, is render QtQuick components inside the SDL window of my game engine.
    I found an example of this here but it's lacking a real implementation.
    It seems to me I need to use QOpenGLContext::setNativeHandle() passing it the GL context of my SDL window, but it would be extremely useful seeing a (cross platform) code example.

  • According to the QWGLNativeContext documentation and some online examples, I set up this little function to try and initialize a QOpenGLContext from an existing and already initialized SDL2 context:

    void QtHooks::initQtOpenGlContext(SDL_Window *screen)
        QOpenGLContext *context = new QOpenGLContext;
        SDL_SysWMinfo sysInfo;
        SDL_GetWindowWMInfo(screen, &sysInfo);
        HGLRC currentContext = wglGetCurrentContext();
        HWND currentWindow = sysInfo.info.win.window;
        QWGLNativeContext nativeContext(currentContext, currentWindow);
        assert(qtContext->isValid());   // <<-- this line always fails 
        context->create();       // if i remove the previous assert, this line kills the application very badly

    This little example always fails in the last two lines. Am I missing something?

Log in to reply