Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/textEngine: doxygen tags, some minor fix

File size: 2.9 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 class to handle a Font
42class GLFont
43{
44 public:
45  GLFont(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
46  virtual ~GLFont();
47
48  static void enableFonts(void);
49  static void disableFonts(void);
50
51  bool setFont(const char* fontFile);
52  void setText(const char* text);
53
54  void setStyle(char* renderStyle);
55  void setSize(unsigned int fontSize);
56  void setColor(Uint8 r, Uint8 g, Uint8 b);
57  void setPosition(int x, int y);
58
59  void createTexture(void);
60 
61  void renderText(void);
62  void renderText(const char* text, int x, int y);
63
64  virtual void draw(void);
65
66 private:
67  // information about the Font
68  TTF_Font* font;
69  char* fontFile;
70  char* text;
71  unsigned int fontSize;
72  SDL_Color color;
73
74  // placement in openGL
75  GLuint texture;
76  SDL_Rect textPosSize;               //!< A SDL-Rectangle representing the position and size of the Text on the screen.
77  int positionX;
78  int positionY;
79  int width;
80  int height;
81  int renderStyle;
82  SDL_Surface* surface;
83  GLfloat* texcoord;
84
85  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
86  int getMaxHeight(void);
87  int getMaxAscent(void);
88  int getMaxDescent(void);
89  Glyph getGlyphMetrics(Uint16 character);
90
91  static bool ttfInitialized;
92
93  void enter2DMode(void);
94  void leave2DMode(void);
95
96  static bool checkVersion(void);
97
98  GLuint loadTexture(SDL_Surface* surface, GLfloat* texcoord);
99
100  static int powerOfTwo(int input);
101
102  void debug(void);
103
104};
105
106#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.