Resurrected Entertainment

Qt for Games – Niblet #4

December 12, 2008

Before I began my investigation into the suitability of Qt for games, I wanted to use Qt’s new QGraphicsItem framework alongside the OpenGL support. I was curious to see if an OpenGL object could be wrapped by a QGraphicsItem and rendered into the same view. The short answer is yes, but the result is not very pretty or practical. Basically, it comes down to a fundamental issue with OpenGL and sharing rendering contexts with other engines. OpenGL doesn’t allow this by design, but you could use an QGLWidget and encapsulate that in a QGraphicsItem implementation. The result is very heavy weight, not particularly elegant, and doesn’t easily support animation of the OpenGL shape. With the latest version of the Qt API, you can render a QWidget object into an OpenGL rendering context, but not the other way around (without using a container like QGLWidget).

This is fine and not detrimental to the project, so we’ll continue using the new graphics framework minus the features relating to OpenGL. This gives us plenty of options for rendering, but 3D will be set aside for now (unless I get a spark of genius). We may revisit it later to explore different ideas, like the intro screen or credits; however, we will need to find out how well Qt supports direct pixel rendering. I am very familiar with various image classes, but whether they can be used in and efficient rendering pipeline is still an unknown.

I’m trying to be realistic here. Niblet is not an overly complex idea, but I would like to use compositing for a variety of effects and some effects like fire would need to be rendered using fast pixel access.

2 Responses to “Qt for Games – Niblet #4”

Matt wrote a comment on July 27, 2009


I’m curious to know how you go with game development on QT. I’ve just started to use QT for some boring ‘forms/reports’ – ‘data in/data out’ stuff.

I’d like a nice distraction with some game development on QT. Just to keep it interesting.

Just 2D stuff. So I’m looking for a game engine to integrate with QT…

Did you make some headway with QGraphicsItem?


admin wrote a comment on July 31, 2009

Qt 4 can certainly be used for games. You’ll probably want to read up on classes like QGraphicsView, QGraphicsScene, QGraphicsItem, and QImage/QPixmap. When you’re ready, the animation classes will probably be useful for you too. If you’re interested in the 2D aspects of game programming, then they also have vector graphics components for you to use. SVG (Scalable Vector Graphics) is a standards-based vector file format. Qt has support for this format and can makes it quite easy to use resources like these in 2D games.

In my experiments, I was trying to hammer OpenGL shapes into the QGraphicsScene framework, which is not what you seem to want to do.

Care to comment?