Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 9, 2005, 4:19:55 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: moved the fonts into a new File textEngine, and also implemented a TextEngine-Singleton-class

File:
1 copied

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h

    r3765 r3766  
    11/*!
    2     \file proto_singleton.h
    3     \brief Definition of the proto class template, used quickly start work
    4    
    5     a simple file to copy and create a singleton-class from
     2    \file text_engine.h
     3    \brief Definition of textEngine, the Font and the Text
     4
     5    Text is the text outputed.
     6    Font is a class that loads a certain ttf-file with a specific height into memory
     7    TextEngine is used to manage the all the different Fonts that might be included
     8
     9    for more information see the specific classes.
    610*/
    711
    8 #ifndef _PROTO_SINGLETON_H
    9 #define _PROTO_SINGLETON_H
     12#ifndef _TEXT_ENGINE_H
     13#define _TEXT_ENGINE_H
    1014
     15
     16#include "glincl.h"
     17#include "SDL_ttf.h"
     18
     19#include "vector.h"
    1120#include "base_object.h"
    1221
    13 // FORWARD DEFINITION \\
     22// FORWARD DECLARATION
     23class PNode;
     24template<class T> class tList;
    1425
    15 //! A default singleton class.
    16 class ProtoSingleton : public BaseObject {
     26
     27/* some default values */
     28#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
     29#define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< some default text to display
     30#define FONT_DEFAULT_COLOR_R    256                  //!< the default red part (color) of the text
     31#define FONT_DEFAULT_COLOR_G    256                  //!< the default red green (color) of the text
     32#define FONT_DEFAULT_COLOR_B    256                  //!< the default red blue (color) of the text
     33#define FONT_NUM_COLORS         256                  //!< The number of colors.
     34
     35#define FONT_HIGHEST_KNOWN_CHAR 128                  //!< The highest character known to the textEngine.
     36
     37#define TEXT_STATIC             0                    //!< Static Text
     38#define TEXT_DYNAMIC            1                    //!< Dynamic Text
     39/**
     40 * STATIC means: a font, that is only one GL-face.
     41 ** it is very fast, and can be used for all text
     42 ** that does not have to be changed anymore, or if
     43 ** the the text should look very nice
     44 * DYNAMIC means: a very fast font, that will is build
     45 ** from multiple quads.
     46 ** Use this type, if you want to create fast changing
     47 ** text like a counter.
     48 */
     49
     50
     51//! A Struct to handel Texture Coordinates for quads
     52struct TexCoord
     53{
     54  float minU;                      //!< The minimum U-Coordinate
     55  float maxU;                      //!< The maximum U-Coordinate
     56  float minV;                      //!< The minimum V-Coordinate
     57  float maxV;                      //!< The maximum V-Coordinate
     58};
     59
     60//! A struct for handling glyphs
     61/**
     62   a Glyph is one letter of a certain font
     63*/
     64struct Glyph
     65{
     66  // Glyph-specific (size and so on)
     67  Uint16 character;              //!< The character
     68  int minX;                      //!< The minimum distance from the origin in X
     69  int maxX;                      //!< The maximum distance from the origin in X
     70  int minY;                      //!< The minimum distance from the origin in Y
     71  int maxY;                      //!< The maximum distance from the origin in Y
     72  int width;                     //!< The width of the Glyph
     73  int height;                    //!< The height of the Glyph
     74  int bearingX;                  //!< How much is right of the Origin
     75  int bearingY;                  //!< How much is above the Origin
     76  int advance;                   //!< How big a Glyph would be in monospace-mode
     77 
     78  // OpenGL-specific
     79  //  TexCoord texCoord;             //!< A Texture Coordinate for this glyph.
     80  GLuint displayList;            //!< DiplayList to render this Glyph.
     81};
     82
     83//! A class to handle a Font
     84class Font
     85{
     86 public:
     87  Font(const char* fontFile);
     88  virtual ~Font();
     89
     90  // font
     91  bool setFont(const char* fontFile);
     92  void setSize(unsigned int fontSize);
     93  void setColor(Uint8 r, Uint8 g, Uint8 b);
     94
     95  // text
     96  void setBindNode(PNode* bindNode);
     97  void setType(int type);
     98  void setText(const char* text);
     99  void setStyle(char* renderStyle);
     100  void setPosition(int x, int y);
     101  void createTexture(void);
     102 
     103  virtual void draw(void);
     104
     105 private:
     106  // general purpose
     107  GLdouble projMat[16];             //!< The Projection Matrix
     108
     109  // information about the Font
     110  TTF_Font* font;                   //!< The font we use for this.
     111  char* fontFile;                   //!< The fontfile from whitch the font was loaded.
     112  unsigned int fontSize;            //!< The size of the font in pixels. each Font has one size.
     113 
     114  Glyph** glyphArray;               //!< An Array of all the Glyphs stored in the Array of Glyphs.
     115  GLuint fastTextureID;             //!< The fast textureID.
     116
     117  //! Represents one textElement.
     118  struct Text
     119  {
     120    int type;                   //!< The type of this Font.
     121    char* text;                      //!< The text to display
     122    SDL_Color color;                 //!< The color of the font.
     123    // placement in openGL
     124    GLuint texture;                  //!< A GL-texture to hold the text
     125    TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
     126    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
     127    int renderStyle;                 //!< The Renderstyle
     128
     129    PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
     130  };
     131  tList<Text>* textList;
     132  Text* currentText;
     133
     134  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
     135  int getMaxHeight(void);
     136  int getMaxAscent(void);
     137  int getMaxDescent(void);
     138  Glyph* getGlyphMetrics(Uint16 character);
     139
     140  void enter2DMode(void);
     141  void leave2DMode(void);
     142
     143
     144  GLuint createFastTexture();
     145  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
     146
     147  void initGlyphs(Uint16 from, Uint16 count);
     148  int findOptimalFastTextureSize(void);
     149  static int powerOfTwo(int input);
     150
     151  void debug(void);
     152
     153};
     154
     155void m_inverse(const float *m, float *out);
     156Vector mvMult(const float *mat, const Vector* vec);
     157
     158
     159///////////////////
     160/// TEXT-ENGINE ///
     161///////////////////
     162//! A singleton Class that operates as a Handler for generating and rendering Text in 2D
     163class TextEngine : public BaseObject {
    17164
    18165 public:
    19   static ProtoSingleton* getInstance(void);
    20   virtual ~ProtoSingleton(void);
     166  static TextEngine* getInstance(void);
     167  virtual ~TextEngine(void);
     168
     169  // general
     170  static void enableFonts(void);
     171  static void disableFonts(void);
     172  static bool checkVersion(void);
    21173
    22174 private:
    23   ProtoSingleton(void);
    24   static ProtoSingleton* singletonRef;
     175  TextEngine(void);
     176  static TextEngine* singletonRef;
     177
    25178};
    26179
    27 #endif /* _PROTO_SINGLETON_H */
     180#endif /* _TEXT_ENGINE_H */
Note: See TracChangeset for help on using the changeset viewer.