Will Qt be a good choice for a game? [closed]

I am wanting to make a 2d, tower defense game. I currently have a version in C# made using XNA, but thought it might be fun to learn Qt as well as run my game on other platforms. The graphics aren't too intense (just 2d sprites), but the underlying calculations can get pretty processor intense, especially if there are a lot of enemies and towers on the screen at one time.

I'm a little curious if Qt would fill this role well or not. Does anyone have experience or advice on using Qt in game development?


I have spent over a decade developing on various C++ based games both 2D and 3D for a number of different engines both big and small and I have also had a short but rather intense run with Qt5 (1.5 years at the time of writing). So far Qt has blown me away with all its neatly stacked cross-platform and performance features and so I am planning on porting my biggest game project to Qt as soon as time lets me.

To be honest I am a bit confused myself as to why Qt is not more prevalent in games. I think the main reason is its rather crooked licensing history together with the fact that it just has not being marketed for use in games. Qt is after all made primarily to ace at cross-platform UI + real-time graphics on many platforms from embedded and up. Now that Qt has become it's own company and with the new QML/QtQuick features maybe there will be a boom of Qt based game soon, who knows? I sure hope more game developers will discover Qt and start using it in their projects.

To answer your question, I will try to match the offerings of Qt with the needs of different types of games.

Performance graphics for 2D

In traditional Qt there exists different abstractions for graphics. For some smaller embedded platforms it can rely on a simple 2D subsystem only. But for most desktop platforms (Windows/MacOSX/Linux) and mobile platforms (Android/OSX) the 2D abstraction rests neatly on top of a high-performance 3D stack based on OpenGL or OpenGL ES respectively.

This is a true gem, and makes graphics programming a joy thanks to the well thought out architecture that allows you to chose how high- or low- level you want to approach your graphics programming.

There are lots of classes that allow you to go about your drawing as usual with well known concepts like color, line thickness, and shape while knowing that it will all be 3D accelerated under the hood.

http://doc.qt.io/qt-5/graphicsview.html

http://doc.qt.io/qt-5/coordsys.html

Then there is the whole new thing "QtQuick" or "QML". A declarative language that together with java script provides the quickest and meanest way to chug out interactive UI and games that I know about on this planet. After I managed to make a full flight of piano keys in 5 lines of code and in under 15minutes I was sold.

http://doc.qt.io/qt-5/qtquick-index.html

Performance graphics for 3D

EDITED 23/2-17 to be more correct. Please see S.O. history for what changed in this section.

Qt has traditionally had a very strong bond to OpenGL, and this bond has served Qt very well as OpenGL is portable and performant over a wide range of platforms. However with the realization that OpenGL is showing it's age, the ever present question of comparability with DirectX on the Microsoft platforms and the advent of new technologies like Vulkan lurking in the near future, the Qt company has made the wise strategic move of starting to pre-preemptively generalizing the hardware abstraction layer towards graphics hardware. So for now Qt is bound to OpenGL, but soon it will support many other graphics abstractions, to your great benefit as a games developer.

While we wait, there is also nothing in Qt to hinder you from using DX together with Qt on the Microsoft platforms. Qt goes to great lengths to not interfere with other libraries on any platform, so it will work with a lot of other toolkits and engines, and you can even embed game engines based on OpenGL inside Qt by exposing Qt's OpenGL context directly. Also keeping the same code-base for a game that is ported to the two noteworthy mobile platforms with Qt will be much simpler without DX.

But, beyond all the convenience classes for managing OpenGL spesific features such as VBO, FBO, loading textures and shaders etc, there really isn't a full-blown 3D engine anywhere in Qt.

UPDATE 2016-01-29: Since I first wrote this answer it has come to my atention that there is a great effort being made to provide a full-blown 3D engine in Qt. It is called Qt3D 2.0 and is a complete rewrite of the old Qt3D that was part of Qt4.x and that was part of only one release before it was removed due to political reasons (Nokia ditched Qt).

