尝试将QML用户界面渲染到SDL窗口中。
有一个使用SDL_SetVideoMode
和SDL_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。
如何使其正常工作?
libopenage/gui/guisys
目录复制粘贴到您的项目中,并查看在libopenage/gui_basic.h
和libopenage/gui_basic.cpp
中如何进行集成。它可以在 Linux 上运行,如果您真的需要 Windows - 我可以发布一个小补丁来使其在 Windows 上运行。顺便说一句,它的最小版本(没有错误检查,有很多内存泄漏和硬编码,仅限于 Linux):https://github.com/ChipmunkV/openage/commit/c2eb84bbfc22119f04dd32ed860f987716edb6c8 - Velkan