Changeset 5343 in orxonox.OLD for trunk/src/lib/graphics/text_engine/text_engine.h
- Timestamp:
- Oct 10, 2005, 12:16:19 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/text_engine.h
r5342 r5343 17 17 #define _TEXT_ENGINE_H 18 18 19 20 #include "glincl.h"21 22 #ifdef HAVE_SDL_TTF_H23 #include <SDL_ttf.h>24 #else25 #include <SDL/SDL_ttf.h>26 #endif27 28 19 #include "base_object.h" 29 #include "element_2d.h" 20 #include "font.h" 21 #include "text.h" 30 22 31 23 #include "vector.h" … … 34 26 class PNode; 35 27 class Font; 36 37 #define TEXT_ALIGN_LEFT E2D_ALIGN_LEFT38 #define TEXT_ALIGN_RIGHT E2D_ALIGN_RIGHT39 #define TEXT_ALIGN_CENTER E2D_ALIGN_CENTER40 #define TEXT_ALIGN_SCREEN_CENTER E2D_ALIGN_SCREEN_CENTER41 #define TEXT_DEFAULT_COLOR Vector(1.0, 1.0, 1.0) //!< the default Color (white)42 #define TEXT_DEFAULT_BLENDING 1.0f //!< the default blending of the text, (no blending at all)43 44 /* some default values */45 #define FONT_DEFAULT_SIZE 50 //!< default size of the Text46 #define FONT_NUM_COLORS 256 //!< number of colors.47 48 #define FONT_HIGHEST_KNOWN_CHAR 128 //!< The highest character known to the textEngine.49 50 #define TEXT_DEFAULT_ALIGNMENT TEXT_ALIGN_CENTER //!< default alignment51 52 typedef enum TEXT_RENDER_TYPE53 {54 TEXT_RENDER_STATIC = 1,55 TEXT_RENDER_DYNAMIC = 256 };57 /**58 * STATIC means: a font, that is only one GL-face.59 ** it is very fast, and can be used for all text60 ** that does not have to be changed anymore, or if61 ** the the text should look very nice62 * DYNAMIC means: a very fast font, that will is build63 ** from multiple quads.64 ** Use this type, if you want to create fast changing65 ** text like a counter.66 */67 68 69 //! A Struct to handel Texture Coordinates for quads70 struct TexCoord71 {72 float minU; //!< The minimum U-Coordinate73 float maxU; //!< The maximum U-Coordinate74 float minV; //!< The minimum V-Coordinate75 float maxV; //!< The maximum V-Coordinate76 };77 78 //! A struct for handling glyphs79 /**80 a Glyph is one letter of a certain font81 */82 struct Glyph83 {84 // Glyph-specific (size and so on)85 Uint16 character; //!< The character86 int minX; //!< The minimum distance from the origin in X87 int maxX; //!< The maximum distance from the origin in X88 int minY; //!< The minimum distance from the origin in Y89 int maxY; //!< The maximum distance from the origin in Y90 int width; //!< The width of the Glyph91 int height; //!< The height of the Glyph92 int bearingX; //!< How much is right of the Origin93 int bearingY; //!< How much is above the Origin94 int advance; //!< How big a Glyph would be in monospace-mode95 96 // OpenGL-specific97 // TexCoord texCoord; //!< A Texture Coordinate for this glyph.98 GLuint displayList; //!< DiplayList to render this Glyph.99 };100 101 ////////////102 /// TEXT ///103 ////////////104 //! Represents one textElement.105 class Text : public Element2D106 {107 friend class TextEngine;108 public:109 Text(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);110 ~Text();111 112 void init();113 114 void setFont(const char* fontFile, unsigned int fontSize);115 void setType(TEXT_RENDER_TYPE type);116 void setText(const char* text, bool isExtern = false);117 /** @returns the String this Text displays */118 inline const char* getText() const { return (externText == NULL)?this->text:this->externText; };119 /** @param blending the blending intensity to set (between 0.0 and 1.0) */120 inline void setBlending(float blending) { this->blending = blending; };121 122 /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */123 void setColor(float r, float g, float b) { this->color = Vector(r,g,b); };124 125 void createTexture();126 127 virtual void draw() const;128 129 void debug() const;130 131 // helpers.132 static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);133 static int powerOfTwo(int input);134 135 private:136 Text(Font* font = NULL, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);137 void setFont(Font* font);138 139 140 private:141 Font* font; //!< Font of this text142 143 TEXT_RENDER_TYPE type; //!< The type of this Font.144 char* text; //!< The text to display145 const char* externText; //!< the text to Display from an external Source.146 Vector color; //!< The color of the font.147 float blending; //!< The blending intensity.148 149 // placement in openGL150 GLuint texture; //!< A GL-texture to hold the text151 TexCoord texCoord; //!< Texture-coordinates @todo fix this to have a struct152 float height;153 float width;154 };155 156 ////////////157 /// FONT ///158 ////////////159 //! A class to handle a Font of a certain ttf-File, Size and Color.160 class Font : public BaseObject161 {162 friend class Text;163 164 public:165 Font(const char* fontFile,166 unsigned int fontSize = FONT_DEFAULT_SIZE);167 Font(char** xpmArray);168 virtual ~Font();169 170 void init();171 172 // font173 bool loadFont(const char* fontFile);174 bool loadFontFromSDL_Surface(SDL_Surface* surface);175 176 void setSize(unsigned int fontSize);177 void setStyle(const char* renderStyle);178 179 /** @returns a Pointer to the Array of Glyphs */180 inline Glyph** getGlyphArray() const { return this->glyphArray; };181 /** @returns the texture to the fast-texture */182 inline GLuint getFastTextureID() const { return this->fastTextureID; };183 /** @returns the default Font */184 inline static Font* getDefaultFont() { return Font::defaultFont; };185 186 void createAsciiImage(const char* fileName);187 static void initDefaultFont();188 static void removeDefaultFont();189 190 private:191 int getMaxHeight();192 int getMaxAscent();193 int getMaxDescent();194 Glyph* getGlyphMetrics(Uint16 character);195 196 GLuint createFastTexture();197 198 void initGlyphs(Uint16 from, Uint16 count);199 int findOptimalFastTextureSize();200 201 void debug();202 203 private:204 static Font* defaultFont; //!< a default font, that is used, if other fonts were unable to be loaded.205 // information about the Font206 TTF_Font* font; //!< The font we use for this.207 unsigned int fontSize; //!< The size of the font in pixels. each Font has one size.208 int renderStyle; //!< The Renderstyle209 210 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs.211 GLuint fastTextureID; //!< The fast textureID.212 213 tList<Text>* textList; //!< A list of texts this Font is mapped to.214 };215 28 216 29 /////////////////// … … 226 39 227 40 Text* createText(const char* fontFile, 228 unsigned int fontSize = FONT_DEFAULT_SIZE,41 unsigned int fontSize = TEXT_DEFAULT_SIZE, 229 42 int textType = TEXT_RENDER_DYNAMIC); 230 43
Note: See TracChangeset
for help on using the changeset viewer.