How to use CEGUI with SDL and OpenGL
Written for CEGUI 0.7.5
Works with versions 0.7.5.x (obsolete)
This tiny HOW-To simply illustrate with a full, runnable example, how CEGUI can be used with SDL and OpenGL. It shows:
- a minimal example
- another more involved example that includes most of the CEGUI widgets that are available (with the Taharez Look).
The platform used here is GNU/Linux.
Contents
Common Topics
Prerequisites
CEGUI depends on various libraries. We used:
* FreeImage (note: the install must be fixed if targeting a prefixed directory rather than the default one in the system tree)
* PCRE (note: if building if from source, specify the --enable-unicode-properties
configure option)
For CEGUI itself, we used the following configuration options: --enable-debug --disable-lua-module --disable-python-module
Locating Resources
For default CEGUI's resources to be found (ex: fonts, images, etc.), the test program must be able to find out what are their paths, which are relative to the place where CEGUI was installed. One must thus update accordingly in the example the CEGUIInstallBasePath
variable so that it points to a directory from which /share/CEGUI/<code> can be found.
Example:
const std::string & CEGUIInstallBasePath = "/home/joe/my-CEGUI-0.7.5-install" ;
Building
A simple yet powerful enough makefile could be this File:GNUmakefile. The main point is to set correctly the compilation and linking flags for SDL and CEGUI.
A Minimal Example
As you can see in File:CEGUI-SDL-hello-world.cc, it is quite short and easy to understand.
The point is first to initialize correctly SDL (notably for OpenGL and input settings) and CEGUI (mainly with regard to resource paths).
Then the application-specific GUI itself is to be created, here fully from code (rather than thanks to XML description files).
The main loop can then be run, it just iterates endlessly through the following steps:
- inputs (including wallclock-timing) are collected from SDL and then fed appropriately to CEGUI
- GUI is requested to update its rendering accordingly
An Example With Most Widgets
The purpose of this example is to show how most CEGUI widgets look in the Taharez look, in order for a developer to know what widgets are available. No wiring or event processing is done for them, we just want to showcase the available toolbox.
This more complex example is built on the minimal one.