2
votes

For a while I've been using SDL to write my 3D engine,and have recently been implementing an editor that can export an optimized format for the type of engine Im building. Right now the editor is fairly simple, objects can just be moved around and their textures and models can be changed. As of right now, I'm using SDL with OpenGL to render everything, but I want to use Qt for the GUI part of the editor, that way it looks native on every platform. I've got it working great so far, I'm running a QApplication inside of the SDL application, so it basically just opens 2 windows, one that uses SDL and OpenGL, and the other using Qt. Doing a bit of research, I've found that you can manually update a QApplication, which totally removes any threading problems, and everything works. Just in case you're having a hard time visualizing this, heres a picture:

enter image description here

What my goal is to merge these windows into one, because on smaller screens (like my laptop's) it makes it really hard to keep track of all the different windows that I would eventually have. I know theres a way to render to Qt with OpenGL, but can this be integrated with SDL? Am I going to need to move away from using an SDL window and use a QT one if the editor is enabled? Just to clarify, when the engine isn't in editor mode, it won't use and Qt, just SDL, so optimally I wouldn't need to do this.

2
'I'm running a QApplication inside of the SDL application', do you mean you are starting both SDL and Qt on the single executable or you are loading a Qt opengl context inside an SDL window? Eitherway this is very interesting, mind sharing any sources on running both Qt and SDL?senex
@Alex720 They're both running in the same executable, basically it goes: Init SDL, Init QT, while (running) updateQT updateEngine renderSDL. I want to know how to embed a SDL context into a Qt windowBlueSpud
@BlueSpud - since you are using a Qt window, might as well drop SDL as a dependency as datenwolf suggested, the stuff SDL does you already have in Qt, you will remove redundancies. Also, this video might help you out with embedding third party opengl rendering with Qt: youtube.com/watch?v=GYa5DLV6ADQdtech

2 Answers

0
votes

Drop the SDL part. You have Qt, which does everything SDL does as well. Just subclass a QGLWidget and use that.

0
votes

You can keep your game and editor separate processes and still make them part of the same app.

Just spawn the window where you want the game to run as part of Qt, and at least in windows, you can then pass the window handle to your game, and make sure when your game is setting up, instead of creating the window yourself in SDL and binding the opengl context to it, you can actually bind to the existing handle.

There are some gotchas with this technique to watch out for such as input focus I believe (I tested with directX, but it might be similar with SDL). The problem is that the foreground mode does some dumb checks on the "root" window which for me was not the window that owned the opengl context, so it failed to initialize. However background mode worked. I think that was for a joystick now that I think about it, but anyway, that's how you can merge everything together.