Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: some new functions to get the optimum size (sqare) of the FastTexture-Array, and to initialize all the Glyphs

File size: 4.5 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};
60
61//! A class to handle a Font
62class GLFont
63{
64 public:
65  GLFont(const char* fontFile);
66  virtual ~GLFont();
67
68  // general
69  static void enableFonts(void);
70  static void disableFonts(void);
71
72  // font
73  bool setFont(const char* fontFile);
74  void setSize(unsigned int fontSize);
75  void setColor(Uint8 r, Uint8 g, Uint8 b);
76
77  // text
78  void setBindNode(PNode* bindNode);
79  void setText(const char* text);
80  void setStyle(char* renderStyle);
81  void setPosition(int x, int y);
82  void createTexture(void);
83 
84  virtual void draw(void);
85
86 private:
87  // general purpose
88  GLdouble projMat[16];             //!< The Projection Matrix
89
90  // information about the Font
91  TTF_Font* font;                   //!< The font we use for this.
92  char* fontFile;                   //!< The fontfile from whitch the font was loaded.
93  unsigned int fontSize;            //!< The size of the font in pixels. each Font has one size.
94 
95  Glyph** glyphArray;               //!< An Array of all the Glyphs stored in the Array of Glyphs.
96
97  //! Represents one textElement.
98  struct Text
99  {
100    char* text;                      //!< The text to display
101    SDL_Color color;                 //!< The color of the font.
102    // placement in openGL
103    GLuint texture;                  //!< A GL-texture to hold the text
104    TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
105    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
106    int renderStyle;                 //!< The Renderstyle
107
108    PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
109  };
110  tList<Text>* textList;
111  Text* currentText;
112
113  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
114  int getMaxHeight(void);
115  int getMaxAscent(void);
116  int getMaxDescent(void);
117  Glyph* getGlyphMetrics(Uint16 character);
118
119  static bool ttfInitialized;
120
121  void enter2DMode(void);
122  void leave2DMode(void);
123
124  static bool checkVersion(void);
125
126  GLuint createFastTexture();
127  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
128
129  void initGlyphs(Uint16 from, Uint16 count);
130  int findOptimalFastTextureSize(void);
131  static int powerOfTwo(int input);
132
133  void debug(void);
134
135};
136
137void m_inverse(const float *m, float *out);
138Vector mvMult(const float *mat, const Vector* vec);
139#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.