<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://cegui.org.uk/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Deek0146</id>
		<title>CEGUI Wiki - Crazy Eddie's GUI System (Open Source) - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://cegui.org.uk/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Deek0146"/>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/Special:Contributions/Deek0146"/>
		<updated>2026-04-06T21:37:10Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=SDL_to_CEGUI_keytable&amp;diff=4577</id>
		<title>SDL to CEGUI keytable</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=SDL_to_CEGUI_keytable&amp;diff=4577"/>
				<updated>2011-07-23T07:48:54Z</updated>
		
		<summary type="html">&lt;p&gt;Deek0146: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|0.4}} {{VersionBadge|0.5}} {{VersionBadge|0.6}} {{VersionBadge|0.7}}&lt;br /&gt;
&lt;br /&gt;
As this was a very boring thing to do, I'll share it with the rest of you ;)&lt;br /&gt;
&lt;br /&gt;
With this function injecting KeyDown and KeyUp events to CEGUI works like you'd expect.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
 /************************************************************************&lt;br /&gt;
     Translate a SDLKey to the proper CEGUI::Key&lt;br /&gt;
 *************************************************************************/&lt;br /&gt;
 CEGUI::uint SDLKeyToCEGUIKey(SDLKey key)&lt;br /&gt;
 {&lt;br /&gt;
     using namespace CEGUI;&lt;br /&gt;
     switch (key)&lt;br /&gt;
     {&lt;br /&gt;
     case SDLK_BACKSPACE:    return Key::Backspace;&lt;br /&gt;
     case SDLK_TAB:          return Key::Tab;&lt;br /&gt;
     case SDLK_RETURN:       return Key::Return;&lt;br /&gt;
     case SDLK_PAUSE:        return Key::Pause;&lt;br /&gt;
     case SDLK_ESCAPE:       return Key::Escape;&lt;br /&gt;
     case SDLK_SPACE:        return Key::Space;&lt;br /&gt;
     case SDLK_COMMA:        return Key::Comma;&lt;br /&gt;
     case SDLK_MINUS:        return Key::Minus;&lt;br /&gt;
     case SDLK_PERIOD:       return Key::Period;&lt;br /&gt;
     case SDLK_SLASH:        return Key::Slash;&lt;br /&gt;
     case SDLK_0:            return Key::Zero;&lt;br /&gt;
     case SDLK_1:            return Key::One;&lt;br /&gt;
     case SDLK_2:            return Key::Two;&lt;br /&gt;
     case SDLK_3:            return Key::Three;&lt;br /&gt;
     case SDLK_4:            return Key::Four;&lt;br /&gt;
     case SDLK_5:            return Key::Five;&lt;br /&gt;
     case SDLK_6:            return Key::Six;&lt;br /&gt;
     case SDLK_7:            return Key::Seven;&lt;br /&gt;
     case SDLK_8:            return Key::Eight;&lt;br /&gt;
     case SDLK_9:            return Key::Nine;&lt;br /&gt;
     case SDLK_COLON:        return Key::Colon;&lt;br /&gt;
     case SDLK_SEMICOLON:    return Key::Semicolon;&lt;br /&gt;
     case SDLK_EQUALS:       return Key::Equals;&lt;br /&gt;
     case SDLK_LEFTBRACKET:  return Key::LeftBracket;&lt;br /&gt;
     case SDLK_BACKSLASH:    return Key::Backslash;&lt;br /&gt;
     case SDLK_RIGHTBRACKET: return Key::RightBracket;&lt;br /&gt;
     case SDLK_a:            return Key::A;&lt;br /&gt;
     case SDLK_b:            return Key::B;&lt;br /&gt;
     case SDLK_c:            return Key::C;&lt;br /&gt;
     case SDLK_d:            return Key::D;&lt;br /&gt;
     case SDLK_e:            return Key::E;&lt;br /&gt;
     case SDLK_f:            return Key::F;&lt;br /&gt;
     case SDLK_g:            return Key::G;&lt;br /&gt;
     case SDLK_h:            return Key::H;&lt;br /&gt;
     case SDLK_i:            return Key::I;&lt;br /&gt;
     case SDLK_j:            return Key::J;&lt;br /&gt;
     case SDLK_k:            return Key::K;&lt;br /&gt;
     case SDLK_l:            return Key::L;&lt;br /&gt;
     case SDLK_m:            return Key::M;&lt;br /&gt;
     case SDLK_n:            return Key::N;&lt;br /&gt;
     case SDLK_o:            return Key::O;&lt;br /&gt;
     case SDLK_p:            return Key::P;&lt;br /&gt;
     case SDLK_q:            return Key::Q;&lt;br /&gt;
     case SDLK_r:            return Key::R;&lt;br /&gt;
     case SDLK_s:            return Key::S;&lt;br /&gt;
     case SDLK_t:            return Key::T;&lt;br /&gt;
     case SDLK_u:            return Key::U;&lt;br /&gt;
     case SDLK_v:            return Key::V;&lt;br /&gt;
     case SDLK_w:            return Key::W;&lt;br /&gt;
     case SDLK_x:            return Key::X;&lt;br /&gt;
     case SDLK_y:            return Key::Y;&lt;br /&gt;
     case SDLK_z:            return Key::Z;&lt;br /&gt;
     case SDLK_DELETE:       return Key::Delete;&lt;br /&gt;
     case SDLK_KP0:          return Key::Numpad0;&lt;br /&gt;
     case SDLK_KP1:          return Key::Numpad1;&lt;br /&gt;
     case SDLK_KP2:          return Key::Numpad2;&lt;br /&gt;
     case SDLK_KP3:          return Key::Numpad3;&lt;br /&gt;
     case SDLK_KP4:          return Key::Numpad4;&lt;br /&gt;
     case SDLK_KP5:          return Key::Numpad5;&lt;br /&gt;
     case SDLK_KP6:          return Key::Numpad6;&lt;br /&gt;
     case SDLK_KP7:          return Key::Numpad7;&lt;br /&gt;
     case SDLK_KP8:          return Key::Numpad8;&lt;br /&gt;
     case SDLK_KP9:          return Key::Numpad9;&lt;br /&gt;
     case SDLK_KP_PERIOD:    return Key::Decimal;&lt;br /&gt;
     case SDLK_KP_DIVIDE:    return Key::Divide;&lt;br /&gt;
     case SDLK_KP_MULTIPLY:  return Key::Multiply;&lt;br /&gt;
     case SDLK_KP_MINUS:     return Key::Subtract;&lt;br /&gt;
     case SDLK_KP_PLUS:      return Key::Add;&lt;br /&gt;
     case SDLK_KP_ENTER:     return Key::NumpadEnter;&lt;br /&gt;
     case SDLK_KP_EQUALS:    return Key::NumpadEquals;&lt;br /&gt;
     case SDLK_UP:           return Key::ArrowUp;&lt;br /&gt;
     case SDLK_DOWN:         return Key::ArrowDown;&lt;br /&gt;
     case SDLK_RIGHT:        return Key::ArrowRight;&lt;br /&gt;
     case SDLK_LEFT:         return Key::ArrowLeft;&lt;br /&gt;
     case SDLK_INSERT:       return Key::Insert;&lt;br /&gt;
     case SDLK_HOME:         return Key::Home;&lt;br /&gt;
     case SDLK_END:          return Key::End;&lt;br /&gt;
     case SDLK_PAGEUP:       return Key::PageUp;&lt;br /&gt;
     case SDLK_PAGEDOWN:     return Key::PageDown;&lt;br /&gt;
     case SDLK_F1:           return Key::F1;&lt;br /&gt;
     case SDLK_F2:           return Key::F2;&lt;br /&gt;
     case SDLK_F3:           return Key::F3;&lt;br /&gt;
     case SDLK_F4:           return Key::F4;&lt;br /&gt;
     case SDLK_F5:           return Key::F5;&lt;br /&gt;
     case SDLK_F6:           return Key::F6;&lt;br /&gt;
     case SDLK_F7:           return Key::F7;&lt;br /&gt;
     case SDLK_F8:           return Key::F8;&lt;br /&gt;
     case SDLK_F9:           return Key::F9;&lt;br /&gt;
     case SDLK_F10:          return Key::F10;&lt;br /&gt;
     case SDLK_F11:          return Key::F11;&lt;br /&gt;
     case SDLK_F12:          return Key::F12;&lt;br /&gt;
     case SDLK_F13:          return Key::F13;&lt;br /&gt;
     case SDLK_F14:          return Key::F14;&lt;br /&gt;
     case SDLK_F15:          return Key::F15;&lt;br /&gt;
     case SDLK_NUMLOCK:      return Key::NumLock;&lt;br /&gt;
     case SDLK_SCROLLOCK:    return Key::ScrollLock;&lt;br /&gt;
     case SDLK_RSHIFT:       return Key::RightShift;&lt;br /&gt;
     case SDLK_LSHIFT:       return Key::LeftShift;&lt;br /&gt;
     case SDLK_RCTRL:        return Key::RightControl;&lt;br /&gt;
     case SDLK_LCTRL:        return Key::LeftControl;&lt;br /&gt;
     case SDLK_RALT:         return Key::RightAlt;&lt;br /&gt;
     case SDLK_LALT:         return Key::LeftAlt;&lt;br /&gt;
     case SDLK_LSUPER:       return Key::LeftWindows;&lt;br /&gt;
     case SDLK_RSUPER:       return Key::RightWindows;&lt;br /&gt;
     case SDLK_SYSREQ:       return Key::SysRq;&lt;br /&gt;
     case SDLK_MENU:         return Key::AppMenu;&lt;br /&gt;
     case SDLK_POWER:        return Key::Power;&lt;br /&gt;
     default:                return 0;&lt;br /&gt;
     }&lt;br /&gt;
     return 0;&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usage is like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
 SDL_Event e;&lt;br /&gt;
 while (SDL_PollEvent(&amp;amp;e))&lt;br /&gt;
 {&lt;br /&gt;
     if (e.type == SDL_KEYDOWN)&lt;br /&gt;
     {&lt;br /&gt;
         CEGUI::uint kc = SDLKeyToCEGUIKey(e.key.keysym.sym);&lt;br /&gt;
         CEGUI::System::getSingleton().injectKeyDown(kc);&lt;br /&gt;
         CEGUI::System::getSingleton().injectChar(event.key.keysym.unicode); /// For this, you need to make sure you have called SDL_EnableUNICODE(1); at some point in your code _after_ the call to SDL_Init&lt;br /&gt;
&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:lindquist]] 19:24, 8 Nov 2005 (CET)&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;/div&gt;</summary>
		<author><name>Deek0146</name></author>	</entry>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4303</id>
		<title>Using CEGUI with SDL and OpenGL (0.7)</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4303"/>
				<updated>2011-03-05T21:47:19Z</updated>
		
		<summary type="html">&lt;p&gt;Deek0146: /* Change of window size */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|0.7}}&lt;br /&gt;
