Index: orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h
===================================================================
--- orxonox/branches/textEngine/src/proto/proto_singleton.h	(revision 3681)
+++ orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h	(revision 3766)
@@ -1,27 +1,180 @@
 /*! 
-    \file proto_singleton.h
-    \brief Definition of the proto class template, used quickly start work
-    
-    a simple file to copy and create a singleton-class from
+    \file text_engine.h
+    \brief Definition of textEngine, the Font and the Text
+
+    Text is the text outputed.
+    Font is a class that loads a certain ttf-file with a specific height into memory
+    TextEngine is used to manage the all the different Fonts that might be included
+
+    for more information see the specific classes.
 */
 
-#ifndef _PROTO_SINGLETON_H
-#define _PROTO_SINGLETON_H
+#ifndef _TEXT_ENGINE_H
+#define _TEXT_ENGINE_H
 
+
+#include "glincl.h"
+#include "SDL_ttf.h"
+
+#include "vector.h"
 #include "base_object.h"
 
-// FORWARD DEFINITION \\
+// FORWARD DECLARATION
+class PNode;
+template<class T> class tList;
 
-//! A default singleton class.
-class ProtoSingleton : public BaseObject {
+
+/* some default values */
+#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
+#define FONT_DEFAULT_TEXT	"orxonox 1234567890" //!< some default text to display
+#define FONT_DEFAULT_COLOR_R    256                  //!< the default red part (color) of the text
+#define FONT_DEFAULT_COLOR_G    256                  //!< the default red green (color) of the text
+#define FONT_DEFAULT_COLOR_B    256                  //!< the default red blue (color) of the text
+#define FONT_NUM_COLORS         256                  //!< The number of colors.
+
+#define FONT_HIGHEST_KNOWN_CHAR 128                  //!< The highest character known to the textEngine.
+
+#define TEXT_STATIC             0                    //!< Static Text
+#define TEXT_DYNAMIC            1                    //!< Dynamic Text
+/**
+ * STATIC means: a font, that is only one GL-face.
+ ** it is very fast, and can be used for all text
+ ** that does not have to be changed anymore, or if
+ ** the the text should look very nice
+ * DYNAMIC means: a very fast font, that will is build
+ ** from multiple quads.
+ ** Use this type, if you want to create fast changing
+ ** text like a counter.
+ */
+
+
+//! A Struct to handel Texture Coordinates for quads
+struct TexCoord
+{
+  float minU;                      //!< The minimum U-Coordinate
+  float maxU;                      //!< The maximum U-Coordinate
+  float minV;                      //!< The minimum V-Coordinate
+  float maxV;                      //!< The maximum V-Coordinate
+};
+
+//! A struct for handling glyphs
+/**
+   a Glyph is one letter of a certain font
+*/
+struct Glyph
+{
+  // Glyph-specific (size and so on)
+  Uint16 character;              //!< The character
+  int minX;                      //!< The minimum distance from the origin in X
+  int maxX;                      //!< The maximum distance from the origin in X
+  int minY;                      //!< The minimum distance from the origin in Y
+  int maxY;                      //!< The maximum distance from the origin in Y
+  int width;                     //!< The width of the Glyph
+  int height;                    //!< The height of the Glyph
+  int bearingX;                  //!< How much is right of the Origin
+  int bearingY;                  //!< How much is above the Origin
+  int advance;                   //!< How big a Glyph would be in monospace-mode
+  
+  // OpenGL-specific
+  //  TexCoord texCoord;             //!< A Texture Coordinate for this glyph.
+  GLuint displayList;            //!< DiplayList to render this Glyph.
+};
+
+//! A class to handle a Font
+class Font
+{
+ public:
+  Font(const char* fontFile);
+  virtual ~Font();
+
+  // font
+  bool setFont(const char* fontFile);
+  void setSize(unsigned int fontSize);
+  void setColor(Uint8 r, Uint8 g, Uint8 b);
+
+  // text
+  void setBindNode(PNode* bindNode);
+  void setType(int type);
+  void setText(const char* text);
+  void setStyle(char* renderStyle);
+  void setPosition(int x, int y);
+  void createTexture(void);
+  
+  virtual void draw(void);
+
+ private:
+  // general purpose
+  GLdouble projMat[16];             //!< The Projection Matrix
+
+  // information about the Font
+  TTF_Font* font;                   //!< The font we use for this.
+  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.
+  
+  Glyph** glyphArray;               //!< An Array of all the Glyphs stored in the Array of Glyphs.
+  GLuint fastTextureID;             //!< The fast textureID.
+
+  //! Represents one textElement.
+  struct Text
+  {
+    int type;                   //!< The type of this Font.
+    char* text;                      //!< The text to display
+    SDL_Color color;                 //!< The color of the font.
+    // placement in openGL
+    GLuint texture;                  //!< A GL-texture to hold the text
+    TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
+    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
+    int renderStyle;                 //!< The Renderstyle
+
+    PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
+  };
+  tList<Text>* textList;
+  Text* currentText;
+
+  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
+  int getMaxHeight(void);
+  int getMaxAscent(void);
+  int getMaxDescent(void);
+  Glyph* getGlyphMetrics(Uint16 character);
+
+  void enter2DMode(void);
+  void leave2DMode(void);
+
+
+  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);
+
+};
+
+void m_inverse(const float *m, float *out);
+Vector mvMult(const float *mat, const Vector* vec);
+
+
+///////////////////
+/// TEXT-ENGINE ///
+///////////////////
+//! A singleton Class that operates as a Handler for generating and rendering Text in 2D
+class TextEngine : public BaseObject {
 
  public:
-  static ProtoSingleton* getInstance(void);
-  virtual ~ProtoSingleton(void);
+  static TextEngine* getInstance(void);
+  virtual ~TextEngine(void);
+
+  // general
+  static void enableFonts(void);
+  static void disableFonts(void);
+  static bool checkVersion(void);
 
  private:
-  ProtoSingleton(void);
-  static ProtoSingleton* singletonRef;
+  TextEngine(void);
+  static TextEngine* singletonRef;
+
 };
 
-#endif /* _PROTO_SINGLETON_H */
+#endif /* _TEXT_ENGINE_H */
