A tutorial on CEGUI and Qt/QGLViewer

CEGUI logo QGLViewer logo Qt logo

Introduction

The QGLViewer library

The work by Gilles Debunne on the QGLViewer provides a wonderful base for developping 3D applications. It encapsulates :

Since it is developped with Qt, it is very easy to have a 3D interface. You build your interface as a widget, using for example the Qt designer, and you let this interface interact with you viewer through signal and slots. However, doing so, you end up with two windows: one for the viewer and one for the interface. You cannot have you interface "overlayed" on you 3D rendering. Theoretically, with Qt4, it should be possible as Qt's widgets can now be rendered using an OpenGL renderer. However, I cannot make it work (and it seems other people are trying and it is difficult). For that reason, I investigated a purely OpenGL based widget/interface library. This tutorial summarizes my investigations.

The CEGUI library

Crazy Eddy's GUI is a quite powerful Open Source and LGPL library that allows overlayed interface. From what I can tell, it is the only one that can integrates with a 3D rendering system by being "rendered" directly in that system. Ogre and Irrlicht typically make use of them. It has a bunch of nice features that we will discover soon. However, it suffers from a number of (classical) drawbacks that I list first so we can get rid of that ;-) :

This said, CEGUI is really cool and quite powerful and as Sinbad (the maniac behind Ogre) adequately puts it, when invited to a free lunch, you should not complain about the quality of the caviar. So thanks Eddie, here is my contribution to the project.

Preparation

Overview of the tutorial

There is a bunch of things to discover in CEGUI and another bunch of things to master in Qt/QGLViewer. There is the way things should theoretically work, and the way we have to do it in practice. There are fundamental issues that are not related to CEGUI in particular. Wow! That's a bunch of things! So we need to walk slowly and progress step by step. The goal of this tutorial is twofold :

The first goal will be achieved through the step-by-step construction of a simple viewer that displays a cube and has an overlayed interface to select color, rendering mode, etc.

The second step will be a complete refactoring of this simple viewer that will allow for very easy sub-classing, enforcing reusability and ease of use.

Finally, if there is some time left, we will try to go into advanced features of CEGUI such as scripting. It will be quite a journey so send your girlfriend to the movie, order a pizza and fasten you seatbelt.

Installation

linux

You must first check that you have DevIL and QGLViewer installed. For that, type in a shell

>rpm -q DevIL libQGLViewer libQGLViewer-devel

If it returns at leas one "packaged not installed", you have to install it before installing CEGUI. The libQGLViewer install is well detailled. For DevIL, I did a src.rpm that you can download below. Apply the same instructions that the one for installing the CEGUI rpms.

To install CEGUI, you have download the source RPMs for CEGUI (and DevIL if you need it). You will have to rebuild and install the binary result. Here is the sequence for CEGUI, to be done as root:

>cd /usr/src/redhat/SRPMS
>wget  http://artis.inrialpes.fr/Membres/Xavier.Decoret/resources/CEGUI/downloads/CEGUI-0.4.1-2.src.rpm
>rpmbuild --rebuild CEGUI-0.4.1-2.src.rpm
>cd /usr/src/redhat/RPMS/i386
>rpm -Uvh CEGUI-0.4.1-2.i386.rpm CEGUI-devel-0.4.1-2.i386.rpm

It's done! Now you can download and compile the examples.