Index: /trunk/src/lib/graphics/text_engine/font.cc
===================================================================
--- /trunk/src/lib/graphics/text_engine/font.cc	(revision 8763)
+++ /trunk/src/lib/graphics/text_engine/font.cc	(revision 8764)
@@ -31,5 +31,5 @@
 
 Font::Font()
-  : data(Font::defaultFontData)
+    : data(Font::defaultFontData)
 {
   this->init();
@@ -43,5 +43,5 @@
  */
 Font::Font(const std::string& fontFile, unsigned int renderSize)
-  : data(Font::defaultFontData)
+    : data(Font::defaultFontData)
 {
   this->init();
@@ -57,5 +57,5 @@
  */
 Font::Font(const std::string& imageFile)
-  : data(Font::defaultFontData)
+    : data(Font::defaultFontData)
 {
   this->init();
@@ -82,5 +82,5 @@
  */
 Font::Font(char** xpmArray)
-  : data(Font::defaultFontData)
+    : data(Font::defaultFontData)
 {
   this->init();
@@ -133,5 +133,5 @@
   if (Font::defaultFontData.get() == NULL)
   {
-     Font::initDefaultFont();
+    Font::initDefaultFont();
     this->data = Font::defaultFontData;
   }
@@ -161,27 +161,10 @@
 {
   this->data = FontDataPointer (new FontData());
-
-  this->setName(fontFile);
-  this->data->fontTTF = TTF_OpenFont(fontFile.c_str(), renderSize);
-  this->data->renderSize = renderSize;
-
-  if(this->data->fontTTF != NULL)
-  {
-    this->setStyle("c");
-    if (this->createFastTexture())
-      return true;
-    else
-    {
-      this->data = Font::defaultFontData;
-      return false;
-    }
-  }
-  else
-  {
-    PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
+  bool retVal = this->data->loadFontFromTTF(fontFile, renderSize);
+  if (!retVal)
     this->data = Font::defaultFontData;
-    return false;
-  }
-
+
+  this->setTexture(this->data->texData);
+  return retVal;
 }
 
@@ -192,52 +175,11 @@
 bool Font::loadFontFromSDL_Surface(SDL_Surface* surface)
 {
-  if(surface == NULL)
-    return false;
-
   this->data = FontDataPointer (new FontData());
-  // loading to a texture.
-
-  bool hasAlpha;
-  SDL_Surface* newSurf = Texture::prepareSurface(surface, hasAlpha);
-  if (newSurf != NULL)
-  {
-    this->data->texData->setSurface(newSurf);
-    this->data->texData->setAlpha(hasAlpha);
-    this->setTexture(Texture::loadTexToGL(newSurf));
-  }
-  else
-  {
+  bool retVal = this->data->loadFontFromSDL_Surface(surface);
+  if (!retVal)
     this->data = Font::defaultFontData;
-    return false;
-  }
-
-  // initializing the Glyphs.
-  if (this->data->glyphArray == NULL)
-  {
-    float cx,cy;
-    Glyph* tmpGlyph;
-    this->data->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
-    for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
-    {
-      tmpGlyph = this->data->glyphArray[i] = new Glyph;
-      cx=(float)(i%16)/16.0f;                  // X Position Of Current Character
-      cy=(float)(i/16)/16.0f;                  // Y Position Of Current Character
-
-      tmpGlyph->texCoord[0] = cx;
-      tmpGlyph->texCoord[1] = cx+0.0625f;
-      tmpGlyph->texCoord[2] = cy;
-      tmpGlyph->texCoord[3] = cy+0.0625f;
-      tmpGlyph->minX = 0.0f;
-      tmpGlyph->maxX = 1.0f;
-      tmpGlyph->minY = 0.0f;
-      tmpGlyph->maxY = 1.0f;
-      tmpGlyph->width = 1.0f;
-      tmpGlyph->advance = 1.0f;
-      tmpGlyph->bearingX = 0.0f;
-      tmpGlyph->bearingY = 0.0f;
-      tmpGlyph->height = 1.0f;
-    }
-  }
-  return true;
+
+  this->setTexture(this->data->texData);
+  return retVal;
 }
 
@@ -250,20 +192,13 @@
 void Font::setStyle(const std::string& renderStyle)
 {
-  this->data->renderStyle = TTF_STYLE_NORMAL;
-
-  for (unsigned int i = 0; i < renderStyle.size(); i++)
-  {
-    if (renderStyle[i] == 'b')
-      this->data->renderStyle |= TTF_STYLE_BOLD;
-    else if (renderStyle[i] == 'i')
-      this->data->renderStyle |= TTF_STYLE_ITALIC;
-    else if (renderStyle[i] == 'u')
-      this->data->renderStyle |= TTF_STYLE_UNDERLINE;
-  }
-  if (likely(this->data->fontTTF != NULL))
-    TTF_SetFontStyle(this->data->fontTTF, this->data->renderStyle);
-  //  else
-  //    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
-}
+  this->data->setStyle(renderStyle);
+}
+
+
+void Font::setTexture(const TextureDataPointer& texDataPointer)
+{
+  this->setDiffuseMap(texDataPointer);
+}
+
 
 /**
@@ -327,278 +262,4 @@
 
 
-/**
- * @returns the maximum height of the Font, if the font was initialized, 0 otherwise
- */
-int Font::getMaxHeight() const
-{
-  if (likely (this->data->fontTTF != NULL))
-    return TTF_FontHeight(this->data->fontTTF);
-  else
-    return 1;
-}
-
-/**
- * @returns the maximum ascent of the Font, if the font was initialized, 0 otherwise
- *
- * the ascent is the pixels of the font above the baseline
- */
-int Font::getMaxAscent() const
-{
-  if (likely(this->data->fontTTF != NULL))
-    return TTF_FontAscent(this->data->fontTTF);
-  else
-    return 0;
-}
-
-/**
- * @returns the maximum descent of the Font, if the font was initialized, 0 otherwise
- *
- * the descent is the pixels of the font below the baseline
- */
-int Font::getMaxDescent() const
-{
-  if (likely(this->data->fontTTF != NULL))
-    return TTF_FontDescent(this->data->fontTTF);
-  else
-    return 0;
-}
-
-/**
- * @param glyph: The Glyph to set the Parameters to.
- * @param character: The character to get info about.
- * @returns a Glyph struct of a character. This Glyph is a pointer,
- * and MUST be deleted by the user..
- *
- * This only works for horizontal fonts. see
- * http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
- * for more info about vertical Fonts
- */
-bool Font::getGlyphMetrics(Glyph* glyph, Uint16 character)
-{
-  glyph->character = character;
-  if (likely (this->data->fontTTF!= NULL))
-  {
-    int miX, maX, miY, maY, adv;
-    if (TTF_GlyphMetrics(this->data->fontTTF, glyph->character,
-                     &miX, &maX,
-                     &miY, &maY,
-                     &adv) == -1)
-      return false;
-    glyph->minX = (float)miX / (float)this->data->renderSize;
-    glyph->maxX = (float)maX / (float)this->data->renderSize;
-    glyph->minY = (float)miY / (float)this->data->renderSize;
-    glyph->maxY = (float)maY / (float)this->data->renderSize;
-    glyph->advance = (float)adv / (float)this->data->renderSize;
-
-    // Calculate the Rest.
-    glyph->height = glyph->maxY - glyph->minY;
-    glyph->width = glyph->maxX - glyph->minX;
-    glyph->bearingX = (glyph->advance - glyph->width) / 2;
-    glyph->bearingY = glyph->maxY;
-
-    //printf("%c:: %d %d %d %d %d\n", character, miX, maX, miY, maY, adv);
-
-    return true;
-  }
-  return false;
-}
-
-/**
- * @brief creates a Fast-Texture of this Font
- */
-bool Font::createFastTexture()
-{
-  /* interesting GLYPHS:
-  *  32: space
-  *  33-47: Special Characters.
-  *  48-57: 0-9
-  *  58-63: some more special chars (minor)
-  *  65-90: A-Z
-  *  97-122: a-z
-  */
-  int numberOfGlyphs = 91;
-
-  this->initGlyphs(32, numberOfGlyphs);
-  //  this->data->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
-
-  int rectSize = this->findOptimalFastTextureSize();
-
-  // setting default values. (maybe not needed afterwards)
-  SDL_Color tmpColor;  tmpColor.r = tmpColor.g = tmpColor.b = 0;
-  // Surface definition.
-  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
-  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_HWSURFACE,
-                          rectSize, rectSize,
-                          32,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
-                          0x000000FF,
-                          0x0000FF00,
-                          0x00FF0000,
-                          0xFF000000
-#else
-                          0xFF000000,
-                          0x00FF0000,
-                          0x0000FF00,
-                          0x000000FF
-#endif
-                                              );
-  tmpRect.x = 0; tmpRect.y = 0; tmpRect.w = tmpSurf->w; tmpRect.h = tmpSurf->h;
-  SDL_SetClipRect(tmpSurf, &tmpRect);
-  int maxLineHeight = this->getMaxHeight();
-
-  // all the interessting Glyphs
-  for (int i = 0; i < 128; i++)
-  {
-    SDL_Surface* glyphSurf = NULL;
-    Glyph* tmpGlyph;
-
-    if (tmpGlyph = this->data->glyphArray[i])
-    {
-      if (tmpGlyph->height*this->data->renderSize > maxLineHeight)
-        maxLineHeight = (int)(tmpGlyph->height*this->data->renderSize);
-
-      if (tmpRect.x+tmpGlyph->advance*this->data->renderSize > tmpSurf->w)
-      {
-        tmpRect.x = 0;
-        tmpRect.y = tmpRect.y + maxLineHeight;
-      }
-      if (tmpRect.y + maxLineHeight > tmpSurf->h)
-      {
-        PRINTF(1)("Protection, so font cannot write over the boundraries (!!this should not heappen!!)\n");
-        break;
-      }
-      // reading in the new Glyph
-      if (likely(this->data->fontTTF != NULL))
-      {
-        SDL_Color white = {255, 255, 255};
-        glyphSurf = TTF_RenderGlyph_Blended(this->data->fontTTF, i, white);
-      }
-      if( glyphSurf != NULL )
-      {
-        SDL_SetAlpha(glyphSurf, 0, 0);
-        int tmpY = tmpRect.y;
-        tmpRect.y += this->getMaxAscent()-(int)((float)tmpGlyph->bearingY*this->data->renderSize);
-        SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect);
-        tmpRect.y = tmpY;
-
-        tmpGlyph->texCoord[0] = (float)((float)tmpRect.x )/(float)tmpSurf->w;
-        tmpGlyph->texCoord[1] = (float)((float)tmpRect.x + tmpGlyph->width*(float)this->data->renderSize)/(float)tmpSurf->w;
-        tmpGlyph->texCoord[2] = (float)(tmpRect.y)/(float)tmpSurf->w;
-        tmpGlyph->texCoord[3] = (float)((float)tmpRect.y+(float)this->getMaxHeight())/(float)tmpSurf->w;
-        SDL_FreeSurface(glyphSurf);
-        tmpRect.x += (int)(tmpGlyph->width * this->data->renderSize) + 1;
-      }
-    }
-  }
-  // outputting the GLYPH-table
-//       char outName[1024];
-//       sprintf( outName, "%s-glyphs.bmp", this->getName());
-//       SDL_SaveBMP(tmpSurf, outName);
-  this->data->texData->setAlpha(true);
-  if (this->data->texData->setSurface(tmpSurf))
-    this->setTexture(Texture::loadTexToGL(tmpSurf));
-  return true;
-}
-
-/**
- * @brief the Internal implementation of setting up the Texture.
- * @param texture the Texture to load.
- * @returns true on success, false otherwise.
- */
-bool Font::setTexture(GLuint texture)
-{
-  bool retVal = this->data->texData->setTexture(texture);
-  this->setDiffuseMap(data->texData, 0);
-  printf("this->texture %d\n", texture);
-  //printf(this->getT)
-  this->debug();
-  return retVal;
-};
-
-/**
- * @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->data->glyphArray)
-  {
-    this->data->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
-    for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
-      this->data->glyphArray[i] = NULL;
-  }
-
-  Uint16 lastGlyph = from + count;
-
-  for (int i = from; i <= lastGlyph; i++)
-  {
-    // setting up all the Glyphs we like.
-    Glyph* newGlyph = new Glyph;
-    if (getGlyphMetrics(newGlyph, i))
-      data->glyphArray[i] = newGlyph;
-    else
-    {
-      delete newGlyph;
-      data->glyphArray[i] = NULL;
-    }
-  }
-  return;
-}
-
-/**
- * @returns the optimal size to use as the texture size
- *
- * @todo: this algorithm can be a lot 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()
-{
-  if (this->data->glyphArray == NULL)
-    return 0;
-
-  unsigned int i;
-  unsigned int x,y; // the counters
-  int maxLineHeight = this->getMaxHeight();
-  unsigned int size = 32;  // starting Value, we have to start somewhere 32 seems reasonable. (take any small enough 2^i number)
-  bool sizeOK = false;
-  Glyph* tmpGlyph;
-
-  while (!sizeOK)
-  {
-    x = 0; y = 0;
-    for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
-    {
-      if((tmpGlyph = this->data->glyphArray[i]) != NULL)
-      {
-        // getting the height of the highest Glyph in the Line.
-        if (tmpGlyph->height*this->data->renderSize > maxLineHeight)
-          maxLineHeight = (int)(tmpGlyph->height*this->data->renderSize);
-
-        if (x + tmpGlyph->advance*this->data->renderSize > size)
-        {
-          x = 0;
-          y = y + maxLineHeight;
-          //maxLineHeight = 0;
-        }
-        if (y + maxLineHeight + 1 > size)
-          break;
-        x += (int)(tmpGlyph->advance*this->data->renderSize)+1;
-
-      }
-    }
-    if (i >= FONT_HIGHEST_KNOWN_CHAR-1 || size > 8192)
-      sizeOK = true;
-    else
-      size *= 2;
-  }
-  return size;
-}
 
 
Index: /trunk/src/lib/graphics/text_engine/font.h
===================================================================
--- /trunk/src/lib/graphics/text_engine/font.h	(revision 8763)
+++ /trunk/src/lib/graphics/text_engine/font.h	(revision 8764)
@@ -32,5 +32,4 @@
   bool operator==(const Font& font) const { return this->data == font.data; };
 
-
   /// LOADING new Fonts
   bool loadFontFromTTF(const std::string& fontFile, unsigned int renderSize);
@@ -44,7 +43,8 @@
   inline TTF_Font* getTTF() const { return this->data->getTTF(); };
 
-  int getMaxHeight() const;
-  int getMaxAscent() const;
-  int getMaxDescent() const;
+  inline int getMaxHeight() const { return data->getMaxHeight(); };
+  inline int getMaxAscent() const { return data->getMaxAscent(); };
+  inline int getMaxDescent() const { return data->getMaxDescent(); };
+
 
   void createAsciiImage(const std::string& fileName, unsigned int size) const;
@@ -54,13 +54,7 @@
 private:
   void init();
-  void initGlyphs(Uint16 from, Uint16 count);
-  bool getGlyphMetrics(Glyph* glyph, Uint16 character);
   static void initDefaultFont();
 
-  int findOptimalFastTextureSize();
-  bool createFastTexture();
-
-  bool setTexture(GLuint texture);
-
+  void setTexture(const TextureDataPointer& texDataPointer);
 
 private:
Index: /trunk/src/lib/graphics/text_engine/font_data.cc
===================================================================
--- /trunk/src/lib/graphics/text_engine/font_data.cc	(revision 8763)
+++ /trunk/src/lib/graphics/text_engine/font_data.cc	(revision 8764)
@@ -21,5 +21,6 @@
 #include "compiler.h"
 
-#include "sdlincl.h"
+#include "texture.h"
+
 
 /**
@@ -65,3 +66,375 @@
 }
 
-
+/**
+ * @returns the maximum height of the Font, if the font was initialized, 0 otherwise
+ */
+int FontData::getMaxHeight() const
+{
+  if (likely (this->fontTTF != NULL))
+    return TTF_FontHeight(this->fontTTF);
+  else
+    return 1;
+}
+
+/**
+ * @returns the maximum ascent of the Font, if the font was initialized, 0 otherwise
+ *
+ * the ascent is the pixels of the font above the baseline
+ */
+int FontData::getMaxAscent() const
+{
+  if (likely(this->fontTTF != NULL))
+    return TTF_FontAscent(this->fontTTF);
+  else
+    return 0;
+}
+
+/**
+ * @returns the maximum descent of the Font, if the font was initialized, 0 otherwise
+ *
+ * the descent is the pixels of the font below the baseline
+ */
+int FontData::getMaxDescent() const
+{
+  if (likely(this->fontTTF != NULL))
+    return TTF_FontDescent(this->fontTTF);
+  else
+    return 0;
+}
+
+
+
+/**
+ * @brief sets The Font.
+ * @param fontFile The file containing the font.
+ * @returns true if loaded, false if something went wrong, or if a font was loaded before.
+ */
+bool FontData::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize)
+{
+  //this->setName(fontFile);
+  this->fontTTF = TTF_OpenFont(fontFile.c_str(), renderSize);
+  this->renderSize = renderSize;
+
+  if(this->fontTTF != NULL)
+  {
+    this->setStyle("c");
+    if (this->createFastTexture())
+      return true;
+    else
+    {
+      return false;
+    }
+  }
+  else
+  {
+    PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
+    return false;
+  }
+
+}
+
+
+
+/**
+ * @brief loads a font From an XPM-array.
+ * @param xpmArray the array of the XPM to load the font from.
+ */
+bool FontData::loadFontFromSDL_Surface(SDL_Surface* surface)
+{
+  if(surface == NULL)
+    return false;
+
+
+  bool hasAlpha;
+  SDL_Surface* newSurf = Texture::prepareSurface(surface, hasAlpha);
+  if (newSurf != NULL)
+  {
+    this->texData->setSurface(newSurf);
+    this->texData->setAlpha(hasAlpha);
+    this->texData->setTexture(Texture::loadTexToGL(newSurf));
+  }
+  else
+  {
+    return false;
+  }
+
+  // initializing the Glyphs.
+  if (this->glyphArray == NULL)
+  {
+    float cx,cy;
+    Glyph* tmpGlyph;
+    this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
+    for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
+    {
+      tmpGlyph = this->glyphArray[i] = new Glyph;
+      cx=(float)(i%16)/16.0f;                  // X Position Of Current Character
+      cy=(float)(i/16)/16.0f;                  // Y Position Of Current Character
+
+      tmpGlyph->texCoord[0] = cx;
+      tmpGlyph->texCoord[1] = cx+0.0625f;
+      tmpGlyph->texCoord[2] = cy;
+      tmpGlyph->texCoord[3] = cy+0.0625f;
+      tmpGlyph->minX = 0.0f;
+      tmpGlyph->maxX = 1.0f;
+      tmpGlyph->minY = 0.0f;
+      tmpGlyph->maxY = 1.0f;
+      tmpGlyph->width = 1.0f;
+      tmpGlyph->advance = 1.0f;
+      tmpGlyph->bearingX = 0.0f;
+      tmpGlyph->bearingY = 0.0f;
+      tmpGlyph->height = 1.0f;
+    }
+  }
+  return true;
+}
+
+/**
+ * @brief sets a specific data->renderStyle
+ * @param data->renderStyle the Style to render: a string (char-array) containing:
+ *   i: italic, b: bold, u, underline
+ */
+void FontData::setStyle(const std::string& renderStyle)
+{
+  this->renderStyle = TTF_STYLE_NORMAL;
+
+  for (unsigned int i = 0; i < renderStyle.size(); i++)
+  {
+    if (renderStyle[i] == 'b')
+      this->renderStyle |= TTF_STYLE_BOLD;
+    else if (renderStyle[i] == 'i')
+      this->renderStyle |= TTF_STYLE_ITALIC;
+    else if (renderStyle[i] == 'u')
+      this->renderStyle |= TTF_STYLE_UNDERLINE;
+  }
+  if (likely(this->fontTTF != NULL))
+    TTF_SetFontStyle(this->fontTTF, this->renderStyle);
+  //  else
+  //    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
+}
+
+
+
+/**
+ * @param glyph: The Glyph to set the Parameters to.
+ * @param character: The character to get info about.
+ * @returns a Glyph struct of a character. This Glyph is a pointer,
+ * and MUST be deleted by the user..
+ *
+ * This only works for horizontal fonts. see
+ * http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
+ * for more info about vertical Fonts
+ */
+bool FontData::getGlyphMetrics(Glyph* glyph, Uint16 character)
+{
+  glyph->character = character;
+  if (likely (this->fontTTF!= NULL))
+  {
+    int miX, maX, miY, maY, adv;
+    if (TTF_GlyphMetrics(this->fontTTF, glyph->character,
+        &miX, &maX,
+        &miY, &maY,
+        &adv) == -1)
+      return false;
+    glyph->minX = (float)miX / (float)this->renderSize;
+    glyph->maxX = (float)maX / (float)this->renderSize;
+    glyph->minY = (float)miY / (float)this->renderSize;
+    glyph->maxY = (float)maY / (float)this->renderSize;
+    glyph->advance = (float)adv / (float)this->renderSize;
+
+    // Calculate the Rest.
+    glyph->height = glyph->maxY - glyph->minY;
+    glyph->width = glyph->maxX - glyph->minX;
+    glyph->bearingX = (glyph->advance - glyph->width) / 2;
+    glyph->bearingY = glyph->maxY;
+
+    //printf("%c:: %d %d %d %d %d\n", character, miX, maX, miY, maY, adv);
+
+    return true;
+  }
+  return false;
+}
+
+
+/**
+ * @brief creates a Fast-Texture of this Font
+ */
+bool FontData::createFastTexture()
+{
+  /* interesting GLYPHS:
+  *  32: space
+  *  33-47: Special Characters.
+  *  48-57: 0-9
+  *  58-63: some more special chars (minor)
+  *  65-90: A-Z
+  *  97-122: a-z
+  */
+  int numberOfGlyphs = 91;
+
+  this->initGlyphs(32, numberOfGlyphs);
+  //  this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
+
+  int rectSize = this->findOptimalFastTextureSize();
+
+  // setting default values. (maybe not needed afterwards)
+  SDL_Color tmpColor;  tmpColor.r = tmpColor.g = tmpColor.b = 0;
+  // Surface definition.
+  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
+  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_HWSURFACE,
+                                               rectSize, rectSize,
+                                               32,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
+                          0x000000FF,
+                          0x0000FF00,
+                          0x00FF0000,
+                          0xFF000000
+#else
+                              0xFF000000,
+                          0x00FF0000,
+                          0x0000FF00,
+                          0x000000FF
+#endif
+                                              );
+  tmpRect.x = 0; tmpRect.y = 0; tmpRect.w = tmpSurf->w; tmpRect.h = tmpSurf->h;
+  SDL_SetClipRect(tmpSurf, &tmpRect);
+  int maxLineHeight = this->getMaxHeight();
+
+  // all the interessting Glyphs
+  for (int i = 0; i < 128; i++)
+  {
+    SDL_Surface* glyphSurf = NULL;
+    Glyph* tmpGlyph;
+
+    if (tmpGlyph = this->glyphArray[i])
+    {
+      if (tmpGlyph->height*this->renderSize > maxLineHeight)
+        maxLineHeight = (int)(tmpGlyph->height*this->renderSize);
+
+      if (tmpRect.x+tmpGlyph->advance*this->renderSize > tmpSurf->w)
+      {
+        tmpRect.x = 0;
+        tmpRect.y = tmpRect.y + maxLineHeight;
+      }
+      if (tmpRect.y + maxLineHeight > tmpSurf->h)
+      {
+        PRINTF(1)("Protection, so font cannot write over the boundraries (!!this should not heappen!!)\n");
+        break;
+      }
+      // reading in the new Glyph
+      if (likely(this->fontTTF != NULL))
+      {
+        SDL_Color white = {255, 255, 255};
+        glyphSurf = TTF_RenderGlyph_Blended(this->fontTTF, i, white);
+      }
+      if( glyphSurf != NULL )
+      {
+        SDL_SetAlpha(glyphSurf, 0, 0);
+        int tmpY = tmpRect.y;
+        tmpRect.y += this->getMaxAscent()-(int)((float)tmpGlyph->bearingY*this->renderSize);
+        SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect);
+        tmpRect.y = tmpY;
+
+        tmpGlyph->texCoord[0] = (float)((float)tmpRect.x )/(float)tmpSurf->w;
+        tmpGlyph->texCoord[1] = (float)((float)tmpRect.x + tmpGlyph->width*(float)this->renderSize)/(float)tmpSurf->w;
+        tmpGlyph->texCoord[2] = (float)(tmpRect.y)/(float)tmpSurf->w;
+        tmpGlyph->texCoord[3] = (float)((float)tmpRect.y+(float)this->getMaxHeight())/(float)tmpSurf->w;
+        SDL_FreeSurface(glyphSurf);
+        tmpRect.x += (int)(tmpGlyph->width * this->renderSize) + 1;
+      }
+    }
+  }
+  // outputting the GLYPH-table
+//       char outName[1024];
+//       sprintf( outName, "%s-glyphs.bmp", this->getName());
+//       SDL_SaveBMP(tmpSurf, outName);
+  this->texData->setAlpha(true);
+  if (this->texData->setSurface(tmpSurf))
+    this->texData->setTexture(Texture::loadTexToGL(tmpSurf));
+  return true;
+}
+
+/**
+ * @brief stores Glyph Metrics in an Array.
+ * @param from The Glyph to start from.
+ * @param count The number of Glyphs to start From.
+ */
+void FontData::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.
+    Glyph* newGlyph = new Glyph;
+    if (getGlyphMetrics(newGlyph, i))
+      this->glyphArray[i] = newGlyph;
+    else
+    {
+      delete newGlyph;
+      this->glyphArray[i] = NULL;
+    }
+  }
+  return;
+}
+
+/**
+ * @returns the optimal size to use as the texture size
+ *
+ * @todo: this algorithm can be a lot 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 FontData::findOptimalFastTextureSize()
+{
+  if (this->glyphArray == NULL)
+    return 0;
+
+  unsigned int i;
+  unsigned int x,y; // the counters
+  int maxLineHeight = this->getMaxHeight();
+  unsigned int size = 32;  // starting Value, we have to start somewhere 32 seems reasonable. (take any small enough 2^i number)
+  bool sizeOK = false;
+  Glyph* tmpGlyph;
+
+  while (!sizeOK)
+  {
+    x = 0; y = 0;
+    for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
+    {
+      if((tmpGlyph = this->glyphArray[i]) != NULL)
+      {
+        // getting the height of the highest Glyph in the Line.
+        if (tmpGlyph->height*this->renderSize > maxLineHeight)
+          maxLineHeight = (int)(tmpGlyph->height*this->renderSize);
+
+        if (x + tmpGlyph->advance*this->renderSize > size)
+        {
+          x = 0;
+          y = y + maxLineHeight;
+          //maxLineHeight = 0;
+        }
+        if (y + maxLineHeight + 1 > size)
+          break;
+        x += (int)(tmpGlyph->advance*this->renderSize)+1;
+
+      }
+    }
+    if (i >= FONT_HIGHEST_KNOWN_CHAR-1 || size > 8192)
+      sizeOK = true;
+    else
+      size *= 2;
+  }
+  return size;
+}
+
Index: /trunk/src/lib/graphics/text_engine/font_data.h
===================================================================
--- /trunk/src/lib/graphics/text_engine/font_data.h	(revision 8763)
+++ /trunk/src/lib/graphics/text_engine/font_data.h	(revision 8764)
@@ -55,4 +55,12 @@
 
 
+  /// LOADING new Fonts
+  bool loadFontFromTTF(const std::string& fontFile, unsigned int renderSize);
+  bool loadFontFromSDL_Surface(SDL_Surface* surface);
+
+  void setStyle(const std::string& renderStyle);
+
+
+
   /** @returns a Pointer to the Array of Glyphs */
   inline Glyph** getGlyphArray() const { return this->glyphArray; };
