How do I use Qt and SDL together?(如何同时使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何同时使用 Qt 和 SDL?
基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
