Index: /orxonox/branches/textEngine/src/defs/debug.h
===================================================================
--- /orxonox/branches/textEngine/src/defs/debug.h	(revision 3768)
+++ /orxonox/branches/textEngine/src/defs/debug.h	(revision 3769)
@@ -70,5 +70,5 @@
 #define DEBUG_MODULE_PLAYER             3
 #define DEBUG_MODULE_MATH               0
-#define DEBUG_MODULE_FONT               0
+#define DEBUG_MODULE_FONT               4
 
 #define DEBUG_MODULE_NULL_PARENT        0
Index: /orxonox/branches/textEngine/src/lib/graphics/font/text_engine.cc
===================================================================
--- /orxonox/branches/textEngine/src/lib/graphics/font/text_engine.cc	(revision 3768)
+++ /orxonox/branches/textEngine/src/lib/graphics/font/text_engine.cc	(revision 3769)
@@ -31,4 +31,6 @@
 
 #include "graphics_engine.h"
+#include "resource_manager.h"
+
 #include "p_node.h"
 #include "vector.h"
@@ -39,9 +41,16 @@
 /// TEXT ///
 ////////////
-
-Text::Text(void)
-{
-
-}
+Text::Text(Font* font, int type)
+{
+  // initialize this Text
+  this->bindNode = NULL;
+  this->text = NULL;
+  this->texture = 0;
+  this->setType(TEXT_DYNAMIC);
+  this->setPosition(0, 0);
+
+  this->setText(FONT_DEFAULT_TEXT);
+}
+
 
 Text::~Text(void)
@@ -89,4 +98,37 @@
 }
 
+/**
+   \brief sets a new color to the font
+   \param r Red
+   \param g Green
+   \param b Blue
+*/
+void Text::setColor(Uint8 r, Uint8 g, Uint8 b)
+{
+  this->color.r = r;
+  this->color.g = g;
+  this->color.b = b;
+}
+
+/**
+   \brief creates a texture out of the given parameters
+
+   this has to be called every time by the user, to if changes were made.
+*/
+void Text::createTexture(void)
+{
+  SDL_Surface* tmpSurf;
+  if (this->texture)
+    glDeleteTextures(1, &this->texture);
+  tmpSurf = TTF_RenderText_Blended(this->font->font,
+				   this->text,
+				   this->color);
+  if (tmpSurf)
+    this->texture = loadTexture(tmpSurf, &this->texCoord);
+
+  this->posSize.w = tmpSurf->w;
+  this->posSize.h = tmpSurf->h;
+  SDL_FreeSurface(tmpSurf);
+}
 
 /**
@@ -97,5 +139,4 @@
 {
   // storing all the Transformation Matrices.
-
   GLdouble modMat[16];
   GLdouble projMat[16];
@@ -104,5 +145,7 @@
   glGetDoublev(GL_MODELVIEW_MATRIX, modMat);
   glGetIntegerv(GL_VIEWPORT, viewPort);
-//    this->enter2DMode();
+
+  printf("rendering some Text\n");
+  //enter2DMode();
 
 
@@ -168,5 +211,5 @@
 	}
     }
-  //  this->leave2DMode();
+  //leave2DMode();
 }
 
@@ -186,32 +229,17 @@
 Font::Font(const char* fontFile, unsigned int fontSize, Uint8 r, Uint8 g, Uint8 b)
 {
-   if (!TTF_WasInit())
-    TextEngine::enableFonts();
-
   // setting default values.
   this->font = NULL;
   this->fontFile = NULL;
   this->glyphArray = NULL;
-  this->fastTextureID = 0;
-
-  this->currentText = new Text;
-
-  this->currentText->bindNode = NULL;
-  this->currentText->text = NULL;
-  this->currentText->texture = 0;
+  this->fastTextureID = 0;  
   
   this->setSize(fontSize);
-  this->setStyle(TTF_STYLE_NORMAL);
+  this->setStyle("c");//TTF_STYLE_NORMAL);
+
   this->setFont(fontFile);
 
 
-  this->currentText->setType(TEXT_DYNAMIC);
-  this->currentText->setPosition(0, 0);
-
-  this->currentText->setText(FONT_DEFAULT_TEXT);
-  
-  this->setColor(r, g, b);
-
-  this->createTexture();
+  this->setFastColor(r, g, b);
 
   this->fastTextureID = this->createFastTexture();
@@ -223,6 +251,7 @@
 Font::~Font(void)
 {
-  delete this->currentText;
-
+  // deleting the List of all Texts
+
+  // deleting all Glyphs
   if (this->glyphArray)
     {
@@ -232,4 +261,5 @@
     }
 
+  // erease this font out of the memory.
   if (this->font)
     TTF_CloseFont(this->font);
@@ -303,32 +333,10 @@
    \param b Blue
 */
