Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render QtQuick GUI over SDL

Tags:

qt

sdl

qt-quick

Trying to render QML user interface into the SDL window.

There is an SDL 1.2 game that creates an OpenGL context via SDL_SetVideoMode with SDL_OPENGLBLIT flag.

The idea is to get the OpenGL context handle and pass it to the QQuickRenderControl that will draw the GUI over the scene.

Getting the native context (example for X11):

GLXContext currentContext;
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
if (SDL_GetWMInfo(&wmInfo))
{
    Display *display = wmInfo.info.x11.gfxdisplay;
    currentContext = glXGetCurrentContext();
    assert(currentContext);
}

Adopting it in Qt:

QOpenGLContext *ctx = new QOpenGLContext;
ctx->setNativeHandle(QVariant::fromValue<QGLXNativeContext>(
    QGLXNativeContext(currentContext, wmInfo.info.x11.display, wmInfo.info.x11.window)
));

And creating the QQuickRenderControl:

QQuickRenderControl *renderControl = new QQuickRenderControl;
renderControl->initialize(ctx);

But QQuickRenderControl can't start without QWindow:

QQuickRenderControl::initialize called with no associated window

Also ctx->isValid() and ctx->makeCurrent() return false.

How to make it work?

like image 347
Velkan Avatar asked Sep 28 '22 05:09

Velkan


1 Answers

At least it's possible with SDL2.

Qt application singleton must be running, window must be extracted from the native handle and passed to the RenderControl.

like image 127
Velkan Avatar answered Nov 07 '22 15:11

Velkan