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
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
[3714]12// FORWARD DECLARATION
13template<class T> class tList;
[3691]14
[3693]15/* some default values */
[3707]16#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
[3694]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
[3700]21#define FONT_NUM_COLORS         256                  //!< The number of colors.
[3693]22
23
24
[3691]25//! A struct for handling glyphs
[3694]26/**
27   a Glyph is one letter of a certain font
28*/
29struct Glyph
[3691]30{
[3694]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
[3691]41};
42
[3700]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
[3694]52//! A class to handle a Font
[3478]53class GLFont
54{
55 public:
[3696]56  GLFont(const char* fontFile);
[3691]57  virtual ~GLFont();
[3478]58
[3691]59  static void enableFonts(void);
60  static void disableFonts(void);
[3478]61
62  bool setFont(const char* fontFile);
63  void setText(const char* text);
64
[3691]65  void setStyle(char* renderStyle);
[3692]66  void setSize(unsigned int fontSize);
67  void setColor(Uint8 r, Uint8 g, Uint8 b);
[3478]68  void setPosition(int x, int y);
[3692]69
70  void createTexture(void);
[3478]71 
[3693]72  virtual void draw(void);
73
[3478]74 private:
[3691]75  // information about the Font
[3696]76  TTF_Font* font;                  //!< The font we use for this.
77  char* fontFile;                  //!< The fontfile from whitch the font was loaded.
[3714]78  unsigned int fontSize;           //!< The size of the font in pixels. each Font has one size.
[3691]79
[3714]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;
[3478]93
[3693]94  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
[3691]95  int getMaxHeight(void);
96  int getMaxAscent(void);
97  int getMaxDescent(void);
[3694]98  Glyph getGlyphMetrics(Uint16 character);
[3478]99
100  static bool ttfInitialized;
101
[3682]102  void enter2DMode(void);
103  void leave2DMode(void);
104
[3691]105  static bool checkVersion(void);
106
[3700]107  GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
[3682]108
[3691]109  static int powerOfTwo(int input);
[3682]110
[3691]111  void debug(void);
112
[3478]113};
114
115#endif /* _GLFONT_H */
Note: See TracBrowser for help on using the repository browser.