🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Using SDL, OpenGL and Qt Together

Started by
5 comments, last by Roots 9 years, 7 months ago

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:

prbjc.jpg

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.

Thanks.

Advertisement
I haven't used it yet but there is QQuickRenderControl which should allow exactly what you want, provided your UI is rendered with QML (but I personally don't want to do old-fashioned UI development since learning QML anyway).

I haven't used it yet but there is QQuickRenderControl which should allow exactly what you want, provided your UI is rendered with QML (but I personally don't want to do old-fashioned UI development since learning QML anyway).

Wouldn't the input break because its just an image? And I really need to not use qml because I need to be able to read the values from the c++ side.
Accessing C++ objects from QML (or the reverse) is not an issue. It is used a lot in my professional work and works fine and rather elegantly once you really start understanding it.

As I said, I haven't used it but the class is explicitly advertised as being usable for integration in game engines. You would have to inject input events somewhere (perhaps using QCoreApplication::postEvent unless some better high-level functionality exists) and give Qt some time to process its event queue somewhere (probably using QCoreApplication::processEvents).

Its absolutely possible. My project is a 2D title that uses SDL and OpenGL for graphics and has a QT map editor. We used our graphics engine in the editor build and all the rendering was done onto an QGLWidget. It worked for us pretty well. Recently, I've been doing a major redesign of our editor and have removed the use of our graphics engine from the editor and instead use QGraphicsScene/QGraphicsView to render the map instead. We didn't have any major issues with using our graphics engine and QT though.

Take a look at the QGLWIdget. I think you can just do all your SDL/OpenGL rendering to that widget, and then place the widget inside your QT application so that you can use QT for the GUI components.

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

Its absolutely possible. My project is a 2D title that uses SDL and OpenGL for graphics and has a QT map editor. We used our graphics engine in the editor build and all the rendering was done onto an QGLWidget. It worked for us pretty well. Recently, I've been doing a major redesign of our editor and have removed the use of our graphics engine from the editor and instead use QGraphicsScene/QGraphicsView to render the map instead. We didn't have any major issues with using our graphics engine and QT though.

Take a look at the QGLWIdget. I think you can just do all your SDL/OpenGL rendering to that widget, and then place the widget inside your QT application so that you can use QT for the GUI components.

doesn't that change the input? I'm pretty sure I ruled that out because it would require quite a bit of restructuring. And just to clarify, I wouldn't be using sdl at all in the editor version of the application

We processed all input in our editor with QT to that widget. The rendering was all done through OpenGL drawing to a SDL surface, which is what I thought you wanted. There might be other ways to do what you want (QT is pretty darn extensive after all), but I'm unaware of any.

If you want to continue using SDL input with your editor to minimize any restructuring you'd have to do with QTs signal/slots, what you might consider doing is to have an input translation layer that processes each QT input action (grabbing all mouse clicks, moves, keyboard presses/releases, and so on) and create the corresponding SDL input event. Then send the event to SDLs event queue so the action can be processed just as if it was a normal event generated by SDL itself (use SDL_PushEvent). The result would be a single application window that would be created and managed by QT that contains a sub-widget that runs your engine/graphical display and processes user input from QT as SDL input events. Would that fit your needs?

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

This topic is closed to new replies.

Advertisement