@@ -60,9 +68,23 @@
   inline TTF_Font* getTTF() const { return this->fontTTF; };
 
+  int getMaxHeight() const;
+  int getMaxAscent() const;
+  int getMaxDescent() const;
+
+
   bool rebuild();
+
+
+
 
 
 private:
   FontData();
+
+  void initGlyphs(Uint16 from, Uint16 count);
+  bool getGlyphMetrics(Glyph* glyph, Uint16 character);
+
+  int findOptimalFastTextureSize();
+  bool createFastTexture();
 
 private:
Index: /trunk/src/lib/graphics/text_engine/text.cc
===================================================================
--- /trunk/src/lib/graphics/text_engine/text.cc	(revision 8763)
+++ /trunk/src/lib/graphics/text_engine/text.cc	(revision 8764)
@@ -187,7 +187,14 @@
     this->_font = *newFont;
 
-  printf("Font Texture is\n" );
-  _font.debug();
-  this->setupTextWidth();
+  this->setupTextWidth();
+}
+
+/**
+ * @brief set a new Font to this Text.
+ * @param font the Font to set.
+ */
+void Text::setFont(const Font& font)
+{
+  this->_font = font;
 }
 
Index: /trunk/src/lib/graphics/text_engine/text.h
===================================================================
--- /trunk/src/lib/graphics/text_engine/text.h	(revision 8763)
+++ /trunk/src/lib/graphics/text_engine/text.h	(revision 8764)
@@ -44,4 +44,5 @@
     /// SETUP
     void setFont(const std::string& fontFile, unsigned int renderSize);
+    void setFont(const Font& font);
     /** @param blending the blending intensity to set (between 0.0 and 1.0) */
     inline void setBlending(float blending) { this->_font.setTransparency(blending); };
