在SDL上渲染QtQuick GUI

5

尝试将QML用户界面渲染到SDL窗口中。

有一个使用SDL_SetVideoModeSDL_OPENGLBLIT标志创建OpenGL上下文的SDL 1.2游戏。

思路是获取OpenGL上下文句柄并将其传递给QQuickRenderControl,以在场景上绘制GUI。

获取本地上下文(X11的示例):

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

采用Qt技术:

在Qt中采用它:

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

创建QQuickRenderControl:

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

但是QQuickRenderControl无法在没有QWindow的情况下启动:
QQuickRenderControl::initialize called with no associated window

另外,ctx->isValid()ctx->makeCurrent() 返回 false。

如何使其正常工作?

1个回答

4

至少使用SDL2是可能的。

Qt应用程序单例必须运行,窗口必须从本地句柄中提取并传递给RenderControl。


请问您能否提供更多信息?即使在使用SDL2时,我得到了ctx->isValid()返回false。 - Miguel El Merendero
1
@MiguelElMerendero,这是一个使用 https://github.com/SFTtech/openage 的项目。您可以将 libopenage/gui/guisys 目录复制粘贴到您的项目中,并查看在 libopenage/gui_basic.hlibopenage/gui_basic.cpp 中如何进行集成。它可以在 Linux 上运行,如果您真的需要 Windows - 我可以发布一个小补丁来使其在 Windows 上运行。顺便说一句,它的最小版本(没有错误检查,有很多内存泄漏和硬编码,仅限于 Linux):https://github.com/ChipmunkV/openage/commit/c2eb84bbfc22119f04dd32ed860f987716edb6c8 - Velkan
谢谢,你的例子很有用!不幸的是,它对我没有起作用,我在Windows上并且修改了一些代码,但我仍然无法获得有效的上下文。我不明白为什么,我在这里打开了这个问题:http://forum.qt.io/topic/68383/qtquick-into-an-sdl2-window/4 - Miguel El Merendero
1
@MiguelElMerendero,此外还有一个示例在QTBUG-50309中(请参见附件中的zip文件)。 - Velkan
让我们在聊天中继续这个讨论 - Velkan
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接