Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: minor change and doxy-tags

File size: 3.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
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);
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  virtual void draw(void);
62
63 private:
64  // information about the Font
65  TTF_Font* font;                  //!< The font we use for this.
66  char* fontFile;                  //!< The fontfile from whitch the font was loaded.
67  char* text;                      //!< The text to display
68  unsigned int fontSize;           //!< The size of the font in pixels
69  SDL_Color color;                 //!< The color of the font.
70
71  // placement in openGL
72  GLuint texture;                  //!< A GL-texture to hold the text
73  SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
74  int renderStyle;                 //!< The Renderstyle
75  GLfloat* texcoord;               //!< Texture-coordinates \todo fix this to have a struct
76
77  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
78  int getMaxHeight(void);
79  int getMaxAscent(void);
80  int getMaxDescent(void);
81  Glyph getGlyphMetrics(Uint16 character);
82
83  static bool ttfInitialized;
84
85  void enter2DMode(void);
86  void leave2DMode(void);
87
88  static bool checkVersion(void);
89
90  GLuint loadTexture(SDL_Surface* surface, GLfloat* texcoord);
91
92  static int powerOfTwo(int input);
93
94  void debug(void);
95
96};
97
98#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.