Index: code/branches/gui/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/gui/src/orxonox/CMakeLists.txt	(revision 1641)
+++ code/branches/gui/src/orxonox/CMakeLists.txt	(revision 1642)
@@ -7,4 +7,9 @@
   RadarViewable.cc
   Settings.cc
+
+  gui/GUIManager.cc
+  gui/OgreCEGUIRenderer.cpp
+  gui/OgreCEGUIResourceProvider.cpp
+  gui/OgreCEGUITexture.cpp
 
   overlays/OrxonoxOverlay.cc
Index: code/branches/gui/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/gui/src/orxonox/Orxonox.cc	(revision 1641)
+++ code/branches/gui/src/orxonox/Orxonox.cc	(revision 1642)
@@ -104,8 +104,6 @@
    */
   Orxonox::Orxonox()
-    : ogre_(0)
-    , startLevel_(0)
+    : startLevel_(0)
     , hud_(0)
-    , radar_(0)
     //, auMan_(0)
     , timer_(0)
@@ -114,8 +112,12 @@
     , mode_(GameMode::GM_Unspecified)
     , debugRefreshTime_(0.0f)
+    , ogre_(0)
+    , inputManager_(0)
+    , radar_(0)
   {
     RegisterRootObject(Orxonox);
 
-    assert(singletonRef_s == 0);
+    //assert(singletonRef_s == 0);
+    OrxAssert(singletonRef_s == 0, "asdfasdfasdfasdfblahblah");
     singletonRef_s = this;
   }
@@ -127,5 +129,8 @@
   {
     // keep in mind: the order of deletion is very important!
-    Loader::unload();
+    if (this->timer_)
+      delete this->timer_;
+
+    Loader::unload(startLevel_);
     if (this->startLevel_)
       delete this->startLevel_;
@@ -138,11 +143,12 @@
       delete this->radar_;
 
-    Loader::close();
     //if (this->auMan_)
     //  delete this->auMan_;
-    InGameConsole::getInstance().destroy();
-    if (this->timer_)
-      delete this->timer_;
-    InputManager::destroy();
+
+    if (this->console_)
+      delete this->console_;
+
+    if (inputManager_)
+      delete inputManager_;
 
     if (this->ogre_)
@@ -153,4 +159,10 @@
     if (server_g)
       delete network::Server::getSingleton();
+
+    // this call will delete every BaseObject!
+    // But currently this will call methods of objects that exist no more
+    // The only 'memory leak' is the ParticleSpawer. They would be deleted here
+    // and call a sceneNode method that has already been destroy by the corresponding space ship.
+    //Loader::close();
 
     singletonRef_s = 0;
@@ -247,12 +259,14 @@
           // Calls the InputManager which sets up the input devices.
           // The render window width and height are used to set up the mouse movement.
-          InputManager::initialise(ogre_->getWindowHandle(),
+          inputManager_ = new InputManager();
+          inputManager_->initialise(ogre_->getWindowHandle(),
                 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true);
           KeyBinder* keyBinder = new KeyBinder();
           keyBinder->loadBindings();
-          InputManager::createSimpleInputState("game", 20)->setHandler(keyBinder);
+          inputManager_->createSimpleInputState("game", 20)->setHandler(keyBinder);
 
           // Load the InGameConsole
-          InGameConsole::getInstance().initialise();
+          console_ = new InGameConsole();
+          console_->initialise();
 
           // load the CEGUI interface
@@ -342,5 +356,5 @@
       if (success)
       {
-        InputManager::requestEnterState("game");
+        InputManager::getInstance().requestEnterState("game");
         this->mode_ = mode;
       }
Index: code/branches/gui/src/orxonox/Orxonox.h
===================================================================
--- code/branches/gui/src/orxonox/Orxonox.h	(revision 1641)
+++ code/branches/gui/src/orxonox/Orxonox.h	(revision 1642)
@@ -84,8 +84,6 @@
 
     private:
-      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
       Level*                startLevel_;    //!< current hard coded default level
       Level*                hud_;           //!< 'level' object fo the HUD
-      Radar*                radar_;         //!< represents the Radar (not the HUD part)
       //audio::AudioManager*  auMan_;         //!< audio manager
       Ogre::Timer*          timer_;         //!< Main loop timer
@@ -100,4 +98,10 @@
       float                 debugRefreshTime_;
 
+      // By Orxonox managed singleton pointers
+      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
+      InputManager*         inputManager_;
+      Radar*                radar_;         //!< represents the Radar (not the HUD part)
+      InGameConsole*        console_;
+
       static Orxonox *singletonRef_s;
   };
Index: code/branches/gui/src/orxonox/gui/GUIManager.cc
===================================================================
--- code/branches/gui/src/orxonox/gui/GUIManager.cc	(revision 1641)
+++ code/branches/gui/src/orxonox/gui/GUIManager.cc	(revision 1642)
@@ -117,5 +117,5 @@
 
                 // register us as input handler
-                SimpleInputState* state = InputManager::createSimpleInputState("gui", 30);
+                SimpleInputState* state = InputManager::getInstance().createSimpleInputState("gui", 30);
                 state->setHandler(this);
                 state->setJoyStickHandler(new EmptyHandler());
@@ -203,5 +203,5 @@
                 this->scriptModule_->executeScriptGlobal("showMainMenu");
 
-                InputManager::requestEnterState("gui");
+                InputManager::getInstance().requestEnterState("gui");
 
                 this->state_ = OnDisplay;
@@ -229,5 +229,5 @@
         this->guiRenderer_->setTargetSceneManager(0);
         this->state_ = Ready;
-        InputManager::requestLeaveState("gui");
+        InputManager::getInstance().requestLeaveState("gui");
     }
 