It has an impressive set of features and a lot of good thinking has gone into it's API to ensure that it can leverage the full potential of modern graphics hardware while staying flexible and performant. Another good news is that is in technology preview. This means that you can try it out today and it will be part of main-line Qt soon. You can read more about it here.

Math

As part of the 3D stack, Qt has a full set of performance math routines such as matrix, vector, quaternions, point, rect etc.

The common stl math functions such as sqrt, floor, sin etc. are also wrapped in a platform-independence layer.

http://doc.qt.io/qt-5/qtmath.html

There are no support for advanced math like full blown physics engine, collision detection or response.

For that you might be interested in this:

https://github.com/junggon/gear

Assets management

Qt has a fully fledged resource management system that compiles resources into your binary. This is cross platform and supports any file type you need with special support for common image formats, svg, sounds, fonts, HTML, CSS. And loading and using resources is really simple since all of Qt's file handlign orutines accept URLs that point to these resources. Really awesome.

User interfaces

GUI code is Qt's forte. It has great tools for working with GUIs that for some small'ish 2D games will actually be usable as level editors.

Cross platform support

UPDATE 2016-01-29: It is part of the core values for Qt to be platform agnostic. Qt supports the major desktop platforms, the major mobile platforms and a bunch of embedded hardware that you never heard of. Please see the official list of community supported (free/open source) platforms here. It will allow you to bring your mostly unchanged code base to all platforms you like, saving you a lot of time, money and effort the day you decide to make the "iOS version".

Platform integration

Qt has wrapped all platform integration in a cross-platform way. This includes:

  • Launcher icons
  • Configuration file (with properly abstracted platform specifics like location and format)
  • Popups
  • Clipboard management
  • Drag and drop
  • Fullscreen/imersive mode switching.
  • Multiple display support
  • Tooltips
  • Platform look and feel

2D Animation

Qt features a full framework for working with state machines. On top of this there sits a full framework for animating properties that can be used for making interactive UI in 2D (or even 3D if you play your cards right). It has all the stuff you expect like easing, automatic state transition and tons of convenience wrappers and ways of doing interresting stuff. It's like working with jQuery but in C++. For some games, this is all you need.

http://doc.qt.io/qt-5/qtquick-statesanimations-animations.html

Containers

Qt has a bunch of STL like container classes with extensions to accommodate Qt specific features. These classes include everything from Lists to maps to arrays and buffers.

http://doc.qt.io/qt-5/containers.html

Strings

Qt's string class is my favourite of any language. It has its quirks, but it gives you a ton of performance and features, and as usual its cross-platform together with all it's friends:

http://doc.qt.io/qt-5/string-processing.html

Timers, threads and events

The whole of Qt framework is implemented around an asynchronous architecture based on event-loops with light-weight events called "signals".

http://doc.qt.io/qt-5/qtqml-syntax-signals.html

Qt supports multiple levels of concurrency from low-level threads, through managed thread pools to modern map-reduce and "futures". It also has cross-platform high-performance locking mechanism such as mutecies, locks, wait conditions, lock free stuff, atomic operations and a whole bunch of other stuff that I didn't get a chance to check out yet.

http://doc.qt.io/qt-5/examples-threadandconcurrent.html

Of course Qt has support for timers that fit well into all this with a lot of convenience features such as adjusting the precision, triggering single-shot etc.

http://doc.qt.io/qt-5/timers.html

Input

Input from touch screens, mice and keyboards is handled using the event architecture, and Qt really has this wrapped up in a basket. Qt just recently (23/2-17) got experimental support for joysticks and gamepads.

http://doc.qt.io/qt-5/eventsandfilters.html

There is also support for sensors like position, pressure, compass, rotation, temperature, so you can make never-ball clones too.

http://doc.qt.io/qt-5/qtsensors-index.html

And there is support for blue-tooth for connecting and sharing game data over the air without access to wifi.

http://doc.qt.io/qt-5/qtbluetooth-index.html

And there is camera support for whatever you might want to use that for in a game.

http://doc.qt.io/qt-5/cameraoverview.html

All cross-platform.

Scripting

Qt has an embedded high-performance ECMA (a.k.a. java script) engine tied into its core. Oh and you get a tightly embedded port of google web-kit included as well, if you need it.

