Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: added bind-node ability, so now the text tries to follow a given PNode (currently trackNode)
the work is not finished, so do not expect too much

File size: 4.1 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
28//! A struct for handling glyphs
29/**
30   a Glyph is one letter of a certain font
31*/
32struct Glyph
33{
34  Uint16 character;              //!< The character
35  int minX;                      //!< The minimum distance from the origin in X
36  int maxX;                      //!< The maximum distance from the origin in X
37  int minY;                      //!< The minimum distance from the origin in Y
38  int maxY;                      //!< The maximum distance from the origin in Y
39  int width;                     //!< The width of the Glyph
40  int height;                    //!< The height of the Glyph
41  int bearingX;                  //!< How much is right of the Origin
42  int bearingY;                  //!< How much is above the Origin
43  int advance;                   //!< How big a Glyph would be in monospace-mode
44};
45
46//! A Struct to handel Texture Coordinates for quads
47struct TexCoord
48{
49  float minU;                      //!< The minimum U-Coordinate
50  float maxU;                      //!< The maximum U-Coordinate
51  float minV;                      //!< The minimum V-Coordinate
52  float maxV;                      //!< The maximum V-Coordinate
53};
54
55//! A class to handle a Font
56class GLFont
57{
58 public:
59  GLFont(const char* fontFile);
60  virtual ~GLFont();
61
62  // general
63  static void enableFonts(void);
64  static void disableFonts(void);
65
66  // font
67  bool setFont(const char* fontFile);
68  void setSize(unsigned int fontSize);
69  void setColor(Uint8 r, Uint8 g, Uint8 b);
70
71  // text
72  void setBindNode(PNode* bindNode);
73  void setText(const char* text);
74  void setStyle(char* renderStyle);
75  void setPosition(int x, int y);
76  void createTexture(void);
77 
78  virtual void draw(void);
79
80 private:
81  // general purpose
82  GLdouble projMat[16];             //!< The Projection Matrix
83
84  // information about the Font
85  TTF_Font* font;                  //!< The font we use for this.
86  char* fontFile;                  //!< The fontfile from whitch the font was loaded.
87  unsigned int fontSize;           //!< The size of the font in pixels. each Font has one size.
88
89  //! Represents one textElement.
90  struct Text
91  {
92    char* text;                      //!< The text to display
93    SDL_Color color;                 //!< The color of the font.
94    // placement in openGL
95    GLuint texture;                  //!< A GL-texture to hold the text
96    TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
97    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
98    int renderStyle;                 //!< The Renderstyle
99
100    PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
101  };
102  tList<Text>* textList;
103  Text* currentText;
104
105  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
106  int getMaxHeight(void);
107  int getMaxAscent(void);
108  int getMaxDescent(void);
109  Glyph getGlyphMetrics(Uint16 character);
110
111  static bool ttfInitialized;
112
113  void enter2DMode(void);
114  void leave2DMode(void);
115
116  static bool checkVersion(void);
117
118  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
119
120  static int powerOfTwo(int input);
121
122  void debug(void);
123
124};
125
126void m_inverse(const float *m, float *out);
127Vector mvMult(const float *mat, const Vector* vec);
128#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.