Changeset 8751 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jun 23, 2006, 6:12:07 PM (18 years ago)
- Location:
- trunk/src/lib/graphics
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/Makefile.am
r8619 r8751 18 18 text_engine/limited_width_text.cc \ 19 19 text_engine/font.cc \ 20 text_engine/font_data.cc \ 20 21 \ 21 22 effects/graphics_effect.cc \ … … 31 32 effects/lense_flare.cc 32 33 33 noinst_HEADERS = graphics_engine.h \ 34 light.h \ 35 shader.h \ 36 \ 37 render2D/render_2d.h \ 38 render2D/element_2d.h \ 39 render2D/image_plane.h \ 40 \ 41 text_engine/text_engine.h \ 42 text_engine/text.h \ 43 text_engine/multi_line_text.h \ 44 text_engine/limited_width_text.h \ 45 text_engine/font.h \ 46 text_engine/default_font.xpm \ 47 \ 48 effects/graphics_effect.h \ 49 effects/atmospheric_engine.h \ 50 effects/weather_effect.h \ 51 effects/sun_effect.h \ 52 effects/fog_effect.h \ 53 effects/volfog_effect.h \ 54 effects/rain_effect.h \ 55 effects/snow_effect.h \ 56 effects/cloud_effect.h \ 57 effects/lightening_effect.h \ 58 effects/lense_flare.h 34 noinst_HEADERS =\ 35 graphics_engine.h \ 36 light.h \ 37 shader.h \ 38 \ 39 render2D/render_2d.h \ 40 render2D/element_2d.h \ 41 render2D/image_plane.h \ 42 \ 43 text_engine/text_engine.h \ 44 text_engine/text.h \ 45 text_engine/multi_line_text.h \ 46 text_engine/limited_width_text.h \ 47 text_engine/font.h \ 48 text_engine/font_data.h \ 49 text_engine/default_font.xpm \ 50 \ 51 effects/graphics_effect.h \ 52 effects/atmospheric_engine.h \ 53 effects/weather_effect.h \ 54 effects/sun_effect.h \ 55 effects/fog_effect.h \ 56 effects/volfog_effect.h \ 57 effects/rain_effect.h \ 58 effects/snow_effect.h \ 59 effects/cloud_effect.h \ 60 effects/lightening_effect.h \ 61 effects/lense_flare.h 59 62 60 63 -
trunk/src/lib/graphics/importer/texture_data.h
r8363 r8751 1 1 /*! 2 * @file texture .h2 * @file texture_data.h 3 3 * @brief Contains the texture class, that handles the reading of Images into Texutre-files. 4 4 */ -
trunk/src/lib/graphics/text_engine/font.cc
r8316 r8751 37 37 */ 38 38 Font::Font(const std::string& fontFile, unsigned int renderSize) 39 : data(new FontData()) 39 40 { 40 41 this->init(); 41 42 42 this->renderSize = renderSize; 43 44 this->data->renderSize = renderSize; 43 45 this->setStyle("c"); 44 46 … … 52 54 */ 53 55 Font::Font(const std::string& imageFile) 56 : data(new FontData()) 54 57 { 55 58 this->init(); … … 75 78 */ 76 79 Font::Font(char** xpmArray) 80 : data(new FontData()) 77 81 { 78 82 this->init(); … … 99 103 */ 100 104 Font::~Font() 101 { 102 // deleting all Glyphs 103 if (this->glyphArray != NULL) 104 { 105 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 106 { 107 if (this->glyphArray[i] != NULL) 108 delete this->glyphArray[i]; 109 } 110 delete[] this->glyphArray; 111 } 112 113 //! @todo check if we really do not need to delete the fastTextureID here. 114 // if (this->fastTextureID != 0) 115 // if(glIsTexture(this->fastTextureID)) 116 // glDeleteTextures(1, &this->fastTextureID); 117 118 // erease this font out of the memory. 119 if (likely(this->fontTTF != NULL)) 120 TTF_CloseFont(this->fontTTF); 121 } 105 { } 122 106 123 107 /** … … 127 111 { 128 112 this->setClassID(CL_FONT, "Font"); 129 // setting default values. 130 this->fontTTF = NULL; 131 this->glyphArray = NULL; 132 } 133 134 135 /** 136 * sets The Font. 113 } 114 115 116 /** 117 * @brief sets The Font. 137 118 * @param fontFile The file containing the font. 138 119 * @returns true if loaded, false if something went wrong, or if a font was loaded before. … … 141 122 { 142 123 // checking for existent Font. 143 if (this-> fontTTF != NULL)144 { 145 TTF_CloseFont(this-> fontTTF);146 this-> fontTTF = NULL;124 if (this->data->fontTTF != NULL) 125 { 126 TTF_CloseFont(this->data->fontTTF); 127 this->data->fontTTF = NULL; 147 128 } 148 129 149 130 150 131 this->setName(fontFile); 151 this-> fontTTF = TTF_OpenFont(this->getName(), this->renderSize);152 153 if(this-> fontTTF != NULL)132 this->data->fontTTF = TTF_OpenFont(this->getName(), this->data->renderSize); 133 134 if(this->data->fontTTF != NULL) 154 135 { 155 136 this->createFastTexture(); … … 174 155 return false; 175 156 176 if (this-> fontTTF != NULL)177 { 178 TTF_CloseFont(this-> fontTTF);179 this-> fontTTF = NULL;157 if (this->data->fontTTF != NULL) 158 { 159 TTF_CloseFont(this->data->fontTTF); 160 this->data->fontTTF = NULL; 180 161 } 181 162 bool hasAlpha; … … 189 170 190 171 // initializing the Glyphs. 191 if (this-> glyphArray == NULL)172 if (this->data->glyphArray == NULL) 192 173 { 193 174 float cx,cy; 194 175 Glyph* tmpGlyph; 195 this-> glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];176 this->data->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR]; 196 177 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 197 178 { 198 tmpGlyph = this-> glyphArray[i] = new Glyph;179 tmpGlyph = this->data->glyphArray[i] = new Glyph; 199 180 cx=(float)(i%16)/16.0f; // X Position Of Current Character 200 181 cy=(float)(i/16)/16.0f; // Y Position Of Current Character … … 220 201 221 202 /** 222 * @brief sets a specific renderStyle223 * @param renderStyle the Style to render: a string (char-array) containing:203 * @brief sets a specific data->renderStyle 204 * @param data->renderStyle the Style to render: a string (char-array) containing: 224 205 * i: italic, b: bold, u, underline 225 206 */ 226 207 void Font::setStyle(const std::string& renderStyle) 227 208 { 228 this-> renderStyle = TTF_STYLE_NORMAL;209 this->data->renderStyle = TTF_STYLE_NORMAL; 229 210 230 211 for (unsigned int i = 0; i < renderStyle.size(); i++) 231 212 { 232 213 if (renderStyle[i] == 'b') 233 this-> renderStyle |= TTF_STYLE_BOLD;214 this->data->renderStyle |= TTF_STYLE_BOLD; 234 215 else if (renderStyle[i] == 'i') 235 this-> renderStyle |= TTF_STYLE_ITALIC;216 this->data->renderStyle |= TTF_STYLE_ITALIC; 236 217 else if (renderStyle[i] == 'u') 237 this-> renderStyle |= TTF_STYLE_UNDERLINE;238 } 239 if (likely(this-> fontTTF != NULL))240 TTF_SetFontStyle(this-> fontTTF, this->renderStyle);218 this->data->renderStyle |= TTF_STYLE_UNDERLINE; 219 } 220 if (likely(this->data->fontTTF != NULL)) 221 TTF_SetFontStyle(this->data->fontTTF, this->data->renderStyle); 241 222 // else 242 223 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); … … 252 233 void Font::createAsciiImage(const std::string& fileName, unsigned int size) const 253 234 { 254 if (this-> fontTTF == NULL)235 if (this->data->fontTTF == NULL) 255 236 return; 256 237 int height = this->getMaxHeight(); … … 284 265 { 285 266 SDL_Surface* glyphSurf = NULL; 286 if (likely(this-> fontTTF != NULL))267 if (likely(this->data->fontTTF != NULL)) 287 268 { 288 269 SDL_Color white = {255, 255, 255}; 289 glyphSurf = TTF_RenderGlyph_Blended(this-> fontTTF, posX+size*posY, white);270 glyphSurf = TTF_RenderGlyph_Blended(this->data->fontTTF, posX+size*posY, white); 290 271 } 291 272 if( glyphSurf != NULL ) … … 329 310 int Font::getMaxHeight() const 330 311 { 331 if (likely (this-> fontTTF != NULL))332 return TTF_FontHeight(this-> fontTTF);312 if (likely (this->data->fontTTF != NULL)) 313 return TTF_FontHeight(this->data->fontTTF); 333 314 else 334 315 return 1; … … 342 323 int Font::getMaxAscent() const 343 324 { 344 if (likely(this-> fontTTF != NULL))345 return TTF_FontAscent(this-> fontTTF);325 if (likely(this->data->fontTTF != NULL)) 326 return TTF_FontAscent(this->data->fontTTF); 346 327 else 347 328 return 0; … … 355 336 int Font::getMaxDescent() const 356 337 { 357 if (likely(this-> fontTTF != NULL))358 return TTF_FontDescent(this-> fontTTF);338 if (likely(this->data->fontTTF != NULL)) 339 return TTF_FontDescent(this->data->fontTTF); 359 340 else 360 341 return 0; … … 374 355 { 375 356 glyph->character = character; 376 if (likely (this-> fontTTF!= NULL))357 if (likely (this->data->fontTTF!= NULL)) 377 358 { 378 359 int miX, maX, miY, maY, adv; 379 if (TTF_GlyphMetrics(this-> fontTTF, glyph->character,360 if (TTF_GlyphMetrics(this->data->fontTTF, glyph->character, 380 361 &miX, &maX, 381 362 &miY, &maY, 382 363 &adv) == -1) 383 364 return false; 384 glyph->minX = (float)miX / (float)this-> renderSize;385 glyph->maxX = (float)maX / (float)this-> renderSize;386 glyph->minY = (float)miY / (float)this-> renderSize;387 glyph->maxY = (float)maY / (float)this-> renderSize;388 glyph->advance = (float)adv / (float)this-> renderSize;365 glyph->minX = (float)miX / (float)this->data->renderSize; 366 glyph->maxX = (float)maX / (float)this->data->renderSize; 367 glyph->minY = (float)miY / (float)this->data->renderSize; 368 glyph->maxY = (float)maY / (float)this->data->renderSize; 369 glyph->advance = (float)adv / (float)this->data->renderSize; 389 370 390 371 // Calculate the Rest. … … 417 398 418 399 this->initGlyphs(32, numberOfGlyphs); 419 // this-> glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space400 // this->data->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space 420 401 421 402 int rectSize = this->findOptimalFastTextureSize(); … … 450 431 Glyph* tmpGlyph; 451 432 452 if (tmpGlyph = this-> glyphArray[i])433 if (tmpGlyph = this->data->glyphArray[i]) 453 434 { 454 if (tmpGlyph->height*this-> renderSize > maxLineHeight)455 maxLineHeight = (int)(tmpGlyph->height*this-> renderSize);456 457 if (tmpRect.x+tmpGlyph->advance*this-> renderSize > tmpSurf->w)435 if (tmpGlyph->height*this->data->renderSize > maxLineHeight) 436 maxLineHeight = (int)(tmpGlyph->height*this->data->renderSize); 437 438 if (tmpRect.x+tmpGlyph->advance*this->data->renderSize > tmpSurf->w) 458 439 { 459 440 tmpRect.x = 0; … … 466 447 } 467 448 // reading in the new Glyph 468 if (likely(this-> fontTTF != NULL))449 if (likely(this->data->fontTTF != NULL)) 469 450 { 470 451 SDL_Color white = {255, 255, 255}; 471 glyphSurf = TTF_RenderGlyph_Blended(this-> fontTTF, i, white);452 glyphSurf = TTF_RenderGlyph_Blended(this->data->fontTTF, i, white); 472 453 } 473 454 if( glyphSurf != NULL ) … … 475 456 SDL_SetAlpha(glyphSurf, 0, 0); 476 457 int tmpY = tmpRect.y; 477 tmpRect.y += this->getMaxAscent()-(int)((float)tmpGlyph->bearingY*this-> renderSize);458 tmpRect.y += this->getMaxAscent()-(int)((float)tmpGlyph->bearingY*this->data->renderSize); 478 459 SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect); 479 460 tmpRect.y = tmpY; 480 461 481 462 tmpGlyph->texCoord[0] = (float)((float)tmpRect.x )/(float)tmpSurf->w; 482 tmpGlyph->texCoord[1] = (float)((float)tmpRect.x + tmpGlyph->width*(float)this-> renderSize)/(float)tmpSurf->w;463 tmpGlyph->texCoord[1] = (float)((float)tmpRect.x + tmpGlyph->width*(float)this->data->renderSize)/(float)tmpSurf->w; 483 464 tmpGlyph->texCoord[2] = (float)(tmpRect.y)/(float)tmpSurf->w; 484 465 tmpGlyph->texCoord[3] = (float)((float)tmpRect.y+(float)this->getMaxHeight())/(float)tmpSurf->w; 485 466 SDL_FreeSurface(glyphSurf); 486 tmpRect.x += (int)(tmpGlyph->width * this-> renderSize) + 1;467 tmpRect.x += (int)(tmpGlyph->width * this->data->renderSize) + 1; 487 468 } 488 469 } … … 508 489 * only if the Glyph-array has not been initialized 509 490 */ 510 if (!this-> glyphArray)511 { 512 this-> glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];491 if (!this->data->glyphArray) 492 { 493 this->data->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR]; 513 494 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 514 this-> glyphArray[i] = NULL;495 this->data->glyphArray[i] = NULL; 515 496 } 516 497 … … 522 503 Glyph* newGlyph = new Glyph; 523 504 if (getGlyphMetrics(newGlyph, i)) 524 glyphArray[i] = newGlyph;505 data->glyphArray[i] = newGlyph; 525 506 else 526 507 { 527 508 delete newGlyph; 528 glyphArray[i] = NULL;509 data->glyphArray[i] = NULL; 529 510 } 530 511 } … … 543 524 int Font::findOptimalFastTextureSize() 544 525 { 545 if (this-> glyphArray == NULL)526 if (this->data->glyphArray == NULL) 546 527 return 0; 547 528 … … 558 539 for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 559 540 { 560 if((tmpGlyph = this-> glyphArray[i]) != NULL)541 if((tmpGlyph = this->data->glyphArray[i]) != NULL) 561 542 { 562 543 // getting the height of the highest Glyph in the Line. 563 if (tmpGlyph->height*this-> renderSize > maxLineHeight)564 maxLineHeight = (int)(tmpGlyph->height*this-> renderSize);565 566 if (x + tmpGlyph->advance*this-> renderSize > size)544 if (tmpGlyph->height*this->data->renderSize > maxLineHeight) 545 maxLineHeight = (int)(tmpGlyph->height*this->data->renderSize); 546 547 if (x + tmpGlyph->advance*this->data->renderSize > size) 567 548 { 568 549 x = 0; … … 572 553 if (y + maxLineHeight + 1 > size) 573 554 break; 574 x += (int)(tmpGlyph->advance*this-> renderSize)+1;555 x += (int)(tmpGlyph->advance*this->data->renderSize)+1; 575 556 576 557 } … … 592 573 // print the loaded font's style 593 574 int style = TTF_STYLE_NORMAL; 594 if (likely(this-> fontTTF != NULL))595 style = TTF_GetFontStyle(this-> fontTTF);575 if (likely(this->data->fontTTF != NULL)) 576 style = TTF_GetFontStyle(this->data->fontTTF); 596 577 PRINTF(0)("The font style is:"); 597 578 if(style==TTF_STYLE_NORMAL) -
trunk/src/lib/graphics/text_engine/font.h
r7450 r8751 13 13 #include "texture.h" 14 14 15 #include "glincl.h" 16 17 18 #ifdef HAVE_SDL_TTF_H 19 #include <SDL_ttf.h> 20 #else 21 #include <SDL/SDL_ttf.h> 22 #endif 23 24 /* some default values */ 25 #define FONT_NUM_COLORS 256 //!< number of colors. 26 27 #define FONT_HIGHEST_KNOWN_CHAR 128 //!< The highest character known to the textEngine. 28 #define FONT_DEFAULT_RENDER_SIZE 50 //!< At what Resolution to render fonts. 29 // FORWARD DECLARATION 30 31 //! A struct for handling glyphs 32 /** 33 * a Glyph is one letter of a certain font 34 */ 35 struct Glyph 36 { 37 // Glyph-specific (size and so on) 38 Uint16 character; //!< The character 39 float minX; //!< The minimum distance from the origin in X 40 float maxX; //!< The maximum distance from the origin in X 41 float minY; //!< The minimum distance from the origin in Y 42 float maxY; //!< The maximum distance from the origin in Y 43 float width; //!< The width of the Glyph 44 float height; //!< The height of the Glyph 45 float bearingX; //!< How much is right of the Origin 46 float bearingY; //!< How much is above the Origin 47 float advance; //!< How big a Glyph would be in monospace-mode 48 49 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom. 50 }; 15 #include "font_data.h" 51 16 52 17 … … 54 19 class Font : public Texture 55 20 { 56 public: 57 Font(const std::string& fontFile, 58 unsigned int renderSize); 59 Font(const std::string& imageFile); 60 Font(char** xpmArray); 61 virtual ~Font(); 21 22 public: 23 Font(const std::string& fontFile, 24 unsigned int renderSize); 25 Font(const std::string& imageFile); 26 Font(char** xpmArray); 27 virtual ~Font(); 62 28 63 29 // font 64 65 30 bool loadFontFromTTF(const std::string& fontFile); 31 bool loadFontFromSDL_Surface(SDL_Surface* surface); 66 32 67 33 void setStyle(const std::string& renderStyle); 68 34 69 70 inline Glyph** getGlyphArray() const { return this->glyphArray; };71 72 inline TTF_Font* getTTF() const { return this->fontTTF; };35 /** @returns a Pointer to the Array of Glyphs */ 36 inline Glyph** getGlyphArray() const { return this->data->getGlyphArray(); }; 37 /** @returns the a pointer to the TTF */ 38 inline TTF_Font* getTTF() const { return this->data->getTTF(); }; 73 39 74 75 76 40 int getMaxHeight() const; 41 int getMaxAscent() const; 42 int getMaxDescent() const; 77 43 78 79 44 /** @returns the default Font */ 45 inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; }; 80 46 81 82 83 47 void createAsciiImage(const std::string& fileName, unsigned int size) const; 48 static void initDefaultFont(); 49 static void removeDefaultFont(); 84 50 85 private:86 void init();87 bool getGlyphMetrics(Glyph* glyph, Uint16 character);88 51 89 bool createFastTexture(); 52 private: 53 void init(); 54 bool getGlyphMetrics(Glyph* glyph, Uint16 character); 90 55 91 void initGlyphs(Uint16 from, Uint16 count); 92 int findOptimalFastTextureSize(); 56 bool createFastTexture(); 93 57 94 void debug(); 58 void initGlyphs(Uint16 from, Uint16 count); 59 int findOptimalFastTextureSize(); 95 60 96 private: 97 static Font* defaultFont; //!< a default font, that is used, if other fonts were unable to be loaded. 98 // information about the Font 99 TTF_Font* fontTTF; //!< The font we use for this. 100 int renderStyle; //!< The Renderstyle 101 unsigned int renderSize; //!< How big the Font should be rendered. 61 void debug(); 102 62 103 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. 63 private: 64 static Font* defaultFont; //!< a default font, that is used, if other fonts were unable to be loaded. 65 66 fontDataPointer data; 104 67 }; 105 68 -
trunk/src/lib/graphics/text_engine/font_data.cc
r8749 r8751 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER 17 17 18 #include " texture.h"18 #include "font_data.h" 19 19 20 20 #include "debug.h" … … 24 24 25 25 /** 26 * @brief creates a new TextureData.26 * @brief creates a new Font Data. 27 27 */ 28 TextureData::TextureData()28 FontData::FontData() 29 29 { 30 this->bAlpha = false; 31 this->texture = 0; 32 this->image = NULL; 30 this->fontTTF = NULL; 31 this->glyphArray = NULL; 33 32 } 34 33 35 34 36 35 /** 37 * @brief Destructor of a Texture36 * @brief Destructor of a Font 38 37 * 39 * Frees Data, and deletes the textures from GL38 * Frees Data, and deletes the fonts from GL 40 39 */ 41 TextureData::~TextureData()40 FontData::~FontData() 42 41 { 43 if (this->texture != 0) 44 glDeleteTextures(1, &this->texture); 45 if (this->image != NULL) 46 SDL_FreeSurface(this->image); 42 // deleting all Glyphs 43 if (this->glyphArray != NULL) 44 { 45 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 46 { 47 if (this->glyphArray[i] != NULL) 48 delete this->glyphArray[i]; 49 } 50 delete[] this->glyphArray; 51 } 52 53 //! @todo check if we really do not need to delete the fastTextureID here. 54 // if (this->fastTextureID != 0) 55 // if(glIsTexture(this->fastTextureID)) 56 // glDeleteTextures(1, &this->fastTextureID); 57 58 // erease this font out of the memory. 59 if (likely(this->fontTTF != NULL)) 60 TTF_CloseFont(this->fontTTF); 47 61 } 48 62 49 63 50 /**51 * @brief Loads an SDL_Surface.52 * @param surface the Surface to Load.53 * @param target the GL-Target to load the Surface to default GL_TEXTURE_2D54 * @returns true on success, false otherwise.55 */56 bool TextureData::loadSurface(SDL_Surface* surface, GLenum target)57 {58 if (Texture::getTextureEnableState())59 {60 SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha);61 if (newSurf != NULL)62 {63 this->setSurface(newSurf);64 this->setTexture(Texture::loadTexToGL(newSurf, target));65 return true;66 }67 }68 return false;69 }70 71 72 73 /**74 * @brief set the surface this Texture handles75 * @param newSurface the new Surface to set as the image for this Texture.76 * @returns true on success.77 *78 * This deletes the old version of the stored Texture,79 * and sets the newly given Surface as current.80 */81 bool TextureData::setSurface(SDL_Surface* newSurface)82 {83 if (this->image != NULL)84 SDL_FreeSurface(this->image);85 86 this->image = newSurface;87 88 return (this->image != NULL);89 }90 91 92 /**93 * @brief sets a new Texture to the Data.94 * @param texture the Texture95 * @returns true on success.96 */97 bool TextureData::setTexture(GLuint texture)98 {99 // unload the old Texture.100 if (this->texture != 0 && glIsTexture(this->getTexture()))101 {102 glDeleteTextures(1, &this->texture);103 }104 this->texture = texture;105 return (texture != 0);106 } -
trunk/src/lib/graphics/text_engine/font_data.h
r8749 r8751 1 1 /*! 2 * @file texture.h3 * @brief Contains the textureclass, that handles the reading of Images into Texutre-files.2 * @file font_data.h 3 * @brief Contains the font-data class, that handles the reading of Images into Texutre-files. 4 4 */ 5 5 6 #ifndef _ TEXTURE_DATA_H7 #define _ TEXTURE_DATA_H6 #ifndef _FONT_DATA_H 7 #define _FONT_DATA_H 8 8 9 9 #include "base_object.h" 10 10 11 11 #include "glincl.h" 12 #include " count_pointer.h"12 #include "texture_data.h" 13 13 14 /* Forward Declaration */ 15 struct SDL_Surface; 14 #ifdef HAVE_SDL_TTF_H 15 #include <SDL_ttf.h> 16 #else 17 #include <SDL/SDL_ttf.h> 18 #endif 16 19 17 20 18 class TextureData 21 22 /* some default values */ 23 #define FONT_NUM_COLORS 256 //!< number of colors. 24 25 #define FONT_HIGHEST_KNOWN_CHAR 128 //!< The highest character known to the textEngine. 26 #define FONT_DEFAULT_RENDER_SIZE 50 //!< At what Resolution to render fonts. 27 28 //! A struct for handling glyphs 29 /** 30 * a Glyph is one letter of a certain font 31 */ 32 struct Glyph 19 33 { 20 public: 21 TextureData(); 22 ~TextureData(); 34 // Glyph-specific (size and so on) 35 Uint16 character; //!< The character 36 float minX; //!< The minimum distance from the origin in X 37 float maxX; //!< The maximum distance from the origin in X 38 float minY; //!< The minimum distance from the origin in Y 39 float maxY; //!< The maximum distance from the origin in Y 40 float width; //!< The width of the Glyph 41 float height; //!< The height of the Glyph 42 float bearingX; //!< How much is right of the Origin 43 float bearingY; //!< How much is above the Origin 44 float advance; //!< How big a Glyph would be in monospace-mode 23 45 24 inline GLuint getTexture() const { return this->texture; }; 25 /** @returns true if texture has alpha, false otherwise */ 26 inline bool hasAlpha() const {return this->bAlpha; } 27 /** @returns the stored image of this Texture */ 28 const SDL_Surface* const getStoredImage() const { return this->image; }; 29 30 bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 31 32 bool rebuild(); 33 34 bool setSurface(SDL_Surface* newSurface); 35 /** @returns true if the Surface has an Alpha Value. */ 36 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; return this->bAlpha; }; 37 bool setTexture(GLuint texture); 38 39 private: 40 GLuint texture; //!< The Texture-ID of opengl from this Texture. 41 bool bAlpha; //!< if the texture has an alpha channel. 42 SDL_Surface* image; //!< The SDL_Surfce that stores the Texture on it. 46 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom. 43 47 }; 44 48 45 #endif /* _TEXTURE_DATA_H */ 49 50 class FontData : public TextureData 51 { 52 friend class Font; 53 public: 54 FontData(); 55 ~FontData(); 56 57 58 /** @returns a Pointer to the Array of Glyphs */ 59 inline Glyph** getGlyphArray() const { return this->glyphArray; }; 60 /** @returns the a pointer to the TTF */ 61 inline TTF_Font* getTTF() const { return this->fontTTF; }; 62 63 bool rebuild(); 64 65 66 private: 67 TTF_Font* fontTTF; //!< The font we use for this. 68 int renderStyle; //!< The Renderstyle 69 unsigned int renderSize; //!< How big the Font should be rendered. 70 71 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. 72 }; 73 74 typedef CountPointer<FontData> fontDataPointer; 75 76 #endif /* _FONT_DATA_H */
Note: See TracChangeset
for help on using the changeset viewer.