Index: /orxonox/branches/textEngine/config.h.in
===================================================================
--- /orxonox/branches/textEngine/config.h.in	(revision 3690)
+++ /orxonox/branches/textEngine/config.h.in	(revision 3691)
@@ -59,4 +59,7 @@
 #undef HAVE_SDL_SDL_IMAGE_H
 
+/* Define to 1 if you have the <SDL/SDL_ttf.h> header file. */
+#undef HAVE_SDL_SDL_TTF_H
+
 /* Define to 1 if you have the `sqrt' function. */
 #undef HAVE_SQRT
Index: /orxonox/branches/textEngine/configure
===================================================================
--- /orxonox/branches/textEngine/configure	(revision 3690)
+++ /orxonox/branches/textEngine/configure	(revision 3691)
@@ -5045,5 +5045,5 @@
  Linux="yes"
 
-CPPFLAGS="-I/usr/X11R6/include"
+CPPFLAGS="-I/usr/X11R6/include -I/usr/include/SDL"
 LDFLAGS="-L/usr/lib/opengl/xorg-x11/lib -L/usr/Mesa-6.0.1/lib -L/usr/X11R6/lib $LDFLAGS"
 # checking gl header
@@ -6110,6 +6110,6 @@
 # SDL_Image #
 #-----------#
-#if test x$def_sdl_image = xyes; then
-# checking for SDL_image-headers
+#if test x$def_sdl_ttf = xyes; then
+# checking for SDL_ttf-headers
 
 for ac_header in SDL/SDL_ttf.h
Index: /orxonox/branches/textEngine/configure.ac
===================================================================
--- /orxonox/branches/textEngine/configure.ac	(revision 3690)
+++ /orxonox/branches/textEngine/configure.ac	(revision 3691)
@@ -291,5 +291,5 @@
  Linux="yes"
 
-CPPFLAGS="-I/usr/X11R6/include"
+CPPFLAGS="-I/usr/X11R6/include -I/usr/include/SDL"
 LDFLAGS="-L/usr/lib/opengl/xorg-x11/lib -L/usr/Mesa-6.0.1/lib -L/usr/X11R6/lib $LDFLAGS"
 # checking gl header
Index: /orxonox/branches/textEngine/src/defs/glincl.h
===================================================================
--- /orxonox/branches/textEngine/src/defs/glincl.h	(revision 3690)
+++ /orxonox/branches/textEngine/src/defs/glincl.h	(revision 3691)
@@ -9,10 +9,10 @@
 #define _GLINCL_H
 
+#include <SDL.h>
+
 #ifndef __APPLE__
-#include <SDL/SDL.h>
 #include <GL/gl.h>
 #include <GL/glu.h>
 #else
-#include <SDL.h>
 #include <OpenGL/gl.h>
 #include <OpenGL/glu.h>
Index: /orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc
===================================================================
--- /orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc	(revision 3690)
+++ /orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc	(revision 3691)
@@ -18,4 +18,5 @@
    *                                                                  ***
 
+   for some fonts and licenses visit: =http://www.dafont.com/en/font.php=
 */
 
@@ -46,14 +47,8 @@
 #include "glfont.h"
 
-
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-#include <SDL/SDL.h>
-#include <SDL/SDL_ttf.h>
-
-#include "glincl.h"
 #include "debug.h"
 
@@ -74,53 +69,168 @@
   this->init(fontFile);
 }