-void Font::setColor(Uint8 r, Uint8 g, Uint8 b)
-{
-  this->currentText->color.r = r;
-  this->currentText->color.g = g;
-  this->currentText->color.b = b;
-}
-
-/**
-   \brief creates a texture out of the given parameters
-
-   this has to be called every time by the user, to if changes were made.
-*/
-void Font::createTexture(void)
-{
-  SDL_Surface* tmpSurf;
-  if (this->currentText->texture)
-    glDeleteTextures(1, &this->currentText->texture);
-  tmpSurf = TTF_RenderText_Blended(this->font,
-				   this->currentText->text,
-				   this->currentText->color);
-  if (tmpSurf)
-    this->currentText->texture = loadTexture(tmpSurf, &this->currentText->texCoord);
-
-  this->currentText->posSize.w = tmpSurf->w;
-  this->currentText->posSize.h = tmpSurf->h;
-  SDL_FreeSurface(tmpSurf);
-}
-
+void Font::setFastColor(Uint8 r, Uint8 g, Uint8 b)
+{
+  this->fastColor.r = r;
+  this->fastColor.g = g;
+  this->fastColor.b = b;
+}
 
 /**
@@ -506,6 +514,5 @@
 	    }
 	  // reading in the new Glyph
-	  //glyphSurf = TTF_RenderGlyph_Shaded(this->font, i, this->currentText->color, tmpColor);
-	  glyphSurf = TTF_RenderGlyph_Blended(this->font, i, this->currentText->color);
+	  glyphSurf = TTF_RenderGlyph_Blended(this->font, i, this->fastColor);
 	  if( glyphSurf ) 
 	    {
@@ -569,4 +576,111 @@
 
 /**
+   \brief stores Glyph Metrics in an Array.
+   \param from The Glyph to start from.
+   \param count The number of Glyphs to start From.
+*/
+void Font::initGlyphs(Uint16 from, Uint16 count)
+{
+  /* initialize the Array, and set all its entries to NULL
+   *  only if the Glyph-array has not been initialized
+   */
+  if (!this->glyphArray)
+    {
+      this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
+      for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
+	this->glyphArray[i] = NULL;
+    }
+  
+  Uint16 lastGlyph = from + count;
+  
+  for (int i = from; i <= lastGlyph; i++)
+    {
+      // setting up all the Glyphs we like.
+      glyphArray[i] = getGlyphMetrics(i);
+    }
+  return;
+}
+
+/**
+   \returns the optimal size to use as the texture size
+
+   \todo: this algorithm can be a lot more faster, althought it does 
+   not really matter within the init-context, and 128 glyphs.
+
+   This function searches for a 2^n sizes texture-size, this is for 
+   openGL-version < 1.2 compatibility. and because it is realy easy like this.
+*/
+int Font::findOptimalFastTextureSize(void)
+{
+  int i;
+  int x,y; // the counters
+  int maxLineHeight;
+  int size = 32;      // starting Value, we have to start somewhere 32 seems reasonable.
+  bool sizeOK = false;
+  Glyph* tmpGlyph;
+
+  while (!sizeOK)
+    {
+      x = 0; y = 0;
+      maxLineHeight = 0;
+      for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
+	{
+	  if(tmpGlyph = this->glyphArray[i])
+	    {
+	      // getting the height of the highest Glyph in the Line.
+	      if (tmpGlyph->height > maxLineHeight)
+		maxLineHeight = tmpGlyph->height;
+
+	      if (x + tmpGlyph->width > size)
+		{
+		  x = 0;
+		  y = y + maxLineHeight;
+		  maxLineHeight = 0;
+		}
+	      if (y + maxLineHeight + 1 > size)
+		break;
+	      x += tmpGlyph->width + 1;
+
+	    }
+	}
+      if (i == FONT_HIGHEST_KNOWN_CHAR)
+	sizeOK = true;
+      else
+	size *= 2;
+    }
+  return size;
+  
+}
+
+
+/**
+   \brief a simple function to get some interesting information about this class
+*/
+void Font::debug(void)
+{
+
+  // print the loaded font's style
+  int style;
+  style=TTF_GetFontStyle(this->font);
+  PRINTF(0)("The font style is:");
+  if(style==TTF_STYLE_NORMAL)
+    PRINTF(0)(" normal");
+  else {
+    if(style&TTF_STYLE_BOLD)
+      PRINTF(0)(" bold");
+    if(style&TTF_STYLE_ITALIC)
+      PRINTF(0)(" italic");
+    if(style&TTF_STYLE_UNDERLINE)
+      PRINTF(0)(" underline");
+  }
+  PRINTF(0)("\n");
+
+
+}
+
+////////////
+/// UTIL ///
+////////////
+/**
    \brief Loads a Font from an SDL_surface into a texture.
    \param surface The surface to make the texture of
@@ -574,5 +688,5 @@
    \returns the ID of the texture
 */
