Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/lib/graphics/font/glfont.h @ 3740

Last change on this file since 3740 was 3740, checked in by bensch, 19 years ago

orxonox/branches/textEngine: now the TextEngine generates Display-Lists

File size: 4.6 KB
Line 
1/*!
2    \file glfont.h
3    \brief Handles the display of glFonts.
4*/
5
6#ifndef _GLFONT_H
7#define _GLFONT_H
8
9#include "glincl.h"
10#include "SDL_ttf.h"
11
12#include "vector.h"
13
14// FORWARD DECLARATION
15class PNode;
16template<class T> class tList;
17
18
19/* some default values */
20#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
21#define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< some default text to display
22#define FONT_DEFAULT_COLOR_R    256                  //!< the default red part (color) of the text
23#define FONT_DEFAULT_COLOR_G    256                  //!< the default red green (color) of the text
24#define FONT_DEFAULT_COLOR_B    256                  //!< the default red blue (color) of the text
25#define FONT_NUM_COLORS         256                  //!< The number of colors.
26
27#define FONT_HIGHEST_KNOWN_CHAR 128                  //!< The highest character known to the textEngine.
28
29
30//! A Struct to handel Texture Coordinates for quads
31struct TexCoord
32{
33  float minU;                      //!< The minimum U-Coordinate
34  float maxU;                      //!< The maximum U-Coordinate
35  float minV;                      //!< The minimum V-Coordinate
36  float maxV;                      //!< The maximum V-Coordinate
37};
38
39//! A struct for handling glyphs
40/**
41   a Glyph is one letter of a certain font
42*/
43struct Glyph
44{
45  // Glyph-specific (size and so on)
46  Uint16 character;              //!< The character
47  int minX;                      //!< The minimum distance from the origin in X
48  int maxX;                      //!< The maximum distance from the origin in X
49  int minY;                      //!< The minimum distance from the origin in Y
50  int maxY;                      //!< The maximum distance from the origin in Y
51  int width;                     //!< The width of the Glyph
52  int height;                    //!< The height of the Glyph
53  int bearingX;                  //!< How much is right of the Origin
54  int bearingY;                  //!< How much is above the Origin
55  int advance;                   //!< How big a Glyph would be in monospace-mode
56 
57  // OpenGL-specific
58  //  TexCoord texCoord;             //!< A Texture Coordinate for this glyph.
59  GLuint displayList;            //!< DiplayList to render this Glyph.
60};
61
62//! A class to handle a Font
63class GLFont
64{
65 public:
66  GLFont(const char* fontFile);
67  virtual ~GLFont();
68
69  // general
70  static void enableFonts(void);
71  static void disableFonts(void);
72
73  // font
74  bool setFont(const char* fontFile);
75  void setSize(unsigned int fontSize);
76  void setColor(Uint8 r, Uint8 g, Uint8 b);
77
78  // text
79  void setBindNode(PNode* bindNode);
80  void setText(const char* text);
81  void setStyle(char* renderStyle);
82  void setPosition(int x, int y);
83  void createTexture(void);
84 
85  virtual void draw(void);
86
87 private:
88  // general purpose
89  GLdouble projMat[16];             //!< The Projection Matrix
90
91  // information about the Font
92  TTF_Font* font;                   //!< The font we use for this.
93  char* fontFile;                   //!< The fontfile from whitch the font was loaded.
94  unsigned int fontSize;            //!< The size of the font in pixels. each Font has one size.
95 
96  Glyph** glyphArray;               //!< An Array of all the Glyphs stored in the Array of Glyphs.
97
98  //! Represents one textElement.
99  struct Text
100  {
101    char* text;                      //!< The text to display
102    SDL_Color color;                 //!< The color of the font.
103    // placement in openGL
104    GLuint texture;                  //!< A GL-texture to hold the text
105    TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
106    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
107    int renderStyle;                 //!< The Renderstyle
108
109    PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
110  };
111  tList<Text>* textList;
112  Text* currentText;
113
114  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
115  int getMaxHeight(void);
116  int getMaxAscent(void);
117  int getMaxDescent(void);
118  Glyph* getGlyphMetrics(Uint16 character);
119
120  static bool ttfInitialized;
121
122  void enter2DMode(void);
123  void leave2DMode(void);
124
125  static bool checkVersion(void);
126
127  GLuint createFastTexture();
128  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
129
130  void initGlyphs(Uint16 from, Uint16 count);
131  int findOptimalFastTextureSize(void);
132  static int powerOfTwo(int input);
133
134  void debug(void);
135
136};
137
138void m_inverse(const float *m, float *out);
139Vector mvMult(const float *mat, const Vector* vec);
140#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.