Index: code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
===================================================================
--- code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc	(revision 1641)
+++ code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc	(revision 1642)
@@ -58,4 +58,6 @@
     SetConsoleCommand(InGameConsole, closeConsole, true);
 
+    InGameConsole* InGameConsole::singletonRef_s = 0;
+
     /**
         @brief Constructor: Creates and initializes the InGameConsole.
@@ -71,4 +73,7 @@
         RegisterObject(InGameConsole);
 
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
+
         this->bActive_ = false;
         this->cursor_ = 0.0f;
@@ -87,128 +92,8 @@
     InGameConsole::~InGameConsole(void)
     {
-        this->destroy();
-    }
-
-    /**
-        @brief Returns a reference to the only existing instance of InGameConsole.
-    */
-    InGameConsole& InGameConsole::getInstance()
-    {
-        static InGameConsole instance;
-        return instance;
-    }
-
-    /**
-        @brief Sets the config values, describing the size of the console.
-    */
-    void InGameConsole::setConfigValues()
-    {
-        SetConfigValue(relativeWidth, 0.8);
-        SetConfigValue(relativeHeight, 0.4);
-        SetConfigValue(blinkTime, 0.5);
-        SetConfigValue(scrollSpeed_, 3.0f);
-        SetConfigValue(noiseSize_, 1.0f);
-        SetConfigValue(cursorSymbol_, '|');
-    }
-
-    /**
-        @brief Initializes the InGameConsole.
-    */
-    void InGameConsole::initialise()
-    {
-        // create the corresponding input state
-        InputManager::createSimpleInputState("console", 40)->setKeyHandler(Shell::getInstance().getInputBuffer());
-
-        // create overlay and elements
-        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
-
-        // create actual overlay
-        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
-
-        // create a container
-        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
-        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
-        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
-        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
-        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
-
-        // create BorderPanel
-        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
-        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
-        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
-        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
-        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
-        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
-        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
-        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
-        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
-        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
-        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
-
-        // create a new font to match the requested size exactly
-        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
-            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
-        font->setType(Ogre::FT_TRUETYPE);
-        font->setSource("Monofur.ttf");
-        font->setTrueTypeSize(18);
-        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
-        font->setTrueTypeResolution(192);
-        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
-        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
-
-        // create the text lines
-        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
-        for (int i = 0; i < LINES; i++)
-        {
-            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
-            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
-            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
-            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
-            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
-            this->consoleOverlayTextAreas_[i]->setLeft(8);
-            this->consoleOverlayTextAreas_[i]->setCaption("");
-            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
-        }
-
-        // create cursor (also a text area overlay element)
-        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
-        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
-        this->consoleOverlayCursor_->setFontName("MonofurConsole");
-        this->consoleOverlayCursor_->setCharHeight(18);
-        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
-        this->consoleOverlayCursor_->setLeft(7);
-        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
-        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
-
-        // create noise
-        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
-        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
-        this->consoleOverlayNoise_->setPosition(5,0);
-        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
-        // comment following line to disable noise
-        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
-
-        this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
-
-        // move overlay "above" the top edge of the screen
-        // we take -1.2 because the border makes the panel bigger
-        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
-
-        Shell::getInstance().addOutputLevel(true);
-
-        COUT(4) << "Info: InGameConsole initialized" << std::endl;
-    }
-
-    /**
-        @brief Destroys all the elements if necessary.
-    */
-    void InGameConsole::destroy()
-    {
         this->deactivate();
 
-        // destroy the input state previously created
-        SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
-        if (inputState)
-            InputManager::destroyState("console");
+        // destroy the input state previously created (InputBuffer gets destroyed by the Shell)
+        InputManager::getInstance().destroyState("console");
 
         Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
@@ -239,4 +124,108 @@
             this->consoleOverlayTextAreas_ = 0;
         }