http://doc.qt.io/qt-5/qtscript-index.html

Media playback

Qt wraps gstreamer and other media libraries to support play back of media such as video and sound. It allows the developer to chose on which level they want to intearact with media. On the high level you can just put a widget and run .play() on the low level you get access to buffers of video and audio for your processing pleasure.

http://doc.qt.io/qt-5/multimediaoverview.html

Media encoding

Depending on the active back-end Qt also gives you access to encode streams to network/disk etc.

Utility classes

Where do I start?

  • MD5/SHA other secure hash algorithms
  • Compression/decompression algorithms
  • Encryption/decryption algorithms
  • File handling both blocking, non-blocking, mapped etc.
  • File system handling such as copy, move, rename of files
  • File alteration monitoring
  • HTTP client
  • High performance socket programming
  • Synthetic UI events generation
  • Time and date
  • DNS access
  • Logging
  • Error messages
  • MIME and URL processing
  • json parser/generator
  • Gesture recognition
  • Compiled regex
  • Serial IO
  • XML parser/generator
  • SSL
  • Undo/Redo

The list really goes on and on... See for your self here:

http://doc.qt.io/qt-5/classes.html

Internationalization

Out-of-the-box internationalization through the use of ICU with all the advanced features such as RTL support in text widgets etc.

http://doc.qt.io/qt-5/internationalization.html

Updates / plug-ins

Qt has a plug-in architecture. That means you can split your executable into bits and update them separately, reloading each bit dynamically at run-time.

http://doc.qt.io/qt-5/plugins-howto.html

Unit testing

Qt has it very own unit testing framework built right in. What sets it apart is that it is tightly integrated with Qt and supports visual testing of user interfaces. You can simulate key-presses and mouse clicks, check for the presence of widgets and states etc.

It also has modes for profiling, bench-marking, data-driven testing and more.

This post is getting kind of long so I won't go into more detail.

http://doc.qt.io/qt-5/qttest-index.html

Stability

Qt was first released in 1995 and has thus had a long time to stabilize. It has a huge set of regression tests that is run before every release and it is thoroughly tested on a bunch of compilers, platforms and devices. For some reason this is not on the top of many game developer's lists.

http://en.wikipedia.org/wiki/List_of_Qt_releases

Documentation

Qt has really good documentation, and it is continuously improving. If you clicked some of my links you would already know.

Community

Since Qt has been around for so long a large community of experienced users has formed. You will find blog posts, wikis and forums in many languages and rich with knowledge of any kind of issue you might be working with. Here is a list:

https://wiki.qt.io/Online_Communities

This turned out to be one hell of a long post with mostly Qt PROs, but I figure this is what it takes to judge a platform before you test it out. Good luck on your project!


New Big MMORPG called Rift is actually done by using Qt + DirectX. This is at least for me the first big scale game that I have found that is created with Qt. Of course there is the DirectX behind also, what is not a big suprise. Too bad because Qt itself would be multiplatform and DirectX is not.

Rift homepage: http://eu.riftgame.com/en/

So sure Go for it, Qt is really very nice platform for any development.


Felgo (felgo.com) is a cross-platform game engine based on Qt/QML with many useful custom Felgo QML game components for handling multiple display resolutions & aspect ratios, animations, particles, physics, pathfinding and more. API reference. The engine core is written in native C++, combined with the custom renderer, the games reach a solid performance of 60fps across all devices.

Squaby is a tower defense game made with Felgo and its full source code is available here: Squaby source code


I'm confident it can. I'm working on my own 2D game engine SDXM, Saelee Deus Ex Machine, with pure Qt. I don't have anything substantial for anyone to download to back my claim, but I am working on tests.

Here are a few actual tests I recorded:

3000 non-user-controlled + 1 user-controlled sprite http://youtu.be/AHdhg3Nw88w

F-Zero type game with real 3D QTransform http://youtu.be/KuTBzhBqU4Y

*Has audio demo implemented with Phonon

So it's quite possible to create something like the games for SNES.