尝试将QML用户界面呈现到SDL窗口中.
有一个SDL 1.2游戏通过SDL_SetVideoMode带SDL_OPENGLBLIT标志创建一个OpenGL上下文.
我们的想法是获取OpenGL上下文句柄并将其传递给将在场景上绘制GUI的QQuickRenderControl.
获取本机上下文(X11的示例):
GLXContext currentContext;
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
if (SDL_GetWMInfo(&wmInfo))
{
Display *display = wmInfo.info.x11.gfxdisplay;
currentContext = glXGetCurrentContext();
assert(currentContext);
}
Run Code Online (Sandbox Code Playgroud)
在Qt中采用它:
QOpenGLContext *ctx = new QOpenGLContext;
ctx->setNativeHandle(QVariant::fromValue<QGLXNativeContext>(
QGLXNativeContext(currentContext, wmInfo.info.x11.display, wmInfo.info.x11.window)
));
Run Code Online (Sandbox Code Playgroud)
并创建QQuickRenderControl:
QQuickRenderControl *renderControl = new QQuickRenderControl;
renderControl->initialize(ctx);
Run Code Online (Sandbox Code Playgroud)
但是如果没有QWindow,QQuickRenderControl就无法启动:
QQuickRenderControl::initialize called with no associated window
Run Code Online (Sandbox Code Playgroud)
还ctx->isValid()和ctx->makeCurrent()返回false.
如何使它工作?