Index: trunk/src/lib/graphics/text_engine/font.cc
===================================================================
--- trunk/src/lib/graphics/text_engine/font.cc	(revision 8751)
+++ trunk/src/lib/graphics/text_engine/font.cc	(revision 8761)
@@ -17,5 +17,4 @@
 
 #include "font.h"
-#include "text.h"
 
 #ifdef HAVE_SDL_IMAGE_H
@@ -24,10 +23,17 @@
 #include <SDL/SDL_image.h>
 #endif
+
 #include "default_font.xpm"
 
 #include "debug.h"
-#include "stdlibincl.h"
 #include "compiler.h"
-using namespace std;
+
+
+Font::Font()
+  : data(Font::defaultFontData)
+{
+  this->init();
+
+}
 
 /**
@@ -37,15 +43,12 @@
  */
 Font::Font(const std::string& fontFile, unsigned int renderSize)
-  : data(new FontData())
+  : data(Font::defaultFontData)
 {
   this->init();
 
-
-  this->data->renderSize = renderSize;
-  this->setStyle("c");
-
   if (!fontFile.empty())
-    this->loadFontFromTTF(fontFile);
-}
+    this->loadFontFromTTF(fontFile, renderSize);
+}
+
 
 /**
@@ -54,7 +57,8 @@
  */
 Font::Font(const std::string& imageFile)
-  : data(new FontData())
+  : data(Font::defaultFontData)
 {
   this->init();
+
   this->setName(imageFile);
   //  this->setSize(fontSize);
@@ -78,5 +82,5 @@
  */
 Font::Font(char** xpmArray)
-  : data(new FontData())
+  : data(Font::defaultFontData)
 {
   this->init();
@@ -92,5 +96,5 @@
   }
   else
-    PRINTF(1)("loading from surface failed: %s\n", IMG_GetError());
+    PRINTF(1)("Loading from XPM-array failed: %s\n", IMG_GetError());
 }
 
@@ -105,4 +109,13 @@
 { }
 
+Font& Font::operator=(const Font& font)
+{
+  Material::operator=(font);
+  this->data = font.data;
+
+  return *this;
+};
+
+
 /**
  * @brief initializes a Font (with default values)
@@ -110,7 +123,28 @@
 void Font::init()
 {
+  this->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
   this->setClassID(CL_FONT, "Font");
-}
-
+  if (Font::defaultFontData.get() == NULL)
+  {
+     Font::initDefaultFont();
+    this->data = Font::defaultFontData;
+  }
+}
+
+FontDataPointer Font::defaultFontData(NULL);
+
+/**
+ * @brief initializes the default font
+ */
+void Font::initDefaultFont()
+{
+  // temporarily create a Font.
+  Font::defaultFontData = FontDataPointer(new FontData);
+  // apply the Data.
+  printf("before: %p\n", defaultFontData.get());
+  Font::defaultFontData = Font(font_xpm).data;
+  printf("after: %p\n", defaultFontData.get());
+}
 
 /**
@@ -119,25 +153,27 @@
  * @returns true if loaded, false if something went wrong, or if a font was loaded before.
  */
-bool Font::loadFontFromTTF(const std::string& fontFile)
-{
-  // checking for existent Font.
-  if (this->data->fontTTF != NULL)
-  {
-    TTF_CloseFont(this->data->fontTTF);
-    this->data->fontTTF = NULL;
-  }
-
+bool Font::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize)
+{
+  this->data = FontDataPointer (new FontData());
 
   this->setName(fontFile);
-  this->data->fontTTF = TTF_OpenFont(this->getName(), this->data->renderSize);
+  this->data->fontTTF = TTF_OpenFont(fontFile.c_str(), renderSize);
+  this->data->renderSize = renderSize;
 
   if(this->data->fontTTF != NULL)
   {
-    this->createFastTexture();
-    return (this->getTexture() != 0);
+    this->setStyle("c");
+    if (this->createFastTexture())
+      return true;
+    else
+    {
+      this->data = Font::defaultFontData;
+      return false;
+    }
   }
   else
   {
     PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
+    this->data = Font::defaultFontData;
     return false;
   }
@@ -151,20 +187,22 @@
 bool Font::loadFontFromSDL_Surface(SDL_Surface* surface)
 {
-  // loading to a texture.
   if(surface == NULL)
     return false;
 
-  if (this->data->fontTTF != NULL)
-  {
-    TTF_CloseFont(this->data->fontTTF);
-    this->data->fontTTF = NULL;
-  }
+  this->data = FontDataPointer (new FontData());
+  // loading to a texture.
+
   bool hasAlpha;
-  SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
+  SDL_Surface* newSurf = Texture::prepareSurface(surface, hasAlpha);
   if (newSurf != NULL)
   {
-    this->setSurface(newSurf);
-    this->setAlpha(hasAlpha);
+    this->data->texData->setSurface(newSurf);
+    this->data->texData->setAlpha(hasAlpha);
     this->setTexture(Texture::loadTexToGL(newSurf));
+  }
+  else
+  {
+    this->data = Font::defaultFontData;
+    return false;
   }
 
@@ -223,6 +261,4 @@
   //    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
 }
-
-Font* Font::defaultFont = NULL;
 
 /**
@@ -283,23 +319,4 @@
   SDL_SaveBMP(tmpSurf, fileName.c_str());
   SDL_FreeSurface(tmpSurf);
-}
-
-/**
- * @brief initializes the default font
- */
-void Font::initDefaultFont()
-{
-  if (Font::defaultFont == NULL)
-    Font::defaultFont = new Font(font_xpm);
-}
-
-/**
- * @brief deletes the default font
- */
-void Font::removeDefaultFont()
-{
-  if (Font::defaultFont != NULL)
-    delete Font::defaultFont;
-  Font::defaultFont = NULL;
 }
 
@@ -473,9 +490,24 @@
 //       sprintf( outName, "%s-glyphs.bmp", this->getName());
 //       SDL_SaveBMP(tmpSurf, outName);
-  this->setAlpha(true);
-  if (this->setSurface(tmpSurf))
-    (this->setTexture(Texture::loadTexToGL(tmpSurf)));
+  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;
+};
 
 /**
@@ -569,6 +601,9 @@
  * @brief a simple function to get some interesting information about this class
  */
-void Font::debug()
-{
+void Font::debug() const
+{
+  Material::debug();
+
+  PRINT(0)("TEST %p and %p\n", this->data.get(), this->data->texData.get());
   // print the loaded font's style
   int style = TTF_STYLE_NORMAL;
