How to use CEGUI with SDL and OpenGL

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Revision as of 13:09, 12 June 2011 by Wondersye (Talk | contribs) (Created page with "{{VersionBadge|0.7.5}} 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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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:

  1. a minimal example
  2. 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.


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:

  1. inputs (including wallclock-timing) are collected from SDL and then fed appropriately to CEGUI
  2. 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.

File:CEGUI-SDL-all-widgets.cc

This more complex example is built on the minimal one.