+
 GLFont::~GLFont()
 {
-  
-}
+  if (this->font)
+    TTF_CloseFont(this->font);
+}
+
+void GLFont::enableFonts(void)
+{
+  if (!GLFont::ttfInitialized)
+    {
+      if(TTF_Init()==-1) {
+	PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
+	exit(2);
+      }
+      GLFont::checkVersion();
+      GLFont::ttfInitialized = true;
+    }
+  else
+    PRINTF(4)("Fonts already initialized\n");
+      
+}
+void GLFont::disableFonts(void)
+{
+  if (GLFont::ttfInitialized)
+    {
+      TTF_Quit();
+      GLFont::ttfInitialized = false;
+    }
+  else
+    PRINTF(4)("Fonts were not initialized.\n");
+}
+
+bool GLFont::ttfInitialized = false;
+
 
 bool GLFont::init(const char* fontFile)
 {
   // setting default values.
-  renderStyle = TTF_STYLE_NORMAL;
-
-
-  // Initializing lib-TTF if necesary.
-  if (TTF_WasInit() && TTF_Init() < 0 ) 
+  this->font = NULL;
+  this->fontFile = NULL;
+  this->fontSize = 16;
+  
+  this->renderStyle = TTF_STYLE_NORMAL;
+
+
+  if (!GLFont::ttfInitialized)
+    GLFont::enableFonts();
+}
+
+
+bool GLFont::setFont(const char* fontFile)
+{
+  if (!this->fontFile)
     {
-      PRINTF(1)("Couldn't initialize TTF: %s\n", SDL_GetError());
-      return false;
+      this->fontFile = new char[strlen(fontFile)+1];
+      strcpy(this->fontFile, fontFile);
+      
+      this->font = TTF_OpenFont(this->fontFile, this->fontSize);
+      if(!this->font) 
+	{
+	  PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
+	  // handle error
+      }
     }
-}
-
-bool GLFont::ttfInitialized = false;
-
-bool GLFont::setFont(const char* fonFile)
-{
-
-}
+  else
+    PRINTF(2)("Font already initialized, unable to change it now.\n");
+}
+
+
 void GLFont::setText(const char* text)
 {
-
-}
-
-void GLFont::setStyle(char* style)
-{
-  renderStyle = TTF_STYLE_NORMAL;
-  
-  for (int i = 0; i < strlen(style); i++)
-    if (strncmp(style+i, "b", 1) == 0) 
+  this->text = new char[strlen(text)+1];
+  strcpy(this->text, text);
+}
+
+/**
+   \brief sets a specific renderStyle
+   \param renderStyle the Style to render: a char-array containing:
+   i: italic, b: bold, u, underline
+*/
+void GLFont::setStyle(char* renderStyle)
+{
+  this->renderStyle = TTF_STYLE_NORMAL;
+  
+  for (int i = 0; i < strlen(renderStyle); i++)
+    if (strncmp(renderStyle+i, "b", 1) == 0) 
       this->renderStyle |= TTF_STYLE_BOLD;
-    else if (strncmp(style+i, "i", 1) == 0)
+    else if (strncmp(renderStyle+i, "i", 1) == 0)
       this->renderStyle |= TTF_STYLE_ITALIC;
-    else if (strncmp(style+i, "u", 1) == 0) 
+    else if (strncmp(renderStyle+i, "u", 1) == 0) 
       this->renderStyle |= TTF_STYLE_UNDERLINE;
 
-  // TTF_SetFontStyle(font, renderstyle);
-
-}
+  if (this->font)
+    TTF_SetFontStyle(this->font, this->renderStyle);
+  else
+    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
+}
+
 void GLFont::setSize(void)
 {
 
 }
+
+/**
+   \returns the maximum height of the Font, if the font was initialized, 0 otherwise
+*/
+int GLFont::getMaxHeight(void)
+{
+  if (this->font)
+    return TTF_FontHeight(this->font);
+  else
+    return 0;
+}
+
+/**
+   \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 GLFont::getMaxAscent(void)
+{
+  if (this->font)
+    return TTF_FontAscent(this->font);
+  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 GLFont::getMaxDescent(void)
+{
+  if (this->font)
+    return TTF_FontDescent(this->font);
+  else
+    return 0;
+}
+
+/**
+   \param character The character to get info about.
+   \returns a Glyph struct of a character.
+
+   This only works for horizontal fonts. see 
+   http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
+   for more info about vertical Fonts
+*/
+glyph GLFont::getGlyphMetrics(Uint16 character)
+{
+  glyph rg;
+  rg.character = character;
+  TTF_GlyphMetrics(this->font, rg.character,
+		   &rg.minX, &rg.maxX,
+		   &rg.minY, &rg.maxY,
+		   &rg.advance);
+  rg.height = rg.maxY - rg.minY;
+  rg.width = rg.maxX - rg.minX;
+  rg.bearingX = (rg.advance - rg.width) / 2;
+  rg.bearingY = rg.maxY;
+  return rg;
+}
+
 void GLFont::setPosition(int x, int y)
 {
@@ -178,7 +288,51 @@
 }
 