-GLuint Font::loadTexture(SDL_Surface *surface, TexCoord* texCoord)
+GLuint loadTexture(SDL_Surface *surface, TexCoord* texCoord)
 {
   GLuint texture;
@@ -650,87 +764,9 @@
 
 /**
-   \brief stores Glyph Metrics in an Array.
-   \param from The Glyph to start from.
-   \param count The number of Glyphs to start From.
-*/
-void Font::initGlyphs(Uint16 from, Uint16 count)
-{
-  /* initialize the Array, and set all its entries to NULL
-   *  only if the Glyph-array has not been initialized
-   */
-  if (!this->glyphArray)
-    {
-      this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
-      for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
-	this->glyphArray[i] = NULL;
-    }
-  
-  Uint16 lastGlyph = from + count;
-  
-  for (int i = from; i <= lastGlyph; i++)
-    {
-      // setting up all the Glyphs we like.
-      glyphArray[i] = getGlyphMetrics(i);
-    }
-  return;
-}
-
-/**
-   \returns the optimal size to use as the texture size
-
-   \todo: this algorithm can be a lot more faster, althought it does 
-   not really matter within the init-context, and 128 glyphs.
-
-   This function searches for a 2^n sizes texture-size, this is for 
-   openGL-version < 1.2 compatibility. and because it is realy easy like this.
-*/
-int Font::findOptimalFastTextureSize(void)
-{
-  int i;
-  int x,y; // the counters
-  int maxLineHeight;
-  int size = 32;      // starting Value, we have to start somewhere 32 seems reasonable.
-  bool sizeOK = false;
-  Glyph* tmpGlyph;
-
-  while (!sizeOK)
-    {
-      x = 0; y = 0;
-      maxLineHeight = 0;
-      for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
-	{
-	  if(tmpGlyph = this->glyphArray[i])
-	    {
-	      // getting the height of the highest Glyph in the Line.
-	      if (tmpGlyph->height > maxLineHeight)
-		maxLineHeight = tmpGlyph->height;
-
-	      if (x + tmpGlyph->width > size)
-		{
-		  x = 0;
-		  y = y + maxLineHeight;
-		  maxLineHeight = 0;
-		}
-	      if (y + maxLineHeight + 1 > size)
-		break;
-	      x += tmpGlyph->width + 1;
-
-	    }
-	}
-      if (i == FONT_HIGHEST_KNOWN_CHAR)
-	sizeOK = true;
-      else
-	size *= 2;
-    }
-  return size;
-  
-}
-
-/**
    \brief Quick utility function for texture creation 
    \param input an integer
    \returns the next bigger 2^n-integer than input
 */
-int Font::powerOfTwo(int input)
+int powerOfTwo(int input)
 {
   int value = 1;
@@ -744,34 +780,4 @@
 
 
-/**
-   \brief a simple function to get some interesting information about this class
-*/
-void Font::debug(void)
-{
-
-  // print the loaded font's style
-  int style;
-  style=TTF_GetFontStyle(this->font);
-  PRINTF(0)("The font style is:");
-  if(style==TTF_STYLE_NORMAL)
-    PRINTF(0)(" normal");
-  else {
-    if(style&TTF_STYLE_BOLD)
-      PRINTF(0)(" bold");
-    if(style&TTF_STYLE_ITALIC)
-      PRINTF(0)(" italic");
-    if(style&TTF_STYLE_UNDERLINE)
-      PRINTF(0)(" underline");
-  }
-  PRINTF(0)("\n");
-
-
-}
-
-
-
-
-
-
 
 
@@ -786,5 +792,7 @@
 {
    this->setClassName ("TextEngine");
-
+   this->enableFonts();
+
+   this->textList = new tList<Text>;
 }
 
@@ -810,4 +818,8 @@
 TextEngine::~TextEngine () 
 {
+  this->disableFonts();
+  
+  delete this->textList;
+
   TextEngine::singletonRef = NULL;
 
@@ -842,4 +854,36 @@
   else
     PRINTF(4)("Fonts were not initialized.\n");
+}
+
+/**
+   \brief creates a new Text with a certain font.
+   \see Font::Font
+   \see Text::Text
+*/
+Text* TextEngine::createText(const char* fontFile, unsigned int fontSize, Uint8 r, Uint8 g, Uint8 b)
+{
+  Font* tmpFont;
+  Text* newText;
+
+  tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME);
+  if (!tmpFont)
+    {
+      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
+      return NULL;
+    }
+
+  newText = new Text(tmpFont, TEXT_DYNAMIC);
+}
+
+void TextEngine::draw(void)
+{
+  tIterator<Text>* textIterator = textList->getIterator();
+  Text* text = textIterator->nextElement();
+  while( text != NULL)
+    {
+      text->draw();
+      text = textIterator->nextElement();
+    }
+  delete textIterator;
 }
 
Index: /orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h
===================================================================
--- /orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h	(revision 3768)
+++ /orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h	(revision 3769)
@@ -93,5 +93,5 @@
 {
  public:
-  Text(void);
+  Text(Font* font, int type = TEXT_DYNAMIC);
   ~Text(void);
 
@@ -101,4 +101,13 @@
   void setText(const char* text);
   void setPosition(int x, int y);
+
+  // Static Text
+  void setColor(Uint8 r, Uint8 g, Uint8 b);
+  void setStyle(char* renderStyle);
+  void createTexture();
+
+  // Dynamic Text
+  
+
 
   virtual void draw(void);
@@ -113,5 +122,5 @@
   GLuint texture;                //!< A GL-texture to hold the text
   TexCoord texCoord;             //!< Texture-coordinates \todo fix this to have a struct
-  SDL_Rect posSize;          //!< An SDL-Rectangle representing the position and size of the Text on the screen.
+  SDL_Rect posSize;              //!< An SDL-Rectangle representing the position and size of the Text on the screen.
   
   PNode* bindNode;               //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
@@ -124,4 +133,5 @@
 class Font
 {
+  friend class Text;
  public:
   Font(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE,
@@ -132,10 +142,9 @@
   bool setFont(const char* fontFile);
   void setSize(unsigned int fontSize);
-  void setColor(Uint8 r, Uint8 g, Uint8 b);
+  void setFastColor(Uint8 r, Uint8 g, Uint8 b);
   void setStyle(char* renderStyle);
 
   inline Glyph** getGlyphArray(void) {return glyphArray;}
   inline GLuint getFastTextureID(void) {return fastTextureID;}
-  void createTexture(void);
   
   
@@ -148,11 +157,11 @@
   char* fontFile;                   //!< The fontfile from whitch the font was loaded.
   unsigned int fontSize;            //!< The size of the font in pixels. each Font has one size.
-  int renderStyle;               //!< The Renderstyle
+  int renderStyle;                  //!< The Renderstyle
   
   Glyph** glyphArray;               //!< An Array of all the Glyphs stored in the Array of Glyphs.
   GLuint fastTextureID;             //!< The fast textureID.
+  SDL_Color fastColor;              //!< A Color for the fast Texture.
 
   tList<Text>* textList;
-  Text* currentText;
 
   int getMaxHeight(void);
@@ -166,13 +175,13 @@
 
   GLuint createFastTexture();
-  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
 
   void initGlyphs(Uint16 from, Uint16 count);
   int findOptimalFastTextureSize(void);
-  static int powerOfTwo(int input);
 
   void debug(void);
 
 };
+GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
+int powerOfTwo(int input);
 
 
@@ -187,4 +196,16 @@
   virtual ~TextEngine(void);
 
+  Text* createText(const char* fontFile,
+		   unsigned int fontSize = FONT_DEFAULT_SIZE,
+		   Uint8 r = FONT_DEFAULT_COLOR_R,
+		   Uint8 g = FONT_DEFAULT_COLOR_G,
+		   Uint8 b = FONT_DEFAULT_COLOR_B);
+
+  void draw(void);
+
+ private:
+  TextEngine(void);
+  static TextEngine* singletonRef;
+
   // general
   static void enableFonts(void);
@@ -192,9 +213,7 @@
   static bool checkVersion(void);
 
- private:
-  TextEngine(void);
-  static TextEngine* singletonRef;
-
-  tList<Font>* fontList;
+
+  //  tList<Font>* fontList;
+  tList<Text>* textList;
 
 };
Index: /orxonox/branches/textEngine/src/lib/util/resource_manager.cc
===================================================================
--- /orxonox/branches/textEngine/src/lib/util/resource_manager.cc	(revision 3768)
+++ /orxonox/branches/textEngine/src/lib/util/resource_manager.cc	(revision 3769)
@@ -22,4 +22,5 @@
 #include "primitive_model.h"
 #include "texture.h"
+#include "text_engine.h"
 
 #include "list.h"
@@ -158,4 +159,6 @@
            !strcmp(fileName, "cone"))
     tmpType = PRIM;
+  else if (!strncmp(fileName+(strlen(fileName)-4), ".ttf", 4))
+    tmpType = TTF;
   else 
     tmpType = IMAGE;
@@ -220,4 +223,10 @@
 	  else if (!strcmp(tmpResource->name, "cone"))
 	    tmpResource->pointer = new PrimitiveModel(CONE);
+	  break;
+	case TTF:
+	  if(isFile(fullName))
+	    tmpResource->pointer = new Font(fullName);
+	  else
+	    PRINTF(2)("Sorry, %s does not exist. Not loading Font\n", fullName);
 	  break;
 	case IMAGE:
Index: /orxonox/branches/textEngine/src/lib/util/resource_manager.h
===================================================================
--- /orxonox/branches/textEngine/src/lib/util/resource_manager.h	(revision 3768)
+++ /orxonox/branches/textEngine/src/lib/util/resource_manager.h	(revision 3769)
@@ -19,5 +19,5 @@
 
 //! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support
-enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, IMAGE};
+enum ResourceType {OBJ, PRIM, WAV, MP3, OGG, TTF, IMAGE};
 //! An enumerator for different UNLOAD-types. 
 /**
@@ -49,4 +49,6 @@
 
    It does it by looking, if a desired file has already been loaded.
+
+   \todo loading also dependant by parameters.
 */
 class ResourceManager : public BaseObject 
