Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: now the Font is dynamical. See the fps :)

File size: 3.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
13/* some default values */
14#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
15#define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< some default text to display
16#define FONT_DEFAULT_COLOR_R    256                  //!< the default red part (color) of the text
17#define FONT_DEFAULT_COLOR_G    256                  //!< the default red green (color) of the text
18#define FONT_DEFAULT_COLOR_B    256                  //!< the default red blue (color) of the text
19#define FONT_NUM_COLORS         256                  //!< The number of colors.
20
21
22
23//! A struct for handling glyphs
24/**
25   a Glyph is one letter of a certain font
26*/
27struct Glyph
28{
29  Uint16 character;              //!< The character
30  int minX;                      //!< The minimum distance from the origin in X
31  int maxX;                      //!< The maximum distance from the origin in X
32  int minY;                      //!< The minimum distance from the origin in Y
33  int maxY;                      //!< The maximum distance from the origin in Y
34  int width;                     //!< The width of the Glyph
35  int height;                    //!< The height of the Glyph
36  int bearingX;                  //!< How much is right of the Origin
37  int bearingY;                  //!< How much is above the Origin
38  int advance;                   //!< How big a Glyph would be in monospace-mode
39};
40
41//! A Struct to handel Texture Coordinates for quads
42struct TexCoord
43{
44  float minU;                      //!< The minimum U-Coordinate
45  float maxU;                      //!< The maximum U-Coordinate
46  float minV;                      //!< The minimum V-Coordinate
47  float maxV;                      //!< The maximum V-Coordinate
48};
49
50//! A class to handle a Font
51class GLFont
52{
53 public:
54  GLFont(const char* fontFile);
55  virtual ~GLFont();
56
57  static void enableFonts(void);
58  static void disableFonts(void);
59
60  bool setFont(const char* fontFile);
61  void setText(const char* text);
62
63  void setStyle(char* renderStyle);
64  void setSize(unsigned int fontSize);
65  void setColor(Uint8 r, Uint8 g, Uint8 b);
66  void setPosition(int x, int y);
67
68  void createTexture(void);
69 
70  virtual void draw(void);
71
72 private:
73  // information about the Font
74  TTF_Font* font;                  //!< The font we use for this.
75  char* fontFile;                  //!< The fontfile from whitch the font was loaded.
76  char* text;                      //!< The text to display
77  unsigned int fontSize;           //!< The size of the font in pixels
78  SDL_Color color;                 //!< The color of the font.
79
80  // placement in openGL
81  GLuint texture;                  //!< A GL-texture to hold the text
82  SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
83  int renderStyle;                 //!< The Renderstyle
84  TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
85
86  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
87  int getMaxHeight(void);
88  int getMaxAscent(void);
89  int getMaxDescent(void);
90  Glyph getGlyphMetrics(Uint16 character);
91
92  static bool ttfInitialized;
93
94  void enter2DMode(void);
95  void leave2DMode(void);
96
97  static bool checkVersion(void);
98
99  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
100
101  static int powerOfTwo(int input);
102
103  void debug(void);
104
105};
106
107#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.