問題描述
我正在 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!