[http://www.libsdl.org SDL (Simple DirectMedia Layer)] is an excellent library for writing portable games and other multimedia applications, but as it is a low-level library, it has no native support for GUI interfaces.&lt;br /&gt;
&lt;br /&gt;
When using [http://www.opengl.org OpenGL] for rendering, using CEGUI with SDL is not hard.&lt;br /&gt;
&lt;br /&gt;
I'll assume that you've read the imbiciles tutorials, and have used SDL with OpenGL.&lt;br /&gt;
And know C / C++ ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialisation ===&lt;br /&gt;
Before we can do anything, we need to initialise our libraries.&lt;br /&gt;
First SDL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_Init(SDL_INIT_VIDEO)&amp;lt;0)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to initialise SDL: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we initialise SDL with video support. We need this for CEGUI.&lt;br /&gt;
O.K. now SDL is ready to go. So let's fire up OpenGL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_SetVideoMode(800,600,0,SDL_OPENGL)==NULL)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to set OpenGL videomode: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  SDL_Quit();&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now OpenGL is ready. But we still need to set a decent configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glEnable(GL_CULL_FACE);&lt;br /&gt;
glDisable(GL_FOG);&lt;br /&gt;
glClearColor(0.0f,0.0f,0.0f,1.0f);&lt;br /&gt;
glViewport(0,0, 800,600);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The OpenGL renderer that comes with CEGUI sets the matrices itself, so if you're using CEGUI for all your rendering needs this would be fine. Normally you would want the normal perspective projection setup though:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glMatrixMode(GL_PROJECTION);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
gluPerspective(45.0, 800.0/600.0, 0.1,100.0);&lt;br /&gt;
glMatrixMode(GL_MODELVIEW);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SDL and OpenGL are now both ready for action. So it's time to initialise CEGUI.&lt;br /&gt;
This new &amp;quot;bootstrap&amp;quot; method in 0.7 is much simpler than the previous methods, it is one simple call&lt;br /&gt;
&lt;br /&gt;
First we need the include (Usually everything you need can be found in &amp;lt;CEGUI/CEGUI.h&amp;gt; but for initialising a specific subsystem you need to do this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;CEGUI/RendererModules/OpenGL/CEGUIOpenGLRenderer.h&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the call to initialise everything&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that you have to load a widget set, set the mouse cursor and a default font before CEGUI is completely ready. This is described in the other tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By default the SDL cursor is displayed, so we'll remove that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_ShowCursor(SDL_DISABLE);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As keypress characters needs to be injected into CEGUI, we activate unicode translation for SDL key events:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableUNICODE(1);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it alot easier as we don't have to worry about modifier keys and keyboard layouts ourselves. More about this later on...&lt;br /&gt;
&lt;br /&gt;
Key repeat is a nice feature for the text input widgets in CEGUI, so we use SDL to generate them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything is ready now, and we can start the main loop :)&lt;br /&gt;
&lt;br /&gt;
=== The Main Loop ===&lt;br /&gt;
To make it all happen, we use a simple main loop that just keeps pushing on those frames:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void main_loop()&lt;br /&gt;
{&lt;br /&gt;
  bool must_quit = false;&lt;br /&gt;
  &lt;br /&gt;
  // get &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
  double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
  &lt;br /&gt;
  while (!must_quit)&lt;br /&gt;
  {&lt;br /&gt;
    inject_input(must_quit);&lt;br /&gt;
    inject_time_pulse(last_time_pulse);&lt;br /&gt;
    render_gui();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function will run the main loop until the ''bool'' value ''must_quit'' becomes ''true''. In this tutorial this will happen when the user clicks the close button provided by the window manager.&lt;br /&gt;
&lt;br /&gt;
The ''double'' value ''last_time_pulse'' holds the time of the latest time pulse injection. More about this later.&lt;br /&gt;
&lt;br /&gt;
Each function in the ''while'' loop will be described below.&lt;br /&gt;
&lt;br /&gt;
There are endless ways of making your main loop. I took a simple approach to ease writing this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Injecting Input and injecting change of window size ===&lt;br /&gt;
When the user press or release keyboard or mouse buttons, we need to tell CEGUI about it, for this we use the injection functions of ''CEGUI::System''. We also have to tell &lt;br /&gt;
&lt;br /&gt;
Here is what our inject_input function looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_input(bool&amp;amp; must_quit)&lt;br /&gt;
{&lt;br /&gt;
  SDL_Event e;&lt;br /&gt;
  &lt;br /&gt;
  // go through all available events&lt;br /&gt;
  while (SDL_PollEvent(&amp;amp;e))&lt;br /&gt;
  {&lt;br /&gt;
    // we use a switch to determine the event type&lt;br /&gt;
    switch (e.type)&lt;br /&gt;
    {&lt;br /&gt;
      // mouse motion handler&lt;br /&gt;
      case SDL_MOUSEMOTION:&lt;br /&gt;
        // we inject the mouse position directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
        );&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse down handler&lt;br /&gt;
      case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
        // let a special function handle the mouse button down event&lt;br /&gt;
        handle_mouse_down(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse up handler&lt;br /&gt;
      case SDL_MOUSEBUTTONUP:&lt;br /&gt;
        // let a special function handle the mouse button up event&lt;br /&gt;
        handle_mouse_up(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // key down&lt;br /&gt;
      case SDL_KEYDOWN:&lt;br /&gt;
        // to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
        &lt;br /&gt;
        // as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
        // this is described in more detail below.&lt;br /&gt;
        if ((e.key.keysym.unicode != 0)&lt;br /&gt;
        {&lt;br /&gt;
          CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
        }&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // key up&lt;br /&gt;
      case SDL_KEYUP:&lt;br /&gt;
        // like before we inject the scancode directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // WM quit event occured&lt;br /&gt;
      case SDL_QUIT:&lt;br /&gt;
        must_quit = true;&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First I'll explain the events that get handled directly in the ''inject_input'' function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Motion''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// we inject the mouse position directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is nothing special here. Like stated in the comment the mouse position is just injected directly.&lt;br /&gt;
&lt;br /&gt;
There are two ways of injecting mouse motion. One where you inject how much the cursor moved, and one where you inject the mouse cursor position. The last one is failsafe.&lt;br /&gt;
Then first one only works correctly in fullscreen mode, or with input grabbed. The reason for this is that in regular windowed mode, the mouse can be moved outside the application window, and during this time no mouse motion event are generated. So if we enter the window at another position, the real mousecursor and CEGUI's mouse cursor will be offset, which will break mouse usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Down'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This event takes a little more work. CEGUI requires that key characters (the printable character the key represents) are injected alongside key codes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luckily the key code is just the SDL scancode, so we inject that directly. (This only seems to be true on windows. On other platforms you will need to use a translation function. One can be found here [[SDL to CEGUI keytable]])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
// this is described in more detail below.&lt;br /&gt;
if (e.key.keysym.unicode != 0)&lt;br /&gt;
{&lt;br /&gt;
  CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of formatting the keypress ourselves, we let SDL do it for us. We could check if we actually got a valid ASCII code, but we want support for local characters as well, so we won't do that. For more information, take a look at the SDL documentation for this feature. [http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fkeysym SDL_keysym].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is simple. Only the keycode need to injected. So we just use the scancode directly (As with KeyDown you will need to use a translation function for non Windows platforms. Check KeyDown above for more info):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// like before we inject the scancode directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Down and Mouse Wheel'''&amp;lt;br /&amp;gt;&lt;br /&gt;
CEGUI and SDL are a little different when it comes to mouse button and mouse wheel events. So a little conversion is necessary. Here's the ''handle_mouse_down'' function that gets called when a mouse button down event occurs in SDL. It takes one parameter, a ''Uint8'' describing the mouse button that was pressed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		// handle real mouse buttons&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		&lt;br /&gt;
		// handle the mouse wheel&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I chose a very &amp;quot;manual&amp;quot; conversion, but it works fine. Everything should be pretty self-explainatory.&lt;br /&gt;
As you can see mouse wheel events are emitted as mouse button down events in SDL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
The mouse button up event is handled very much like the mouse button down event, except there are no mousewheel release events.&lt;br /&gt;
Like ''handle_mouse_down'' it takes one parameter, a ''Uint8'' describing the mouse button that was released:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Time Pulses ===&lt;br /&gt;
SDL has a built-in millisecond counter which we will use for this example. There are other ways to use timers with SDL, but I chose this approach as it is simple to use, and provides decent precision.&lt;br /&gt;
&lt;br /&gt;
Remember in the main loop where we stored the current &amp;quot;run-time&amp;quot; in seconds ? This value will be passed as a reference to ''inject_time_pulse'' function which in turn will set a new value to it.&lt;br /&gt;
&lt;br /&gt;
CEGUI's interface for injecting time pulses requires that you pass the time in seconds that has passed since the last time pulse injection. Let's take a look at the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	// get current &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
&lt;br /&gt;
	// inject the time that passed since the last call &lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
&lt;br /&gt;
	// store the new time as the last time&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The first line gets the actual &amp;quot;run-time&amp;quot; when called.&lt;br /&gt;
* The second line injects the time pulse as the difference between the current time and the last time.&lt;br /&gt;
* The third line stores the current time as the last time a time pulse was injected.&lt;br /&gt;
&lt;br /&gt;
This will work for about 47 days... After that the counter wraps to zero and it breaks (a single insanely invalid timepulse will be injected).&lt;br /&gt;
I'll leave it up to you to fix that if it's a problem.&lt;br /&gt;
&lt;br /&gt;
=== Change of window size ===&lt;br /&gt;
If the window size changes (e.g. switching to fullscreen mode), we have to tell the openGlRenderer what's the new window size. Otherwise e.g. the Fonts aren't scaled properly. Therefore we add an SDL Event Handler for SDL_VIDEORESIZE and submit the new window size to the openGlRenderer of CEGUI.&lt;br /&gt;
If you have used previous versions you will know that you have to do some stuff here to stop textures from being skewed, but that is no longer an issue&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
      case SDL_VIDEORESIZE:&lt;br /&gt;
            //your resize code here, including the SDL_SetVideoMode call&lt;br /&gt;
            CEGUI::System::getSingleton().getRenderer()-&amp;gt;setDisplaySize(CEGUI::Size(event.resize.w, event.resize.h));&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rendering ===&lt;br /&gt;
Now all that's left is renderingthe GUI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	// clear the colour buffer&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
&lt;br /&gt;
	// render the GUI :)&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&lt;br /&gt;
	// Update the screen&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does all the CEGUI magic and sets OpenGL state itself. As long as the viewport is setup, it will render the GUI.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
The neat C++ architecture of CEGUI suggests that C++ exceptions are used for error handling. This is completely true.&lt;br /&gt;
Whenever an error occurs, a sub-class of ''CEGUI::Exception'' is thrown.&lt;br /&gt;
&lt;br /&gt;
There are many scenarios where an exception can be thrown. And whether or not these should be considered fatal depends on the application. To make sure you catch the CEGUI exceptions a regular ''try'' block is used. Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
	// do some cegui code&lt;br /&gt;
}&lt;br /&gt;
catch (CEGUI::Exception&amp;amp; e)&lt;br /&gt;
{&lt;br /&gt;
	fprintf(stderr,&amp;quot;CEGUI Exception occured: %s&amp;quot;, e.getMessage().c_str());&lt;br /&gt;
	// you could quit here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should provide you with the basic steps needed to get interactive with CEGUI in your SDL application.&lt;br /&gt;
Have fun.&lt;br /&gt;
&lt;br /&gt;
=== The Code ===&lt;br /&gt;
To compile under linux:&lt;br /&gt;
&amp;lt;code&amp;gt;gcc teste.cpp -I/usr/include/CEGUI/ -lSDL -lGL -lGLU -lCEGUIBase -lCEGUIOpenGLRenderer&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code uses release 0.5.0 of CEGUI.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Adapted by: Johnny Souza - johnnysouza.js@gmail.com&lt;br /&gt;
 * Date: 19/01/07 17:00&lt;br /&gt;
 * Description: Using CEGUI with SDL and OpenGL&lt;br /&gt;
 */&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;SDL/SDL.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;CEGUI.h&amp;gt;&lt;br /&gt;
#include &amp;lt;RendererModules/OpenGL/CEGUIOpenGLRenderer.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;GL/gl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;GL/glu.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button ) {&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
	{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_input (bool &amp;amp; must_quit) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Event e;&lt;br /&gt;
	/* go through all available events */&lt;br /&gt;
	while (SDL_PollEvent(&amp;amp;e)) {&lt;br /&gt;
		/* we use a switch to determine the event type */&lt;br /&gt;
		switch (e.type) {&lt;br /&gt;
			/* mouse motion handler */&lt;br /&gt;
			case SDL_MOUSEMOTION:&lt;br /&gt;
				/* we inject the mouse position directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectMousePosition(static_cast&amp;lt;float&amp;gt;(e.motion.x),static_cast&amp;lt;float&amp;gt;(e.motion.y));&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* mouse down handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
				/* let a special function handle the mouse button down event */&lt;br /&gt;
				handle_mouse_down (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* mouse up handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONUP:&lt;br /&gt;
				/* let a special function handle the mouse button up event */&lt;br /&gt;
				handle_mouse_up (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* key down */&lt;br /&gt;
			case SDL_KEYDOWN:&lt;br /&gt;
				/* to tell CEGUI that a key was pressed, we inject the scancode. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
				/* as for the character it's a litte more complicated.&lt;br /&gt;
				 * we'll use for translated unicode value.&lt;br /&gt;
				 * this is described in more detail below.&lt;br /&gt;
				 */&lt;br /&gt;
				if ((e.key.keysym.unicode &amp;amp; 0xFF80) == 0) {&lt;br /&gt;
					CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode &amp;amp; 0x7F);&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* key up */&lt;br /&gt;
			case SDL_KEYUP:&lt;br /&gt;
				/* like before we inject the scancode directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* WM quit event occured */&lt;br /&gt;
			case SDL_QUIT:&lt;br /&gt;
				must_quit = true;&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			case SDL_VIDEORESIZE:&lt;br /&gt;
				CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	/* get current &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
	/* inject the time that passed since the last call */&lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
	/* store the new time as the last time */&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	/* clear the colour buffer */&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
	/* render the GUI :) */&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
	/* Update the screen */&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main_loop () &lt;br /&gt;
{&lt;br /&gt;
	bool must_quit = false;&lt;br /&gt;
	/* get &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
	while (!must_quit) {&lt;br /&gt;
		inject_input (must_quit);&lt;br /&gt;
		inject_time_pulse (last_time_pulse);&lt;br /&gt;
		render_gui ();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main (int argc, char **argv) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Surface * screen;&lt;br /&gt;
	atexit (SDL_Quit);&lt;br /&gt;
	SDL_Init (SDL_INIT_VIDEO);&lt;br /&gt;
	screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);&lt;br /&gt;
	if (screen == NULL) {&lt;br /&gt;
		/* Se ainda não der, desiste! */ &lt;br /&gt;
		fprintf (stderr, &amp;quot;Impossível ajustar ao vídeo: %s\n&amp;quot;, SDL_GetError ());&lt;br /&gt;
		exit (1);&lt;br /&gt;
	}&lt;br /&gt;
        CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
	SDL_ShowCursor (SDL_DISABLE);&lt;br /&gt;
	SDL_EnableUNICODE (1);&lt;br /&gt;
	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
	main_loop();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[User:Lindquist]] 16:21, 8 May 2005 (BST)&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Deek0146</name></author>	</entry>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4302</id>
		<title>Using CEGUI with SDL and OpenGL (0.7)</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4302"/>
				<updated>2011-03-05T21:41:56Z</updated>
		
		<summary type="html">&lt;p&gt;Deek0146: /* The Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|0.7}}&lt;br /&gt;
[http://www.libsdl.org SDL (Simple DirectMedia Layer)] is an excellent library for writing portable games and other multimedia applications, but as it is a low-level library, it has no native support for GUI interfaces.&lt;br /&gt;
&lt;br /&gt;
When using [http://www.opengl.org OpenGL] for rendering, using CEGUI with SDL is not hard.&lt;br /&gt;
&lt;br /&gt;
I'll assume that you've read the imbiciles tutorials, and have used SDL with OpenGL.&lt;br /&gt;
And know C / C++ ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialisation ===&lt;br /&gt;
Before we can do anything, we need to initialise our libraries.&lt;br /&gt;
First SDL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_Init(SDL_INIT_VIDEO)&amp;lt;0)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to initialise SDL: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we initialise SDL with video support. We need this for CEGUI.&lt;br /&gt;
O.K. now SDL is ready to go. So let's fire up OpenGL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_SetVideoMode(800,600,0,SDL_OPENGL)==NULL)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to set OpenGL videomode: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  SDL_Quit();&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now OpenGL is ready. But we still need to set a decent configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glEnable(GL_CULL_FACE);&lt;br /&gt;
glDisable(GL_FOG);&lt;br /&gt;
glClearColor(0.0f,0.0f,0.0f,1.0f);&lt;br /&gt;
glViewport(0,0, 800,600);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The OpenGL renderer that comes with CEGUI sets the matrices itself, so if you're using CEGUI for all your rendering needs this would be fine. Normally you would want the normal perspective projection setup though:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glMatrixMode(GL_PROJECTION);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
gluPerspective(45.0, 800.0/600.0, 0.1,100.0);&lt;br /&gt;
glMatrixMode(GL_MODELVIEW);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SDL and OpenGL are now both ready for action. So it's time to initialise CEGUI.&lt;br /&gt;
This new &amp;quot;bootstrap&amp;quot; method in 0.7 is much simpler than the previous methods, it is one simple call&lt;br /&gt;
&lt;br /&gt;
First we need the include (Usually everything you need can be found in &amp;lt;CEGUI/CEGUI.h&amp;gt; but for initialising a specific subsystem you need to do this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;CEGUI/RendererModules/OpenGL/CEGUIOpenGLRenderer.h&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the call to initialise everything&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that you have to load a widget set, set the mouse cursor and a default font before CEGUI is completely ready. This is described in the other tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By default the SDL cursor is displayed, so we'll remove that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_ShowCursor(SDL_DISABLE);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As keypress characters needs to be injected into CEGUI, we activate unicode translation for SDL key events:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableUNICODE(1);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it alot easier as we don't have to worry about modifier keys and keyboard layouts ourselves. More about this later on...&lt;br /&gt;
&lt;br /&gt;
Key repeat is a nice feature for the text input widgets in CEGUI, so we use SDL to generate them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything is ready now, and we can start the main loop :)&lt;br /&gt;
&lt;br /&gt;
=== The Main Loop ===&lt;br /&gt;
To make it all happen, we use a simple main loop that just keeps pushing on those frames:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void main_loop()&lt;br /&gt;
{&lt;br /&gt;
  bool must_quit = false;&lt;br /&gt;
  &lt;br /&gt;
  // get &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
  double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
  &lt;br /&gt;
  while (!must_quit)&lt;br /&gt;
  {&lt;br /&gt;
    inject_input(must_quit);&lt;br /&gt;
    inject_time_pulse(last_time_pulse);&lt;br /&gt;
    render_gui();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function will run the main loop until the ''bool'' value ''must_quit'' becomes ''true''. In this tutorial this will happen when the user clicks the close button provided by the window manager.&lt;br /&gt;
&lt;br /&gt;
The ''double'' value ''last_time_pulse'' holds the time of the latest time pulse injection. More about this later.&lt;br /&gt;
&lt;br /&gt;
Each function in the ''while'' loop will be described below.&lt;br /&gt;
&lt;br /&gt;
There are endless ways of making your main loop. I took a simple approach to ease writing this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Injecting Input and injecting change of window size ===&lt;br /&gt;
When the user press or release keyboard or mouse buttons, we need to tell CEGUI about it, for this we use the injection functions of ''CEGUI::System''. We also have to tell &lt;br /&gt;
&lt;br /&gt;
Here is what our inject_input function looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_input(bool&amp;amp; must_quit)&lt;br /&gt;
{&lt;br /&gt;
  SDL_Event e;&lt;br /&gt;
  &lt;br /&gt;
  // go through all available events&lt;br /&gt;
  while (SDL_PollEvent(&amp;amp;e))&lt;br /&gt;
  {&lt;br /&gt;
    // we use a switch to determine the event type&lt;br /&gt;
    switch (e.type)&lt;br /&gt;
    {&lt;br /&gt;
      // mouse motion handler&lt;br /&gt;
      case SDL_MOUSEMOTION:&lt;br /&gt;
        // we inject the mouse position directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
        );&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse down handler&lt;br /&gt;
      case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
        // let a special function handle the mouse button down event&lt;br /&gt;
        handle_mouse_down(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse up handler&lt;br /&gt;
      case SDL_MOUSEBUTTONUP:&lt;br /&gt;
        // let a special function handle the mouse button up event&lt;br /&gt;
        handle_mouse_up(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // key down&lt;br /&gt;
      case SDL_KEYDOWN:&lt;br /&gt;
        // to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
        &lt;br /&gt;
        // as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
        // this is described in more detail below.&lt;br /&gt;
        if ((e.key.keysym.unicode != 0)&lt;br /&gt;
        {&lt;br /&gt;
          CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
        }&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // key up&lt;br /&gt;
      case SDL_KEYUP:&lt;br /&gt;
        // like before we inject the scancode directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // WM quit event occured&lt;br /&gt;
      case SDL_QUIT:&lt;br /&gt;
        must_quit = true;&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First I'll explain the events that get handled directly in the ''inject_input'' function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Motion''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// we inject the mouse position directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is nothing special here. Like stated in the comment the mouse position is just injected directly.&lt;br /&gt;
&lt;br /&gt;
There are two ways of injecting mouse motion. One where you inject how much the cursor moved, and one where you inject the mouse cursor position. The last one is failsafe.&lt;br /&gt;
Then first one only works correctly in fullscreen mode, or with input grabbed. The reason for this is that in regular windowed mode, the mouse can be moved outside the application window, and during this time no mouse motion event are generated. So if we enter the window at another position, the real mousecursor and CEGUI's mouse cursor will be offset, which will break mouse usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Down'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This event takes a little more work. CEGUI requires that key characters (the printable character the key represents) are injected alongside key codes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luckily the key code is just the SDL scancode, so we inject that directly. (This only seems to be true on windows. On other platforms you will need to use a translation function. One can be found here [[SDL to CEGUI keytable]])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
// this is described in more detail below.&lt;br /&gt;
if (e.key.keysym.unicode != 0)&lt;br /&gt;
{&lt;br /&gt;
  CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of formatting the keypress ourselves, we let SDL do it for us. We could check if we actually got a valid ASCII code, but we want support for local characters as well, so we won't do that. For more information, take a look at the SDL documentation for this feature. [http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fkeysym SDL_keysym].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is simple. Only the keycode need to injected. So we just use the scancode directly (As with KeyDown you will need to use a translation function for non Windows platforms. Check KeyDown above for more info):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// like before we inject the scancode directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Down and Mouse Wheel'''&amp;lt;br /&amp;gt;&lt;br /&gt;
CEGUI and SDL are a little different when it comes to mouse button and mouse wheel events. So a little conversion is necessary. Here's the ''handle_mouse_down'' function that gets called when a mouse button down event occurs in SDL. It takes one parameter, a ''Uint8'' describing the mouse button that was pressed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		// handle real mouse buttons&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		&lt;br /&gt;
		// handle the mouse wheel&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I chose a very &amp;quot;manual&amp;quot; conversion, but it works fine. Everything should be pretty self-explainatory.&lt;br /&gt;
As you can see mouse wheel events are emitted as mouse button down events in SDL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
The mouse button up event is handled very much like the mouse button down event, except there are no mousewheel release events.&lt;br /&gt;
Like ''handle_mouse_down'' it takes one parameter, a ''Uint8'' describing the mouse button that was released:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Time Pulses ===&lt;br /&gt;
SDL has a built-in millisecond counter which we will use for this example. There are other ways to use timers with SDL, but I chose this approach as it is simple to use, and provides decent precision.&lt;br /&gt;
&lt;br /&gt;
Remember in the main loop where we stored the current &amp;quot;run-time&amp;quot; in seconds ? This value will be passed as a reference to ''inject_time_pulse'' function which in turn will set a new value to it.&lt;br /&gt;
&lt;br /&gt;
CEGUI's interface for injecting time pulses requires that you pass the time in seconds that has passed since the last time pulse injection. Let's take a look at the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	// get current &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
&lt;br /&gt;
	// inject the time that passed since the last call &lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
&lt;br /&gt;
	// store the new time as the last time&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The first line gets the actual &amp;quot;run-time&amp;quot; when called.&lt;br /&gt;
* The second line injects the time pulse as the difference between the current time and the last time.&lt;br /&gt;
* The third line stores the current time as the last time a time pulse was injected.&lt;br /&gt;
&lt;br /&gt;
This will work for about 47 days... After that the counter wraps to zero and it breaks (a single insanely invalid timepulse will be injected).&lt;br /&gt;
I'll leave it up to you to fix that if it's a problem.&lt;br /&gt;
&lt;br /&gt;
=== Change of window size ===&lt;br /&gt;
If the window size changes (e.g. switching to fullscreen mode), we have to tell the openGlRenderer what's the new window size. Otherwise e.g. the Fonts aren't scaled properly. Therefore we add an SDL Event Handler for SDL_VIDEORESIZE and submit the new window size to the openGlRenderer of CEGUI.&lt;br /&gt;
If you have used previous versions you will know that you have to do some stuff here to stop textures from being skewed, but that is no longer an issue&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
      case SDL_VIDEORESIZE:&lt;br /&gt;
            //your resize code here, including the SDL_SetVideoMode call&lt;br /&gt;
            CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rendering ===&lt;br /&gt;
Now all that's left is renderingthe GUI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	// clear the colour buffer&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
&lt;br /&gt;
	// render the GUI :)&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&lt;br /&gt;
	// Update the screen&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does all the CEGUI magic and sets OpenGL state itself. As long as the viewport is setup, it will render the GUI.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
The neat C++ architecture of CEGUI suggests that C++ exceptions are used for error handling. This is completely true.&lt;br /&gt;
Whenever an error occurs, a sub-class of ''CEGUI::Exception'' is thrown.&lt;br /&gt;
&lt;br /&gt;
There are many scenarios where an exception can be thrown. And whether or not these should be considered fatal depends on the application. To make sure you catch the CEGUI exceptions a regular ''try'' block is used. Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
	// do some cegui code&lt;br /&gt;
}&lt;br /&gt;
catch (CEGUI::Exception&amp;amp; e)&lt;br /&gt;
{&lt;br /&gt;
	fprintf(stderr,&amp;quot;CEGUI Exception occured: %s&amp;quot;, e.getMessage().c_str());&lt;br /&gt;
	// you could quit here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should provide you with the basic steps needed to get interactive with CEGUI in your SDL application.&lt;br /&gt;
Have fun.&lt;br /&gt;
&lt;br /&gt;
=== The Code ===&lt;br /&gt;
To compile under linux:&lt;br /&gt;
&amp;lt;code&amp;gt;gcc teste.cpp -I/usr/include/CEGUI/ -lSDL -lGL -lGLU -lCEGUIBase -lCEGUIOpenGLRenderer&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code uses release 0.5.0 of CEGUI.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Adapted by: Johnny Souza - johnnysouza.js@gmail.com&lt;br /&gt;
 * Date: 19/01/07 17:00&lt;br /&gt;
 * Description: Using CEGUI with SDL and OpenGL&lt;br /&gt;
 */&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;SDL/SDL.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;CEGUI.h&amp;gt;&lt;br /&gt;
#include &amp;lt;RendererModules/OpenGL/CEGUIOpenGLRenderer.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;GL/gl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;GL/glu.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button ) {&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
	{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_input (bool &amp;amp; must_quit) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Event e;&lt;br /&gt;
	/* go through all available events */&lt;br /&gt;
	while (SDL_PollEvent(&amp;amp;e)) {&lt;br /&gt;
		/* we use a switch to determine the event type */&lt;br /&gt;
		switch (e.type) {&lt;br /&gt;
			/* mouse motion handler */&lt;br /&gt;
			case SDL_MOUSEMOTION:&lt;br /&gt;
				/* we inject the mouse position directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectMousePosition(static_cast&amp;lt;float&amp;gt;(e.motion.x),static_cast&amp;lt;float&amp;gt;(e.motion.y));&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* mouse down handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
				/* let a special function handle the mouse button down event */&lt;br /&gt;
				handle_mouse_down (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* mouse up handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONUP:&lt;br /&gt;
				/* let a special function handle the mouse button up event */&lt;br /&gt;
				handle_mouse_up (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* key down */&lt;br /&gt;
			case SDL_KEYDOWN:&lt;br /&gt;
				/* to tell CEGUI that a key was pressed, we inject the scancode. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
				/* as for the character it's a litte more complicated.&lt;br /&gt;
				 * we'll use for translated unicode value.&lt;br /&gt;
				 * this is described in more detail below.&lt;br /&gt;
				 */&lt;br /&gt;
				if ((e.key.keysym.unicode &amp;amp; 0xFF80) == 0) {&lt;br /&gt;
					CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode &amp;amp; 0x7F);&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* key up */&lt;br /&gt;
			case SDL_KEYUP:&lt;br /&gt;
				/* like before we inject the scancode directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* WM quit event occured */&lt;br /&gt;
			case SDL_QUIT:&lt;br /&gt;
				must_quit = true;&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			case SDL_VIDEORESIZE:&lt;br /&gt;
				CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	/* get current &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
	/* inject the time that passed since the last call */&lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
	/* store the new time as the last time */&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	/* clear the colour buffer */&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
	/* render the GUI :) */&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
	/* Update the screen */&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main_loop () &lt;br /&gt;
{&lt;br /&gt;
	bool must_quit = false;&lt;br /&gt;
	/* get &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
	while (!must_quit) {&lt;br /&gt;
		inject_input (must_quit);&lt;br /&gt;
		inject_time_pulse (last_time_pulse);&lt;br /&gt;
		render_gui ();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main (int argc, char **argv) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Surface * screen;&lt;br /&gt;
	atexit (SDL_Quit);&lt;br /&gt;
	SDL_Init (SDL_INIT_VIDEO);&lt;br /&gt;
	screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);&lt;br /&gt;
	if (screen == NULL) {&lt;br /&gt;
		/* Se ainda não der, desiste! */ &lt;br /&gt;
		fprintf (stderr, &amp;quot;Impossível ajustar ao vídeo: %s\n&amp;quot;, SDL_GetError ());&lt;br /&gt;
		exit (1);&lt;br /&gt;
	}&lt;br /&gt;
        CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
	SDL_ShowCursor (SDL_DISABLE);&lt;br /&gt;
	SDL_EnableUNICODE (1);&lt;br /&gt;
	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
	main_loop();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[User:Lindquist]] 16:21, 8 May 2005 (BST)&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Deek0146</name></author>	</entry>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4298</id>
		<title>Using CEGUI with SDL and OpenGL (0.7)</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4298"/>
				<updated>2011-03-05T21:23:49Z</updated>
		
		<summary type="html">&lt;p&gt;Deek0146: /* The Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|0.6}} {{VersionBadge|0.5}}&lt;br /&gt;
[http://www.libsdl.org SDL (Simple DirectMedia Layer)] is an excellent library for writing portable games and other multimedia applications, but as it is a low-level library, it has no native support for GUI interfaces.&lt;br /&gt;
&lt;br /&gt;
When using [http://www.opengl.org OpenGL] for rendering, using CEGUI with SDL is not hard.&lt;br /&gt;
&lt;br /&gt;
I'll assume that you've read the imbiciles tutorials, and have used SDL with OpenGL.&lt;br /&gt;
And know C / C++ ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialisation ===&lt;br /&gt;
Before we can do anything, we need to initialise our libraries.&lt;br /&gt;
First SDL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_Init(SDL_INIT_VIDEO)&amp;lt;0)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to initialise SDL: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we initialise SDL with video support. We need this for CEGUI.&lt;br /&gt;
O.K. now SDL is ready to go. So let's fire up OpenGL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_SetVideoMode(800,600,0,SDL_OPENGL)==NULL)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to set OpenGL videomode: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  SDL_Quit();&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now OpenGL is ready. But we still need to set a decent configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glEnable(GL_CULL_FACE);&lt;br /&gt;
glDisable(GL_FOG);&lt;br /&gt;
glClearColor(0.0f,0.0f,0.0f,1.0f);&lt;br /&gt;
glViewport(0,0, 800,600);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The OpenGL renderer that comes with CEGUI sets the matrices itself, so if you're using CEGUI for all your rendering needs this would be fine. Normally you would want the normal perspective projection setup though:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glMatrixMode(GL_PROJECTION);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
gluPerspective(45.0, 800.0/600.0, 0.1,100.0);&lt;br /&gt;
glMatrixMode(GL_MODELVIEW);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SDL and OpenGL are now both ready for action. So it's time to initialise CEGUI.&lt;br /&gt;
This new &amp;quot;bootstrap&amp;quot; method in 0.7 is much simpler than the previous methods, it is one simple call&lt;br /&gt;
&lt;br /&gt;
First we need the include (Usually everything you need can be found in &amp;lt;CEGUI/CEGUI.h&amp;gt; but for initialising a specific subsystem you need to do this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;CEGUI/RendererModules/OpenGL/CEGUIOpenGLRenderer.h&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the call to initialise everything&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that you have to load a widget set, set the mouse cursor and a default font before CEGUI is completely ready. This is described in the other tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By default the SDL cursor is displayed, so we'll remove that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_ShowCursor(SDL_DISABLE);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As keypress characters needs to be injected into CEGUI, we activate unicode translation for SDL key events:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableUNICODE(1);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it alot easier as we don't have to worry about modifier keys and keyboard layouts ourselves. More about this later on...&lt;br /&gt;
&lt;br /&gt;
Key repeat is a nice feature for the text input widgets in CEGUI, so we use SDL to generate them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything is ready now, and we can start the main loop :)&lt;br /&gt;
&lt;br /&gt;
=== The Main Loop ===&lt;br /&gt;
To make it all happen, we use a simple main loop that just keeps pushing on those frames:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void main_loop()&lt;br /&gt;
{&lt;br /&gt;
  bool must_quit = false;&lt;br /&gt;
  &lt;br /&gt;
  // get &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
  double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
  &lt;br /&gt;
  while (!must_quit)&lt;br /&gt;
  {&lt;br /&gt;
    inject_input(must_quit);&lt;br /&gt;
    inject_time_pulse(last_time_pulse);&lt;br /&gt;
    render_gui();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function will run the main loop until the ''bool'' value ''must_quit'' becomes ''true''. In this tutorial this will happen when the user clicks the close button provided by the window manager.&lt;br /&gt;
&lt;br /&gt;
The ''double'' value ''last_time_pulse'' holds the time of the latest time pulse injection. More about this later.&lt;br /&gt;
&lt;br /&gt;
Each function in the ''while'' loop will be described below.&lt;br /&gt;
&lt;br /&gt;
There are endless ways of making your main loop. I took a simple approach to ease writing this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Injecting Input and injecting change of window size ===&lt;br /&gt;
When the user press or release keyboard or mouse buttons, we need to tell CEGUI about it, for this we use the injection functions of ''CEGUI::System''. We also have to tell &lt;br /&gt;
&lt;br /&gt;
Here is what our inject_input function looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_input(bool&amp;amp; must_quit)&lt;br /&gt;
{&lt;br /&gt;
  SDL_Event e;&lt;br /&gt;
  &lt;br /&gt;
  // go through all available events&lt;br /&gt;
  while (SDL_PollEvent(&amp;amp;e))&lt;br /&gt;
  {&lt;br /&gt;
    // we use a switch to determine the event type&lt;br /&gt;
    switch (e.type)&lt;br /&gt;
    {&lt;br /&gt;
      // mouse motion handler&lt;br /&gt;
      case SDL_MOUSEMOTION:&lt;br /&gt;
        // we inject the mouse position directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
        );&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse down handler&lt;br /&gt;
      case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
        // let a special function handle the mouse button down event&lt;br /&gt;
        handle_mouse_down(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse up handler&lt;br /&gt;
      case SDL_MOUSEBUTTONUP:&lt;br /&gt;
        // let a special function handle the mouse button up event&lt;br /&gt;
        handle_mouse_up(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // key down&lt;br /&gt;
      case SDL_KEYDOWN:&lt;br /&gt;
        // to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
        &lt;br /&gt;
        // as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
        // this is described in more detail below.&lt;br /&gt;
        if ((e.key.keysym.unicode != 0)&lt;br /&gt;
        {&lt;br /&gt;
          CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
        }&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // key up&lt;br /&gt;
      case SDL_KEYUP:&lt;br /&gt;
        // like before we inject the scancode directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // WM quit event occured&lt;br /&gt;
      case SDL_QUIT:&lt;br /&gt;
        must_quit = true;&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First I'll explain the events that get handled directly in the ''inject_input'' function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Motion''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// we inject the mouse position directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is nothing special here. Like stated in the comment the mouse position is just injected directly.&lt;br /&gt;
&lt;br /&gt;
There are two ways of injecting mouse motion. One where you inject how much the cursor moved, and one where you inject the mouse cursor position. The last one is failsafe.&lt;br /&gt;
Then first one only works correctly in fullscreen mode, or with input grabbed. The reason for this is that in regular windowed mode, the mouse can be moved outside the application window, and during this time no mouse motion event are generated. So if we enter the window at another position, the real mousecursor and CEGUI's mouse cursor will be offset, which will break mouse usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Down'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This event takes a little more work. CEGUI requires that key characters (the printable character the key represents) are injected alongside key codes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luckily the key code is just the SDL scancode, so we inject that directly. (This only seems to be true on windows. On other platforms you will need to use a translation function. One can be found here [[SDL to CEGUI keytable]])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
// this is described in more detail below.&lt;br /&gt;
if (e.key.keysym.unicode != 0)&lt;br /&gt;
{&lt;br /&gt;
  CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of formatting the keypress ourselves, we let SDL do it for us. We could check if we actually got a valid ASCII code, but we want support for local characters as well, so we won't do that. For more information, take a look at the SDL documentation for this feature. [http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fkeysym SDL_keysym].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is simple. Only the keycode need to injected. So we just use the scancode directly (As with KeyDown you will need to use a translation function for non Windows platforms. Check KeyDown above for more info):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// like before we inject the scancode directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Down and Mouse Wheel'''&amp;lt;br /&amp;gt;&lt;br /&gt;
CEGUI and SDL are a little different when it comes to mouse button and mouse wheel events. So a little conversion is necessary. Here's the ''handle_mouse_down'' function that gets called when a mouse button down event occurs in SDL. It takes one parameter, a ''Uint8'' describing the mouse button that was pressed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		// handle real mouse buttons&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		&lt;br /&gt;
		// handle the mouse wheel&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I chose a very &amp;quot;manual&amp;quot; conversion, but it works fine. Everything should be pretty self-explainatory.&lt;br /&gt;
As you can see mouse wheel events are emitted as mouse button down events in SDL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
The mouse button up event is handled very much like the mouse button down event, except there are no mousewheel release events.&lt;br /&gt;
Like ''handle_mouse_down'' it takes one parameter, a ''Uint8'' describing the mouse button that was released:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Time Pulses ===&lt;br /&gt;
SDL has a built-in millisecond counter which we will use for this example. There are other ways to use timers with SDL, but I chose this approach as it is simple to use, and provides decent precision.&lt;br /&gt;
&lt;br /&gt;
Remember in the main loop where we stored the current &amp;quot;run-time&amp;quot; in seconds ? This value will be passed as a reference to ''inject_time_pulse'' function which in turn will set a new value to it.&lt;br /&gt;
&lt;br /&gt;
CEGUI's interface for injecting time pulses requires that you pass the time in seconds that has passed since the last time pulse injection. Let's take a look at the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	// get current &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
&lt;br /&gt;
	// inject the time that passed since the last call &lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
&lt;br /&gt;
	// store the new time as the last time&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The first line gets the actual &amp;quot;run-time&amp;quot; when called.&lt;br /&gt;
* The second line injects the time pulse as the difference between the current time and the last time.&lt;br /&gt;
* The third line stores the current time as the last time a time pulse was injected.&lt;br /&gt;
&lt;br /&gt;
This will work for about 47 days... After that the counter wraps to zero and it breaks (a single insanely invalid timepulse will be injected).&lt;br /&gt;
I'll leave it up to you to fix that if it's a problem.&lt;br /&gt;
&lt;br /&gt;
=== Change of window size ===&lt;br /&gt;
If the window size changes (e.g. switching to fullscreen mode), we have to tell the openGlRenderer what's the new window size. Otherwise e.g. the Fonts aren't scaled properly. Therefore we add an SDL Event Handler for SDL_VIDEORESIZE and submit the new window size to the openGlRenderer of CEGUI.&lt;br /&gt;
If you have used previous versions you will know that you have to do some stuff here to stop textures from being skewed, but that is no longer an issue&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
      case SDL_VIDEORESIZE:&lt;br /&gt;
            //your resize code here, including the SDL_SetVideoMode call&lt;br /&gt;
            CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rendering ===&lt;br /&gt;
Now all that's left is renderingthe GUI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	// clear the colour buffer&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
&lt;br /&gt;
	// render the GUI :)&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&lt;br /&gt;
	// Update the screen&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does all the CEGUI magic and sets OpenGL state itself. As long as the viewport is setup, it will render the GUI.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
The neat C++ architecture of CEGUI suggests that C++ exceptions are used for error handling. This is completely true.&lt;br /&gt;
Whenever an error occurs, a sub-class of ''CEGUI::Exception'' is thrown.&lt;br /&gt;
&lt;br /&gt;
There are many scenarios where an exception can be thrown. And whether or not these should be considered fatal depends on the application. To make sure you catch the CEGUI exceptions a regular ''try'' block is used. Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
	// do some cegui code&lt;br /&gt;
}&lt;br /&gt;
catch (CEGUI::Exception&amp;amp; e)&lt;br /&gt;
{&lt;br /&gt;
	fprintf(stderr,&amp;quot;CEGUI Exception occured: %s&amp;quot;, e.getMessage().c_str());&lt;br /&gt;
	// you could quit here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should provide you with the basic steps needed to get interactive with CEGUI in your SDL application.&lt;br /&gt;
Have fun.&lt;br /&gt;
&lt;br /&gt;
=== The Code ===&lt;br /&gt;
To compile under linux:&lt;br /&gt;
&amp;lt;code&amp;gt;gcc teste.cpp -I/usr/include/CEGUI/ -lSDL -lGL -lGLU -lCEGUIBase -lCEGUIOpenGLRenderer&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code uses release 0.5.0 of CEGUI.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Adapted by: Johnny Souza - johnnysouza.js@gmail.com&lt;br /&gt;
 * Date: 19/01/07 17:00&lt;br /&gt;
 * Description: Using CEGUI with SDL and OpenGL&lt;br /&gt;
 */&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;SDL/SDL.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;CEGUI.h&amp;gt;&lt;br /&gt;
/* for release 0.4.X use:&lt;br /&gt;
 * #include &amp;lt;renderers/OpenGLGUIRenderer/openglrenderer.h&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;RendererModules/OpenGLGUIRenderer/openglrenderer.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;GL/gl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;GL/glu.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
CEGUI::OpenGLRenderer *renderer;&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button ) {&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
	{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_input (bool &amp;amp; must_quit) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Event e;&lt;br /&gt;
	/* go through all available events */&lt;br /&gt;
	while (SDL_PollEvent(&amp;amp;e)) {&lt;br /&gt;
		/* we use a switch to determine the event type */&lt;br /&gt;
		switch (e.type) {&lt;br /&gt;
			/* mouse motion handler */&lt;br /&gt;
			case SDL_MOUSEMOTION:&lt;br /&gt;
				/* we inject the mouse position directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectMousePosition(static_cast&amp;lt;float&amp;gt;(e.motion.x),static_cast&amp;lt;float&amp;gt;(e.motion.y));&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* mouse down handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
				/* let a special function handle the mouse button down event */&lt;br /&gt;
				handle_mouse_down (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* mouse up handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONUP:&lt;br /&gt;
				/* let a special function handle the mouse button up event */&lt;br /&gt;
				handle_mouse_up (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* key down */&lt;br /&gt;
			case SDL_KEYDOWN:&lt;br /&gt;
				/* to tell CEGUI that a key was pressed, we inject the scancode. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
				/* as for the character it's a litte more complicated.&lt;br /&gt;
				 * we'll use for translated unicode value.&lt;br /&gt;
				 * this is described in more detail below.&lt;br /&gt;
				 */&lt;br /&gt;
				if ((e.key.keysym.unicode &amp;amp; 0xFF80) == 0) {&lt;br /&gt;
					CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode &amp;amp; 0x7F);&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* key up */&lt;br /&gt;
			case SDL_KEYUP:&lt;br /&gt;
				/* like before we inject the scancode directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* WM quit event occured */&lt;br /&gt;
			case SDL_QUIT:&lt;br /&gt;
				must_quit = true;&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			case SDL_VIDEORESIZE:&lt;br /&gt;
				CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	/* get current &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
	/* inject the time that passed since the last call */&lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
	/* store the new time as the last time */&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	/* clear the colour buffer */&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
	/* render the GUI :) */&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
	/* Update the screen */&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main_loop () &lt;br /&gt;
{&lt;br /&gt;
	bool must_quit = false;&lt;br /&gt;
	/* get &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
	while (!must_quit) {&lt;br /&gt;
		inject_input (must_quit);&lt;br /&gt;
		inject_time_pulse (last_time_pulse);&lt;br /&gt;
		render_gui ();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main (int argc, char **argv) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Surface * screen;&lt;br /&gt;
	atexit (SDL_Quit);&lt;br /&gt;
	SDL_Init (SDL_INIT_VIDEO);&lt;br /&gt;
	screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);&lt;br /&gt;
	if (screen == NULL) {&lt;br /&gt;
		/* Se ainda não der, desiste! */ &lt;br /&gt;
		fprintf (stderr, &amp;quot;Impossível ajustar ao vídeo: %s\n&amp;quot;, SDL_GetError ());&lt;br /&gt;
		exit (1);&lt;br /&gt;
	}&lt;br /&gt;
        CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
	SDL_ShowCursor (SDL_DISABLE);&lt;br /&gt;
	SDL_EnableUNICODE (1);&lt;br /&gt;
	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
	main_loop();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[User:Lindquist]] 16:21, 8 May 2005 (BST)&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Deek0146</name></author>	</entry>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4297</id>
		<title>Using CEGUI with SDL and OpenGL (0.7)</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4297"/>
				<updated>2011-03-05T21:22:58Z</updated>
		
		<summary type="html">&lt;p&gt;Deek0146: /* The Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|0.6}} {{VersionBadge|0.5}}&lt;br /&gt;
[http://www.libsdl.org SDL (Simple DirectMedia Layer)] is an excellent library for writing portable games and other multimedia applications, but as it is a low-level library, it has no native support for GUI interfaces.&lt;br /&gt;
&lt;br /&gt;
When using [http://www.opengl.org OpenGL] for rendering, using CEGUI with SDL is not hard.&lt;br /&gt;
&lt;br /&gt;
I'll assume that you've read the imbiciles tutorials, and have used SDL with OpenGL.&lt;br /&gt;
And know C / C++ ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialisation ===&lt;br /&gt;
Before we can do anything, we need to initialise our libraries.&lt;br /&gt;
First SDL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_Init(SDL_INIT_VIDEO)&amp;lt;0)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to initialise SDL: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we initialise SDL with video support. We need this for CEGUI.&lt;br /&gt;
O.K. now SDL is ready to go. So let's fire up OpenGL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_SetVideoMode(800,600,0,SDL_OPENGL)==NULL)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to set OpenGL videomode: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  SDL_Quit();&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now OpenGL is ready. But we still need to set a decent configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glEnable(GL_CULL_FACE);&lt;br /&gt;
glDisable(GL_FOG);&lt;br /&gt;
glClearColor(0.0f,0.0f,0.0f,1.0f);&lt;br /&gt;
glViewport(0,0, 800,600);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The OpenGL renderer that comes with CEGUI sets the matrices itself, so if you're using CEGUI for all your rendering needs this would be fine. Normally you would want the normal perspective projection setup though:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glMatrixMode(GL_PROJECTION);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
gluPerspective(45.0, 800.0/600.0, 0.1,100.0);&lt;br /&gt;
glMatrixMode(GL_MODELVIEW);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SDL and OpenGL are now both ready for action. So it's time to initialise CEGUI.&lt;br /&gt;
This new &amp;quot;bootstrap&amp;quot; method in 0.7 is much simpler than the previous methods, it is one simple call&lt;br /&gt;
&lt;br /&gt;
First we need the include (Usually everything you need can be found in &amp;lt;CEGUI/CEGUI.h&amp;gt; but for initialising a specific subsystem you need to do this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;CEGUI/RendererModules/OpenGL/CEGUIOpenGLRenderer.h&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the call to initialise everything&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that you have to load a widget set, set the mouse cursor and a default font before CEGUI is completely ready. This is described in the other tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By default the SDL cursor is displayed, so we'll remove that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_ShowCursor(SDL_DISABLE);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As keypress characters needs to be injected into CEGUI, we activate unicode translation for SDL key events:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableUNICODE(1);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it alot easier as we don't have to worry about modifier keys and keyboard layouts ourselves. More about this later on...&lt;br /&gt;
&lt;br /&gt;
Key repeat is a nice feature for the text input widgets in CEGUI, so we use SDL to generate them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything is ready now, and we can start the main loop :)&lt;br /&gt;
&lt;br /&gt;
=== The Main Loop ===&lt;br /&gt;
To make it all happen, we use a simple main loop that just keeps pushing on those frames:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void main_loop()&lt;br /&gt;
{&lt;br /&gt;
  bool must_quit = false;&lt;br /&gt;
  &lt;br /&gt;
  // get &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
  double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
  &lt;br /&gt;
  while (!must_quit)&lt;br /&gt;
  {&lt;br /&gt;
    inject_input(must_quit);&lt;br /&gt;
    inject_time_pulse(last_time_pulse);&lt;br /&gt;
    render_gui();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function will run the main loop until the ''bool'' value ''must_quit'' becomes ''true''. In this tutorial this will happen when the user clicks the close button provided by the window manager.&lt;br /&gt;
&lt;br /&gt;
The ''double'' value ''last_time_pulse'' holds the time of the latest time pulse injection. More about this later.&lt;br /&gt;
&lt;br /&gt;
Each function in the ''while'' loop will be described below.&lt;br /&gt;
&lt;br /&gt;
There are endless ways of making your main loop. I took a simple approach to ease writing this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Injecting Input and injecting change of window size ===&lt;br /&gt;
When the user press or release keyboard or mouse buttons, we need to tell CEGUI about it, for this we use the injection functions of ''CEGUI::System''. We also have to tell &lt;br /&gt;
&lt;br /&gt;
Here is what our inject_input function looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_input(bool&amp;amp; must_quit)&lt;br /&gt;
{&lt;br /&gt;
  SDL_Event e;&lt;br /&gt;
  &lt;br /&gt;
  // go through all available events&lt;br /&gt;
  while (SDL_PollEvent(&amp;amp;e))&lt;br /&gt;
  {&lt;br /&gt;
    // we use a switch to determine the event type&lt;br /&gt;
    switch (e.type)&lt;br /&gt;
    {&lt;br /&gt;
      // mouse motion handler&lt;br /&gt;
      case SDL_MOUSEMOTION:&lt;br /&gt;
        // we inject the mouse position directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
        );&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse down handler&lt;br /&gt;
      case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
        // let a special function handle the mouse button down event&lt;br /&gt;
        handle_mouse_down(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse up handler&lt;br /&gt;
      case SDL_MOUSEBUTTONUP:&lt;br /&gt;
        // let a special function handle the mouse button up event&lt;br /&gt;
        handle_mouse_up(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // key down&lt;br /&gt;
      case SDL_KEYDOWN:&lt;br /&gt;
        // to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
        &lt;br /&gt;
        // as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
        // this is described in more detail below.&lt;br /&gt;
        if ((e.key.keysym.unicode != 0)&lt;br /&gt;
        {&lt;br /&gt;
          CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
        }&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // key up&lt;br /&gt;
      case SDL_KEYUP:&lt;br /&gt;
        // like before we inject the scancode directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // WM quit event occured&lt;br /&gt;
      case SDL_QUIT:&lt;br /&gt;
        must_quit = true;&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First I'll explain the events that get handled directly in the ''inject_input'' function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Motion''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// we inject the mouse position directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is nothing special here. Like stated in the comment the mouse position is just injected directly.&lt;br /&gt;
&lt;br /&gt;
There are two ways of injecting mouse motion. One where you inject how much the cursor moved, and one where you inject the mouse cursor position. The last one is failsafe.&lt;br /&gt;
Then first one only works correctly in fullscreen mode, or with input grabbed. The reason for this is that in regular windowed mode, the mouse can be moved outside the application window, and during this time no mouse motion event are generated. So if we enter the window at another position, the real mousecursor and CEGUI's mouse cursor will be offset, which will break mouse usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Down'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This event takes a little more work. CEGUI requires that key characters (the printable character the key represents) are injected alongside key codes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luckily the key code is just the SDL scancode, so we inject that directly. (This only seems to be true on windows. On other platforms you will need to use a translation function. One can be found here [[SDL to CEGUI keytable]])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
// this is described in more detail below.&lt;br /&gt;
if (e.key.keysym.unicode != 0)&lt;br /&gt;
{&lt;br /&gt;
  CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of formatting the keypress ourselves, we let SDL do it for us. We could check if we actually got a valid ASCII code, but we want support for local characters as well, so we won't do that. For more information, take a look at the SDL documentation for this feature. [http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fkeysym SDL_keysym].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is simple. Only the keycode need to injected. So we just use the scancode directly (As with KeyDown you will need to use a translation function for non Windows platforms. Check KeyDown above for more info):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// like before we inject the scancode directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Down and Mouse Wheel'''&amp;lt;br /&amp;gt;&lt;br /&gt;
CEGUI and SDL are a little different when it comes to mouse button and mouse wheel events. So a little conversion is necessary. Here's the ''handle_mouse_down'' function that gets called when a mouse button down event occurs in SDL. It takes one parameter, a ''Uint8'' describing the mouse button that was pressed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		// handle real mouse buttons&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		&lt;br /&gt;
		// handle the mouse wheel&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I chose a very &amp;quot;manual&amp;quot; conversion, but it works fine. Everything should be pretty self-explainatory.&lt;br /&gt;
As you can see mouse wheel events are emitted as mouse button down events in SDL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
The mouse button up event is handled very much like the mouse button down event, except there are no mousewheel release events.&lt;br /&gt;
Like ''handle_mouse_down'' it takes one parameter, a ''Uint8'' describing the mouse button that was released:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Time Pulses ===&lt;br /&gt;
SDL has a built-in millisecond counter which we will use for this example. There are other ways to use timers with SDL, but I chose this approach as it is simple to use, and provides decent precision.&lt;br /&gt;
&lt;br /&gt;
Remember in the main loop where we stored the current &amp;quot;run-time&amp;quot; in seconds ? This value will be passed as a reference to ''inject_time_pulse'' function which in turn will set a new value to it.&lt;br /&gt;
&lt;br /&gt;
CEGUI's interface for injecting time pulses requires that you pass the time in seconds that has passed since the last time pulse injection. Let's take a look at the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	// get current &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
&lt;br /&gt;
	// inject the time that passed since the last call &lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
&lt;br /&gt;
	// store the new time as the last time&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The first line gets the actual &amp;quot;run-time&amp;quot; when called.&lt;br /&gt;
* The second line injects the time pulse as the difference between the current time and the last time.&lt;br /&gt;
* The third line stores the current time as the last time a time pulse was injected.&lt;br /&gt;
&lt;br /&gt;
This will work for about 47 days... After that the counter wraps to zero and it breaks (a single insanely invalid timepulse will be injected).&lt;br /&gt;
I'll leave it up to you to fix that if it's a problem.&lt;br /&gt;
&lt;br /&gt;
=== Change of window size ===&lt;br /&gt;
If the window size changes (e.g. switching to fullscreen mode), we have to tell the openGlRenderer what's the new window size. Otherwise e.g. the Fonts aren't scaled properly. Therefore we add an SDL Event Handler for SDL_VIDEORESIZE and submit the new window size to the openGlRenderer of CEGUI.&lt;br /&gt;
If you have used previous versions you will know that you have to do some stuff here to stop textures from being skewed, but that is no longer an issue&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
      case SDL_VIDEORESIZE:&lt;br /&gt;
            //your resize code here, including the SDL_SetVideoMode call&lt;br /&gt;
            CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rendering ===&lt;br /&gt;
Now all that's left is renderingthe GUI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	// clear the colour buffer&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
&lt;br /&gt;
	// render the GUI :)&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&lt;br /&gt;
	// Update the screen&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does all the CEGUI magic and sets OpenGL state itself. As long as the viewport is setup, it will render the GUI.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
The neat C++ architecture of CEGUI suggests that C++ exceptions are used for error handling. This is completely true.&lt;br /&gt;
Whenever an error occurs, a sub-class of ''CEGUI::Exception'' is thrown.&lt;br /&gt;
&lt;br /&gt;
There are many scenarios where an exception can be thrown. And whether or not these should be considered fatal depends on the application. To make sure you catch the CEGUI exceptions a regular ''try'' block is used. Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
	// do some cegui code&lt;br /&gt;
}&lt;br /&gt;
catch (CEGUI::Exception&amp;amp; e)&lt;br /&gt;
{&lt;br /&gt;
	fprintf(stderr,&amp;quot;CEGUI Exception occured: %s&amp;quot;, e.getMessage().c_str());&lt;br /&gt;
	// you could quit here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should provide you with the basic steps needed to get interactive with CEGUI in your SDL application.&lt;br /&gt;
Have fun.&lt;br /&gt;
&lt;br /&gt;
=== The Code ===&lt;br /&gt;
To compile under linux:&lt;br /&gt;
&amp;lt;code&amp;gt;gcc teste.cpp -I/usr/include/CEGUI/ -lSDL -lGL -lGLU -lCEGUIBase -lCEGUIOpenGLRenderer&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code uses release 0.5.0 of CEGUI.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Adapted by: Johnny Souza - johnnysouza.js@gmail.com&lt;br /&gt;
 * Date: 19/01/07 17:00&lt;br /&gt;
 * Description: Using CEGUI with SDL and OpenGL&lt;br /&gt;
 */&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;SDL/SDL.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;CEGUI.h&amp;gt;&lt;br /&gt;
/* for release 0.4.X use:&lt;br /&gt;
 * #include &amp;lt;renderers/OpenGLGUIRenderer/openglrenderer.h&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;RendererModules/OpenGLGUIRenderer/openglrenderer.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;GL/gl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;GL/glu.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
CEGUI::OpenGLRenderer *renderer;&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button ) {&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
	{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_input (bool &amp;amp; must_quit) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Event e;&lt;br /&gt;
	/* go through all available events */&lt;br /&gt;
	while (SDL_PollEvent(&amp;amp;e)) {&lt;br /&gt;
		/* we use a switch to determine the event type */&lt;br /&gt;
		switch (e.type) {&lt;br /&gt;
			/* mouse motion handler */&lt;br /&gt;
			case SDL_MOUSEMOTION:&lt;br /&gt;
				/* we inject the mouse position directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectMousePosition(static_cast&amp;lt;float&amp;gt;(e.motion.x),static_cast&amp;lt;float&amp;gt;(e.motion.y));&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* mouse down handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
				/* let a special function handle the mouse button down event */&lt;br /&gt;
				handle_mouse_down (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* mouse up handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONUP:&lt;br /&gt;
				/* let a special function handle the mouse button up event */&lt;br /&gt;
				handle_mouse_up (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* key down */&lt;br /&gt;
			case SDL_KEYDOWN:&lt;br /&gt;
				/* to tell CEGUI that a key was pressed, we inject the scancode. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
				/* as for the character it's a litte more complicated.&lt;br /&gt;
				 * we'll use for translated unicode value.&lt;br /&gt;
				 * this is described in more detail below.&lt;br /&gt;
				 */&lt;br /&gt;
				if ((e.key.keysym.unicode &amp;amp; 0xFF80) == 0) {&lt;br /&gt;
					CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode &amp;amp; 0x7F);&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* key up */&lt;br /&gt;
			case SDL_KEYUP:&lt;br /&gt;
				/* like before we inject the scancode directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* WM quit event occured */&lt;br /&gt;
			case SDL_QUIT:&lt;br /&gt;
				must_quit = true;&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			case SDL_VIDEORESIZE:&lt;br /&gt;
				CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	/* get current &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
	/* inject the time that passed since the last call */&lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
	/* store the new time as the last time */&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	/* clear the colour buffer */&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
	/* render the GUI :) */&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
	/* Update the screen */&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main_loop () &lt;br /&gt;
{&lt;br /&gt;
	bool must_quit = false;&lt;br /&gt;
	/* get &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
	while (!must_quit) {&lt;br /&gt;
		inject_input (must_quit);&lt;br /&gt;
		inject_time_pulse (last_time_pulse);&lt;br /&gt;
		render_gui ();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main (int argc, char **argv) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Surface * screen;&lt;br /&gt;
	atexit (SDL_Quit);&lt;br /&gt;
	SDL_Init (SDL_INIT_VIDEO);&lt;br /&gt;
	screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);&lt;br /&gt;
	if (screen == NULL) {&lt;br /&gt;
		/* Se ainda não der, desiste! */ &lt;br /&gt;
		fprintf (stderr, &amp;quot;Impossível ajustar ao vídeo: %s\n&amp;quot;, SDL_GetError ());&lt;br /&gt;
		exit (1);&lt;br /&gt;
	}&lt;br /&gt;
	renderer = new CEGUI::OpenGLRenderer (0, 600, 480);&lt;br /&gt;
	new CEGUI::System (renderer);&lt;br /&gt;
	SDL_ShowCursor (SDL_DISABLE);&lt;br /&gt;
	SDL_EnableUNICODE (1);&lt;br /&gt;
	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
	main_loop();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[User:Lindquist]] 16:21, 8 May 2005 (BST)&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Deek0146</name></author>	</entry>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4296</id>
		<title>Using CEGUI with SDL and OpenGL (0.7)</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=Using_CEGUI_with_SDL_and_OpenGL_(0.7)&amp;diff=4296"/>
				<updated>2011-03-05T21:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;Deek0146: Created page with &amp;quot;{{VersionBadge|0.6}} {{VersionBadge|0.5}} [http://www.libsdl.org SDL (Simple DirectMedia Layer)] is an excellent library for writing portable games and other multimedia applicati...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{VersionBadge|0.6}} {{VersionBadge|0.5}}&lt;br /&gt;
[http://www.libsdl.org SDL (Simple DirectMedia Layer)] is an excellent library for writing portable games and other multimedia applications, but as it is a low-level library, it has no native support for GUI interfaces.&lt;br /&gt;
&lt;br /&gt;
When using [http://www.opengl.org OpenGL] for rendering, using CEGUI with SDL is not hard.&lt;br /&gt;
&lt;br /&gt;
I'll assume that you've read the imbiciles tutorials, and have used SDL with OpenGL.&lt;br /&gt;
And know C / C++ ...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Initialisation ===&lt;br /&gt;
Before we can do anything, we need to initialise our libraries.&lt;br /&gt;
First SDL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_Init(SDL_INIT_VIDEO)&amp;lt;0)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to initialise SDL: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we initialise SDL with video support. We need this for CEGUI.&lt;br /&gt;
O.K. now SDL is ready to go. So let's fire up OpenGL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
if (SDL_SetVideoMode(800,600,0,SDL_OPENGL)==NULL)&lt;br /&gt;
{&lt;br /&gt;
  fprintf(stderr, &amp;quot;Unable to set OpenGL videomode: %s&amp;quot;, SDL_GetError());&lt;br /&gt;
  SDL_Quit();&lt;br /&gt;
  exit(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now OpenGL is ready. But we still need to set a decent configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glEnable(GL_CULL_FACE);&lt;br /&gt;
glDisable(GL_FOG);&lt;br /&gt;
glClearColor(0.0f,0.0f,0.0f,1.0f);&lt;br /&gt;
glViewport(0,0, 800,600);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The OpenGL renderer that comes with CEGUI sets the matrices itself, so if you're using CEGUI for all your rendering needs this would be fine. Normally you would want the normal perspective projection setup though:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
glMatrixMode(GL_PROJECTION);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
gluPerspective(45.0, 800.0/600.0, 0.1,100.0);&lt;br /&gt;
glMatrixMode(GL_MODELVIEW);&lt;br /&gt;
glLoadIdentity();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SDL and OpenGL are now both ready for action. So it's time to initialise CEGUI.&lt;br /&gt;
This new &amp;quot;bootstrap&amp;quot; method in 0.7 is much simpler than the previous methods, it is one simple call&lt;br /&gt;
&lt;br /&gt;
First we need the include (Usually everything you need can be found in &amp;lt;CEGUI/CEGUI.h&amp;gt; but for initialising a specific subsystem you need to do this&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;CEGUI/RendererModules/OpenGL/CEGUIOpenGLRenderer.h&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is the call to initialise everything&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::OpenGLRenderer::bootstrapSystem();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that you have to load a widget set, set the mouse cursor and a default font before CEGUI is completely ready. This is described in the other tutorials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
By default the SDL cursor is displayed, so we'll remove that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_ShowCursor(SDL_DISABLE);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As keypress characters needs to be injected into CEGUI, we activate unicode translation for SDL key events:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableUNICODE(1);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes it alot easier as we don't have to worry about modifier keys and keyboard layouts ourselves. More about this later on...&lt;br /&gt;
&lt;br /&gt;
Key repeat is a nice feature for the text input widgets in CEGUI, so we use SDL to generate them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything is ready now, and we can start the main loop :)&lt;br /&gt;
&lt;br /&gt;
=== The Main Loop ===&lt;br /&gt;
To make it all happen, we use a simple main loop that just keeps pushing on those frames:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void main_loop()&lt;br /&gt;
{&lt;br /&gt;
  bool must_quit = false;&lt;br /&gt;
  &lt;br /&gt;
  // get &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
  double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
  &lt;br /&gt;
  while (!must_quit)&lt;br /&gt;
  {&lt;br /&gt;
    inject_input(must_quit);&lt;br /&gt;
    inject_time_pulse(last_time_pulse);&lt;br /&gt;
    render_gui();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function will run the main loop until the ''bool'' value ''must_quit'' becomes ''true''. In this tutorial this will happen when the user clicks the close button provided by the window manager.&lt;br /&gt;
&lt;br /&gt;
The ''double'' value ''last_time_pulse'' holds the time of the latest time pulse injection. More about this later.&lt;br /&gt;
&lt;br /&gt;
Each function in the ''while'' loop will be described below.&lt;br /&gt;
&lt;br /&gt;
There are endless ways of making your main loop. I took a simple approach to ease writing this tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Injecting Input and injecting change of window size ===&lt;br /&gt;
When the user press or release keyboard or mouse buttons, we need to tell CEGUI about it, for this we use the injection functions of ''CEGUI::System''. We also have to tell &lt;br /&gt;
&lt;br /&gt;
Here is what our inject_input function looks like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_input(bool&amp;amp; must_quit)&lt;br /&gt;
{&lt;br /&gt;
  SDL_Event e;&lt;br /&gt;
  &lt;br /&gt;
  // go through all available events&lt;br /&gt;
  while (SDL_PollEvent(&amp;amp;e))&lt;br /&gt;
  {&lt;br /&gt;
    // we use a switch to determine the event type&lt;br /&gt;
    switch (e.type)&lt;br /&gt;
    {&lt;br /&gt;
      // mouse motion handler&lt;br /&gt;
      case SDL_MOUSEMOTION:&lt;br /&gt;
        // we inject the mouse position directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
          static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
        );&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse down handler&lt;br /&gt;
      case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
        // let a special function handle the mouse button down event&lt;br /&gt;
        handle_mouse_down(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // mouse up handler&lt;br /&gt;
      case SDL_MOUSEBUTTONUP:&lt;br /&gt;
        // let a special function handle the mouse button up event&lt;br /&gt;
        handle_mouse_up(e.button.button);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // key down&lt;br /&gt;
      case SDL_KEYDOWN:&lt;br /&gt;
        // to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
        &lt;br /&gt;
        // as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
        // this is described in more detail below.&lt;br /&gt;
        if ((e.key.keysym.unicode != 0)&lt;br /&gt;
        {&lt;br /&gt;
          CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
        }&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
      // key up&lt;br /&gt;
      case SDL_KEYUP:&lt;br /&gt;
        // like before we inject the scancode directly.&lt;br /&gt;
        CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
      // WM quit event occured&lt;br /&gt;
      case SDL_QUIT:&lt;br /&gt;
        must_quit = true;&lt;br /&gt;
        break;&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First I'll explain the events that get handled directly in the ''inject_input'' function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Motion''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// we inject the mouse position directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectMousePosition(&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.x),&lt;br /&gt;
  static_cast&amp;lt;float&amp;gt;(e.motion.y)&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is nothing special here. Like stated in the comment the mouse position is just injected directly.&lt;br /&gt;
&lt;br /&gt;
There are two ways of injecting mouse motion. One where you inject how much the cursor moved, and one where you inject the mouse cursor position. The last one is failsafe.&lt;br /&gt;
Then first one only works correctly in fullscreen mode, or with input grabbed. The reason for this is that in regular windowed mode, the mouse can be moved outside the application window, and during this time no mouse motion event are generated. So if we enter the window at another position, the real mousecursor and CEGUI's mouse cursor will be offset, which will break mouse usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Down'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This event takes a little more work. CEGUI requires that key characters (the printable character the key represents) are injected alongside key codes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// to tell CEGUI that a key was pressed, we inject the scancode.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luckily the key code is just the SDL scancode, so we inject that directly. (This only seems to be true on windows. On other platforms you will need to use a translation function. One can be found here [[SDL to CEGUI keytable]])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// as for the character it's a litte more complicated. we'll use for translated unicode value.&lt;br /&gt;
// this is described in more detail below.&lt;br /&gt;
if (e.key.keysym.unicode != 0)&lt;br /&gt;
{&lt;br /&gt;
  CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of formatting the keypress ourselves, we let SDL do it for us. We could check if we actually got a valid ASCII code, but we want support for local characters as well, so we won't do that. For more information, take a look at the SDL documentation for this feature. [http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fkeysym SDL_keysym].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Key Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
This one is simple. Only the keycode need to injected. So we just use the scancode directly (As with KeyDown you will need to use a translation function for non Windows platforms. Check KeyDown above for more info):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
// like before we inject the scancode directly.&lt;br /&gt;
CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Down and Mouse Wheel'''&amp;lt;br /&amp;gt;&lt;br /&gt;
CEGUI and SDL are a little different when it comes to mouse button and mouse wheel events. So a little conversion is necessary. Here's the ''handle_mouse_down'' function that gets called when a mouse button down event occurs in SDL. It takes one parameter, a ''Uint8'' describing the mouse button that was pressed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		// handle real mouse buttons&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		&lt;br /&gt;
		// handle the mouse wheel&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I chose a very &amp;quot;manual&amp;quot; conversion, but it works fine. Everything should be pretty self-explainatory.&lt;br /&gt;
As you can see mouse wheel events are emitted as mouse button down events in SDL.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Mouse Button Up'''&amp;lt;br /&amp;gt;&lt;br /&gt;
The mouse button up event is handled very much like the mouse button down event, except there are no mousewheel release events.&lt;br /&gt;
Like ''handle_mouse_down'' it takes one parameter, a ''Uint8'' describing the mouse button that was released:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
	{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
		{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Time Pulses ===&lt;br /&gt;
SDL has a built-in millisecond counter which we will use for this example. There are other ways to use timers with SDL, but I chose this approach as it is simple to use, and provides decent precision.&lt;br /&gt;
&lt;br /&gt;
Remember in the main loop where we stored the current &amp;quot;run-time&amp;quot; in seconds ? This value will be passed as a reference to ''inject_time_pulse'' function which in turn will set a new value to it.&lt;br /&gt;
&lt;br /&gt;
CEGUI's interface for injecting time pulses requires that you pass the time in seconds that has passed since the last time pulse injection. Let's take a look at the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	// get current &amp;quot;run-time&amp;quot; in seconds&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
&lt;br /&gt;
	// inject the time that passed since the last call &lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
&lt;br /&gt;
	// store the new time as the last time&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The first line gets the actual &amp;quot;run-time&amp;quot; when called.&lt;br /&gt;
* The second line injects the time pulse as the difference between the current time and the last time.&lt;br /&gt;
* The third line stores the current time as the last time a time pulse was injected.&lt;br /&gt;
&lt;br /&gt;
This will work for about 47 days... After that the counter wraps to zero and it breaks (a single insanely invalid timepulse will be injected).&lt;br /&gt;
I'll leave it up to you to fix that if it's a problem.&lt;br /&gt;
&lt;br /&gt;
=== Change of window size ===&lt;br /&gt;
If the window size changes (e.g. switching to fullscreen mode), we have to tell the openGlRenderer what's the new window size. Otherwise e.g. the Fonts aren't scaled properly. Therefore we add an SDL Event Handler for SDL_VIDEORESIZE and submit the new window size to the openGlRenderer of CEGUI.&lt;br /&gt;
If you have used previous versions you will know that you have to do some stuff here to stop textures from being skewed, but that is no longer an issue&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
      case SDL_VIDEORESIZE:&lt;br /&gt;
            //your resize code here, including the SDL_SetVideoMode call&lt;br /&gt;
            CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Size(event.resize.w,event.resize.h));&lt;br /&gt;
            break;&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rendering ===&lt;br /&gt;
Now all that's left is renderingthe GUI.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	// clear the colour buffer&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
&lt;br /&gt;
	// render the GUI :)&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&lt;br /&gt;
	// Update the screen&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does all the CEGUI magic and sets OpenGL state itself. As long as the viewport is setup, it will render the GUI.&lt;br /&gt;
&lt;br /&gt;
=== Error Handling ===&lt;br /&gt;
The neat C++ architecture of CEGUI suggests that C++ exceptions are used for error handling. This is completely true.&lt;br /&gt;
Whenever an error occurs, a sub-class of ''CEGUI::Exception'' is thrown.&lt;br /&gt;
&lt;br /&gt;
There are many scenarios where an exception can be thrown. And whether or not these should be considered fatal depends on the application. To make sure you catch the CEGUI exceptions a regular ''try'' block is used. Like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
try&lt;br /&gt;
{&lt;br /&gt;
	// do some cegui code&lt;br /&gt;
}&lt;br /&gt;
catch (CEGUI::Exception&amp;amp; e)&lt;br /&gt;
{&lt;br /&gt;
	fprintf(stderr,&amp;quot;CEGUI Exception occured: %s&amp;quot;, e.getMessage().c_str());&lt;br /&gt;
	// you could quit here&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This should provide you with the basic steps needed to get interactive with CEGUI in your SDL application.&lt;br /&gt;
Have fun.&lt;br /&gt;
&lt;br /&gt;
=== The Code ===&lt;br /&gt;
To compile under linux:&lt;br /&gt;
&amp;lt;code&amp;gt;gcc teste.cpp -I/usr/include/CEGUI/ -lSDL -lGL -lGLU -lCEGUIBase -lCEGUIOpenGLRenderer&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code uses release 0.5.0 of CEGUI.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * Adapted by: Johnny Souza - johnnysouza.js@gmail.com&lt;br /&gt;
 * Date: 19/01/07 17:00&lt;br /&gt;
 * Description: Using CEGUI with SDL and OpenGL&lt;br /&gt;
 */&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;SDL/SDL.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;CEGUI.h&amp;gt;&lt;br /&gt;
/* for release 0.4.X use:&lt;br /&gt;
 * #include &amp;lt;renderers/OpenGLGUIRenderer/openglrenderer.h&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;RendererModules/OpenGLGUIRenderer/openglrenderer.h&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;GL/gl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;GL/glu.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
CEGUI::OpenGLRenderer *renderer;&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_down(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button ) {&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
&lt;br /&gt;
		case SDL_BUTTON_WHEELDOWN:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( -1 );&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_WHEELUP:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseWheelChange( +1 );&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void handle_mouse_up(Uint8 button)&lt;br /&gt;
{&lt;br /&gt;
	switch ( button )&lt;br /&gt;
	{&lt;br /&gt;
		case SDL_BUTTON_LEFT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_MIDDLE:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);&lt;br /&gt;
			break;&lt;br /&gt;
		case SDL_BUTTON_RIGHT:&lt;br /&gt;
			CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);&lt;br /&gt;
			break;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_input (bool &amp;amp; must_quit) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Event e;&lt;br /&gt;
	/* go through all available events */&lt;br /&gt;
	while (SDL_PollEvent(&amp;amp;e)) {&lt;br /&gt;
		/* we use a switch to determine the event type */&lt;br /&gt;
		switch (e.type) {&lt;br /&gt;
			/* mouse motion handler */&lt;br /&gt;
			case SDL_MOUSEMOTION:&lt;br /&gt;
				/* we inject the mouse position directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectMousePosition(static_cast&amp;lt;float&amp;gt;(e.motion.x),static_cast&amp;lt;float&amp;gt;(e.motion.y));&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* mouse down handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONDOWN:&lt;br /&gt;
				/* let a special function handle the mouse button down event */&lt;br /&gt;
				handle_mouse_down (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* mouse up handler */&lt;br /&gt;
			case SDL_MOUSEBUTTONUP:&lt;br /&gt;
				/* let a special function handle the mouse button up event */&lt;br /&gt;
				handle_mouse_up (e.button.button);&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			/* key down */&lt;br /&gt;
			case SDL_KEYDOWN:&lt;br /&gt;
				/* to tell CEGUI that a key was pressed, we inject the scancode. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyDown(e.key.keysym.scancode);&lt;br /&gt;
				/* as for the character it's a litte more complicated.&lt;br /&gt;
				 * we'll use for translated unicode value.&lt;br /&gt;
				 * this is described in more detail below.&lt;br /&gt;
				 */&lt;br /&gt;
				if ((e.key.keysym.unicode &amp;amp; 0xFF80) == 0) {&lt;br /&gt;
					CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode &amp;amp; 0x7F);&lt;br /&gt;
				}&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* key up */&lt;br /&gt;
			case SDL_KEYUP:&lt;br /&gt;
				/* like before we inject the scancode directly. */&lt;br /&gt;
				CEGUI::System::getSingleton().injectKeyUp(e.key.keysym.scancode);&lt;br /&gt;
				break;&lt;br /&gt;
	 &lt;br /&gt;
			/* WM quit event occured */&lt;br /&gt;
			case SDL_QUIT:&lt;br /&gt;
				must_quit = true;&lt;br /&gt;
				break;&lt;br /&gt;
&lt;br /&gt;
			case SDL_VIDEORESIZE:&lt;br /&gt;
				renderer-&amp;gt;setDisplaySize(CEGUI::Size(e.resize.w, e.resize.h));&lt;br /&gt;
				break;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void inject_time_pulse(double&amp;amp; last_time_pulse)&lt;br /&gt;
{&lt;br /&gt;
	/* get current &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double t = 0.001*SDL_GetTicks();&lt;br /&gt;
	/* inject the time that passed since the last call */&lt;br /&gt;
	CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );&lt;br /&gt;
	/* store the new time as the last time */&lt;br /&gt;
	last_time_pulse = t;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void render_gui()&lt;br /&gt;
{&lt;br /&gt;
	/* clear the colour buffer */&lt;br /&gt;
	glClear( GL_COLOR_BUFFER_BIT );&lt;br /&gt;
	/* render the GUI :) */&lt;br /&gt;
	CEGUI::System::getSingleton().renderGUI();&lt;br /&gt;
	/* Update the screen */&lt;br /&gt;
	SDL_GL_SwapBuffers();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main_loop () &lt;br /&gt;
{&lt;br /&gt;
	bool must_quit = false;&lt;br /&gt;
	/* get &amp;quot;run-time&amp;quot; in seconds */&lt;br /&gt;
	double last_time_pulse = 0.001*static_cast&amp;lt;double&amp;gt;(SDL_GetTicks());&lt;br /&gt;
	while (!must_quit) {&lt;br /&gt;
		inject_input (must_quit);&lt;br /&gt;
		inject_time_pulse (last_time_pulse);&lt;br /&gt;
		render_gui ();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main (int argc, char **argv) &lt;br /&gt;
{&lt;br /&gt;
	SDL_Surface * screen;&lt;br /&gt;
	atexit (SDL_Quit);&lt;br /&gt;
	SDL_Init (SDL_INIT_VIDEO);&lt;br /&gt;
	screen = SDL_SetVideoMode (600, 480, 0, SDL_OPENGL);&lt;br /&gt;
	if (screen == NULL) {&lt;br /&gt;
		/* Se ainda não der, desiste! */ &lt;br /&gt;
		fprintf (stderr, &amp;quot;Impossível ajustar ao vídeo: %s\n&amp;quot;, SDL_GetError ());&lt;br /&gt;
		exit (1);&lt;br /&gt;
	}&lt;br /&gt;
	renderer = new CEGUI::OpenGLRenderer (0, 600, 480);&lt;br /&gt;
	new CEGUI::System (renderer);&lt;br /&gt;
	SDL_ShowCursor (SDL_DISABLE);&lt;br /&gt;
	SDL_EnableUNICODE (1);&lt;br /&gt;
	SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);&lt;br /&gt;
	main_loop();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[User:Lindquist]] 16:21, 8 May 2005 (BST)&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Deek0146</name></author>	</entry>

	</feed>