Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3754 was 3747, checked in by bensch, 20 years ago

orxonox/braches/textEngine: now shows single char

File size: 5.2 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#define TEXT_STATIC             0                    //!< Static Text
30#define TEXT_DYNAMIC            1                    //!< Dynamic Text
31/**
32 * STATIC means: a font, that is only one GL-face.
33 ** it is very fast, and can be used for all text
34 ** that does not have to be changed anymore, or if
35 ** the the text should look very nice
36 * DYNAMIC means: a very fast font, that will is build
37 ** from multiple quads.
38 ** Use this type, if you want to create fast changing
39 ** text like a counter.
40 */
41
42
43//! A Struct to handel Texture Coordinates for quads
44struct TexCoord
45{
46  float minU;                      //!< The minimum U-Coordinate
47  float maxU;                      //!< The maximum U-Coordinate
48  float minV;                      //!< The minimum V-Coordinate
49  float maxV;                      //!< The maximum V-Coordinate
50};
51
52//! A struct for handling glyphs
53/**
54   a Glyph is one letter of a certain font
55*/
56struct Glyph
57{
58  // Glyph-specific (size and so on)
59  Uint16 character;              //!< The character
60  int minX;                      //!< The minimum distance from the origin in X
61  int maxX;                      //!< The maximum distance from the origin in X
62  int minY;                      //!< The minimum distance from the origin in Y
63  int maxY;                      //!< The maximum distance from the origin in Y
64  int width;                     //!< The width of the Glyph
65  int height;                    //!< The height of the Glyph
66  int bearingX;                  //!< How much is right of the Origin
67  int bearingY;                  //!< How much is above the Origin
68  int advance;                   //!< How big a Glyph would be in monospace-mode
69 
70  // OpenGL-specific
71  //  TexCoord texCoord;             //!< A Texture Coordinate for this glyph.
72  GLuint displayList;            //!< DiplayList to render this Glyph.
73};
74
75//! A class to handle a Font
76class GLFont
77{
78 public:
79  GLFont(const char* fontFile);
80  virtual ~GLFont();
81
82  // general
83  static void enableFonts(void);
84  static void disableFonts(void);
85
86  // font
87  bool setFont(const char* fontFile);
88  void setSize(unsigned int fontSize);
89  void setColor(Uint8 r, Uint8 g, Uint8 b);
90
91  // text
92  void setBindNode(PNode* bindNode);
93  void setType(int type);
94  void setText(const char* text);
95  void setStyle(char* renderStyle);
96  void setPosition(int x, int y);
97  void createTexture(void);
98 
99  virtual void draw(void);
100
101 private:
102  // general purpose
103  GLdouble projMat[16];             //!< The Projection Matrix
104
105  // information about the Font
106  TTF_Font* font;                   //!< The font we use for this.
107  char* fontFile;                   //!< The fontfile from whitch the font was loaded.
108  unsigned int fontSize;            //!< The size of the font in pixels. each Font has one size.
109 
110  Glyph** glyphArray;               //!< An Array of all the Glyphs stored in the Array of Glyphs.
111  GLuint fastTextureID;             //!< The fast textureID.
112
113  //! Represents one textElement.
114  struct Text
115  {
116    int type;                   //!< The type of this Font.
117    char* text;                      //!< The text to display
118    SDL_Color color;                 //!< The color of the font.
119    // placement in openGL
120    GLuint texture;                  //!< A GL-texture to hold the text
121    TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
122    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
123    int renderStyle;                 //!< The Renderstyle
124
125    PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
126  };
127  tList<Text>* textList;
128  Text* currentText;
129
130  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
131  int getMaxHeight(void);
132  int getMaxAscent(void);
133  int getMaxDescent(void);
134  Glyph* getGlyphMetrics(Uint16 character);
135
136  static bool ttfInitialized;
137
138  void enter2DMode(void);
139  void leave2DMode(void);
140
141  static bool checkVersion(void);
142
143  GLuint createFastTexture();
144  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
145
146  void initGlyphs(Uint16 from, Uint16 count);
147  int findOptimalFastTextureSize(void);
148  static int powerOfTwo(int input);
149
150  void debug(void);
151
152};
153
154void m_inverse(const float *m, float *out);
155Vector mvMult(const float *mat, const Vector* vec);
156#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.