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
RevLine 
[3478]1/*!
2    \file glfont.h
3    \brief Handles the display of glFonts.
4*/
5
6#ifndef _GLFONT_H
7#define _GLFONT_H
8
[3682]9#include "glincl.h"
[3691]10#include "SDL_ttf.h"
[3478]11
[3691]12
[3693]13/* some default values */
[3707]14#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
[3694]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
[3700]19#define FONT_NUM_COLORS         256                  //!< The number of colors.
[3693]20
21
22
[3691]23//! A struct for handling glyphs
[3694]24/**
25   a Glyph is one letter of a certain font
26*/
27struct Glyph
[3691]28{
[3694]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
[3691]39};
40
[3700]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
[3694]50//! A class to handle a Font
[3478]51class GLFont
52{
53 public:
[3696]54  GLFont(const char* fontFile);
[3691]55  virtual ~GLFont();
[3478]56
[3691]57  static void enableFonts(void);
58  static void disableFonts(void);
[3478]59
60  bool setFont(const char* fontFile);
61  void setText(const char* text);
62
[3691]63  void setStyle(char* renderStyle);
[3692]64  void setSize(unsigned int fontSize);
65  void setColor(Uint8 r, Uint8 g, Uint8 b);
[3478]66  void setPosition(int x, int y);
[3692]67
68  void createTexture(void);
[3478]69 
[3693]70  virtual void draw(void);
71
[3478]72 private:
[3691]73  // information about the Font
[3696]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.
[3691]79
80  // placement in openGL
[3696]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
[3700]84  TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
[3478]85
[3693]86  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
[3691]87  int getMaxHeight(void);
88  int getMaxAscent(void);
89  int getMaxDescent(void);
[3694]90  Glyph getGlyphMetrics(Uint16 character);
[3478]91
92  static bool ttfInitialized;
93
[3682]94  void enter2DMode(void);
95  void leave2DMode(void);
96
[3691]97  static bool checkVersion(void);
98
[3700]99  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
[3682]100
[3691]101  static int powerOfTwo(int input);
[3682]102
[3691]103  void debug(void);
104
[3478]105};
106
107#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.