Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/textEngine: packed some parameters for texts into a Struct, to build a List of texts.

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