-
-bool GLFont::loadTexture()
-{
+void GLFont::enter2DMode()
+{
+  SDL_Surface *screen = SDL_GetVideoSurface();
+  
+  /* Note, there may be other things you need to change,
+     depending on how you have your OpenGL state set up.
+  */
+  glPushAttrib(GL_ENABLE_BIT);
+  glDisable(GL_DEPTH_TEST);
+  glDisable(GL_CULL_FACE);
+  glEnable(GL_TEXTURE_2D);
+  
+  /* This allows alpha blending of 2D textures with the scene */
+  glEnable(GL_BLEND);
+  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+  
+  glViewport(0, 0, screen->w, screen->h);
+  
+  glMatrixMode(GL_PROJECTION);
+  glPushMatrix();
+  glLoadIdentity();
+  
+  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
+  
+  glMatrixMode(GL_MODELVIEW);
+  glPushMatrix();
+  glLoadIdentity();
+  
+  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+}
+
+
+void GLFont::leave2DMode()
+{
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+
+	glPopAttrib();
+}
+
+
+GLuint GLFont::loadTexture(SDL_Surface *surface, GLfloat *texcoord)
+{
+  GLuint texture;
   int w, h;
   SDL_Surface *image;
@@ -249,6 +403,37 @@
   SDL_FreeSurface(image); /* No longer needed */
   
-  //  return texture;
-}
+  return texture;
+}
+
+
+bool GLFont::checkVersion(void)
+{
+  SDL_version compile_version;
+  SDL_version link_version;
+  TTF_VERSION(&compile_version);
+  link_version = *TTF_Linked_Version();
+
+  if (compile_version.major == link_version.major &&
+      compile_version.minor == link_version.minor &&
+      compile_version.patch == link_version.patch)
+    {
+      return true;
+    }
+  else
+    {
+      PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", 
+		compile_version.major,
+		compile_version.minor,
+		compile_version.patch);
+      
+      PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", 
+		link_version.major,
+		link_version.minor,
+		link_version.patch);
+      return false;
+    }
+}
+
+
 
 /* Quick utility function for texture creation */
