如何同时使用 Qt 和 SDL? [英] How do I use Qt and SDL together?

查看:49
本文介绍了如何同时使用 Qt 和 SDL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Windows 中构建物理模拟引擎和编辑器.我想使用 Qt 构建编辑器部分,并且我想使用 SDL 和 OpenGL 运行引擎.

I am building a physics simulation engine and editor in Windows. I want to build the editor part using Qt and I want to run the engine using SDL with OpenGL.

我的第一个想法是仅使用 Qt 构建编辑器,并与引擎(资源管理器、渲染器、数学)共享尽可能多的代码.但是,我也希望能够在编辑器中运行模拟.这意味着我还必须分享使用 SDL 线程的模拟代码.

My first idea was to build the editor using only Qt and share as much code with the engine (the resource manager, the renderer, the maths). But, I would also like to be able to run the simulation inside the editor. This means I also have to share the simulation code which uses SDL threads.

所以,我的问题是:有没有办法使用 SDL 将 OpenGL 渲染到 Qt 窗口?

So, my question is this: Is there a way to have an the render OpenGL to a Qt window by using SDL?

我在网上读到,可能可以为 SDL 提供一个窗口句柄来进行渲染.有人有这方面的经验吗?

I have read on the web that it might be possible to supply SDL with a window handle in which to render. Anybody has experience dong that?

此外,模拟器的线程部分可能会造成问题,因为它使用 SDL 线程.

Also, the threaded part of the simulator might pose a problem since it uses SDL threads.

推荐答案

虽然您可能会像第一个答案一样让它工作,但您可能会因线程处理而遇到问题.在线程方面没有简单的解决方案,在这里您将有 SDL Qt 和 OpenGL 主循环交互.不好玩.

While you might get it to work like first answer suggest you will likely run into problems due to threading. There is no simple solutions when it comes to threading, and here you would have SDL Qt and OpenGL mainloop interacting. Not fun.

最简单、最明智的解决方案是将两个部分解耦.这样 SDL 和 Qt 在不同的进程中运行,并让它们使用某种消息传递进行通信(我在这里推荐 d-bus ).您可以将 SDL 渲染到无边框窗口中,并且您的编辑器通过消息发送命令.

The easiest and sanest solution would be to decouple both parts. So that SDL and Qt run in separate processes and have them use some kind of messaging to communicate (I'd recommend d-bus here ). You can have SDL render into borderless window and your editor sends commands via messages.

这篇关于如何同时使用 Qt 和 SDL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