Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: minor

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