@@ -264,143 +449,24 @@
 
 
-/*
-private:
-char* fontFile;
-char* text;
-int positionX;
-int positionY;
-*/
-
-
-
-
-char Usage[100] = "orxonox test" ;
-void GLFont::enter2DMode()
-{
-  SDL_Surface *screen = SDL_GetVideoSurface();
-  
-  /* Note, there may be other things you need to change,
-     depending on how you have your OpenGL state set up.
-  */
-  glPushAttrib(GL_ENABLE_BIT);
-  glDisable(GL_DEPTH_TEST);
-  glDisable(GL_CULL_FACE);
-  glEnable(GL_TEXTURE_2D);
-  
-  /* This allows alpha blending of 2D textures with the scene */
-  glEnable(GL_BLEND);
-  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-  
-  glViewport(0, 0, screen->w, screen->h);
-  
-  glMatrixMode(GL_PROJECTION);
-  glPushMatrix();
-  glLoadIdentity();
-  
-  glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
-  
-  glMatrixMode(GL_MODELVIEW);
-  glPushMatrix();
-  glLoadIdentity();
-  
-  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-}
-
-
-void GLFont::leave2DMode()
-{
-	glMatrixMode(GL_MODELVIEW);
-	glPopMatrix();
-
-	glMatrixMode(GL_PROJECTION);
-	glPopMatrix();
-
-	glPopAttrib();
-}
-
-
-GLuint GLFont::loadTexture(SDL_Surface *surface, GLfloat *texcoord)
-{
-  GLuint texture;
-  int w, h;
-  SDL_Surface *image;
-  SDL_Rect area;
-  Uint32 saved_flags;
-  Uint8  saved_alpha;
-  
-  /* Use the surface width and height expanded to powers of 2 */
-  w = power_of_two(surface->w);
-  h = power_of_two(surface->h);
-  texcoord[0] = 0.0f;			/* Min X */
-  texcoord[1] = 0.0f;			/* Min Y */
-  texcoord[2] = (GLfloat)surface->w / w;	/* Max X */
-  texcoord[3] = (GLfloat)surface->h / h;	/* Max Y */
-  
-  image = SDL_CreateRGBSurface(
-			       SDL_SWSURFACE,
-			       w, h,
-			       32,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
-			       0x000000FF, 
-			       0x0000FF00, 
-			       0x00FF0000, 
-			       0xFF000000
-#else
-			       0xFF000000,
-			       0x00FF0000, 
-			       0x0000FF00, 
-			       0x000000FF
-#endif
-			       );
-  if ( image == NULL ) {
-    return 0;
+
+void GLFont::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");
   }
-  
-  /* Save the alpha blending attributes */
-  saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
-  saved_alpha = surface->format->alpha;
-  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
-    SDL_SetAlpha(surface, 0, 0);
-  }
-  
-  /* Copy the surface into the GL texture image */
-  area.x = 0;
-  area.y = 0;
-  area.w = surface->w;
-  area.h = surface->h;
-  SDL_BlitSurface(surface, &area, image, &area);
-  
-  /* Restore the alpha blending attributes */
-  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
-    SDL_SetAlpha(surface, saved_flags, saved_alpha);
-  }
-  
-  /* Create an OpenGL texture for the image */
-  glGenTextures(1, &texture);
-  glBindTexture(GL_TEXTURE_2D, texture);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-  glTexImage2D(GL_TEXTURE_2D,
-	       0,
-	       GL_RGBA,
-	       w, h,
-	       0,
-	       GL_RGBA,
-	       GL_UNSIGNED_BYTE,
-	       image->pixels);
-  SDL_FreeSurface(image); /* No longer needed */
-  
-  return texture;
-}
-
-
-/* Quick utility function for texture creation */
-int GLFont::power_of_two(int input)
-{
-  int value = 1;
-  
-  while ( value < input ) {
-    value <<= 1;
-  }
-  return value;
-}
+  PRINTF(0)("\n");
+
+
+}
Index: /orxonox/branches/textEngine/src/lib/graphics/font/glfont.h
===================================================================
--- /orxonox/branches/textEngine/src/lib/graphics/font/glfont.h	(revision 3690)
+++ /orxonox/branches/textEngine/src/lib/graphics/font/glfont.h	(revision 3691)
@@ -8,12 +8,37 @@
 
 #include "glincl.h"
+#include "SDL_ttf.h"
+
+
+//! A struct for handling glyphs
+struct glyph
+{
+  Uint16 character;
+  int minX;
+  int maxX;
+  int minY;
+  int maxY;
+  int width;
+  int height;
+  int bearingX;
+  int bearingY;
+  int advance;
+};
+
 
 class GLFont
 {
+  
+ private:
+
+    
+
  public:
   GLFont();
   GLFont(const char* fontFile);
-  ~GLFont();
-  
+  virtual ~GLFont();
+
+  static void enableFonts(void);
+  static void disableFonts(void);
 
 
@@ -21,5 +46,5 @@
   void setText(const char* text);
 
-  void setStyle(char* style);
+  void setStyle(char* renderStyle);
   void setSize(void);
   void setPosition(int x, int y);
@@ -29,6 +54,11 @@
 
  private:
+  // information about the Font
+  TTF_Font* font;
   char* fontFile;
   char* text;
+  unsigned int fontSize;
+
+  // placement in openGL
   GLuint texture;
   int positionX;
@@ -39,6 +69,8 @@
 
   bool init(const char* fontFile);
-  bool loadTexture();
-  static int powerOfTwo(int input);
+  int getMaxHeight(void);
+  int getMaxAscent(void);
+  int getMaxDescent(void);
+  glyph getGlyphMetrics(Uint16 character);
 
   static bool ttfInitialized;
@@ -47,7 +79,11 @@
   void leave2DMode(void);
 
+  static bool checkVersion(void);
+
   GLuint loadTexture(SDL_Surface* surface, GLfloat* texcoord);
 
-  static int power_of_two(int input);
+  static int powerOfTwo(int input);
+
+  void debug(void);
 
 };