+
+        singletonRef_s = 0;
+    }
+
+    /**
+        @brief Sets the config values, describing the size of the console.
+    */
+    void InGameConsole::setConfigValues()
+    {
+        SetConfigValue(relativeWidth, 0.8);
+        SetConfigValue(relativeHeight, 0.4);
+        SetConfigValue(blinkTime, 0.5);
+        SetConfigValue(scrollSpeed_, 3.0f);
+        SetConfigValue(noiseSize_, 1.0f);
+        SetConfigValue(cursorSymbol_, '|');
+    }
+
+    /**
+        @brief Initializes the InGameConsole.
+    */
+    void InGameConsole::initialise()
+    {
+        // create the corresponding input state
+        InputManager::getInstance().createSimpleInputState("console", 40)
+            ->setKeyHandler(Shell::getInstance().getInputBuffer());
+
+        // create overlay and elements
+        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
+
+        // create actual overlay
+        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
+
+        // create a container
+        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
+        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
+        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
+        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
+        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
+
+        // create BorderPanel
+        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
+        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
+        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
+        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
+        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
+        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
+        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
+        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
+        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
+        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
+        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
+
+        // create a new font to match the requested size exactly
+        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
+            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
+        font->setType(Ogre::FT_TRUETYPE);
+        font->setSource("Monofur.ttf");
+        font->setTrueTypeSize(18);
+        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
+        font->setTrueTypeResolution(192);
+        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
+        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
+
+        // create the text lines
+        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
+        for (int i = 0; i < LINES; i++)
+        {
+            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
+            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
+            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
+            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
+            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
+            this->consoleOverlayTextAreas_[i]->setLeft(8);
+            this->consoleOverlayTextAreas_[i]->setCaption("");
+            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
+        }
+
+        // create cursor (also a text area overlay element)
+        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
+        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
+        this->consoleOverlayCursor_->setFontName("MonofurConsole");
+        this->consoleOverlayCursor_->setCharHeight(18);
+        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
+        this->consoleOverlayCursor_->setLeft(7);
+        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
+        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
+
+        // create noise
+        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
+        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
+        this->consoleOverlayNoise_->setPosition(5,0);
+        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
+        // comment following line to disable noise
+        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
+
+        this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
+
+        // move overlay "above" the top edge of the screen
+        // we take -1.2 because the border makes the panel bigger
+        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
+
+        Shell::getInstance().addOutputLevel(true);
+
+        COUT(4) << "Info: InGameConsole initialized" << std::endl;
     }
 
@@ -491,5 +480,5 @@
         {
             this->bActive_ = true;
-            InputManager::requestEnterState("console");
+            InputManager::getInstance().requestEnterState("console");
             Shell::getInstance().registerListener(this);
 
@@ -513,5 +502,5 @@
         {
             this->bActive_ = false;
-            InputManager::requestLeaveState("console");
+            InputManager::getInstance().requestLeaveState("console");
             Shell::getInstance().unregisterListener(this);
 
Index: code/branches/gui/src/orxonox/overlays/console/InGameConsole.h
===================================================================
--- code/branches/gui/src/orxonox/overlays/console/InGameConsole.h	(revision 1641)
+++ code/branches/gui/src/orxonox/overlays/console/InGameConsole.h	(revision 1642)
@@ -46,4 +46,7 @@
     {
     public: // functions
+        InGameConsole();
+        ~InGameConsole();
+
         void initialise();
         void destroy();
@@ -52,5 +55,6 @@
         void tick(float dt);
 
-        static InGameConsole& getInstance();
+        static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
+        static InGameConsole* getInstancePtr() { return singletonRef_s; }
 
         static void openConsole();
@@ -58,7 +62,5 @@
 
     private: // functions
-        InGameConsole();
         InGameConsole(const InGameConsole& other) {}
-        ~InGameConsole();
 
         void activate();
@@ -107,4 +109,6 @@
         float noiseSize_;
         char cursorSymbol_;
+
+        static InGameConsole* singletonRef_s;
     };
 }