Index: /orxonox/branches/textEngine/src/orxonox.cc
===================================================================
--- /orxonox/branches/textEngine/src/orxonox.cc	(revision 3768)
+++ /orxonox/branches/textEngine/src/orxonox.cc	(revision 3769)
@@ -59,5 +59,5 @@
   delete GraphicsEngine::getInstance(); // deleting the Graphics
   delete ResourceManager::getInstance(); // deletes the Resource Manager
-  TextEngine::disableFonts();
+  delete TextEngine::getInstance();
 }
 
@@ -170,5 +170,5 @@
   return 0;
   PRINT(3)("initializing TextEngine\n");
-  TextEngine::enableFonts();
+  TextEngine::getInstance();
 }
 
Index: /orxonox/branches/textEngine/src/story_entities/world.cc
===================================================================
--- /orxonox/branches/textEngine/src/story_entities/world.cc	(revision 3768)
+++ /orxonox/branches/textEngine/src/story_entities/world.cc	(revision 3769)
@@ -32,4 +32,5 @@
 #include "terrain.h"
 #include "light.h"
+#include "text_engine.h"
 
 #include "track_manager.h"
@@ -39,6 +40,4 @@
 #include "glmenu_imagescreen.h"
 #include "list.h"
-
-
 
 using namespace std;
@@ -350,4 +349,5 @@
 	    trackManager->condition(2, LEFTRIGHT, this->localPlayer);
 	    this->glmis->step();
+	    this->testText = TextEngine::getInstance()->createText("fonts/earth.ttf");
 
 	    break;
@@ -589,4 +589,5 @@
   skySphere->draw();
 
+  TextEngine::getInstance()->draw();
   lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes //
 }
Index: /orxonox/branches/textEngine/src/story_entities/world.h
===================================================================
--- /orxonox/branches/textEngine/src/story_entities/world.h	(revision 3768)
+++ /orxonox/branches/textEngine/src/story_entities/world.h	(revision 3769)
@@ -23,4 +23,5 @@
 class Terrain;
 class GarbageCollector;
+class Text;
 
 //! The game world Interface
@@ -94,4 +95,5 @@
   bool bPause;                  //!< pause mode
 
+  Text* testText;               //!< A text to Test the TextEngine;
   GLMenuImageScreen* glmis;     //!< The Level-Loader Display
 
