Changeset 5347 in orxonox.OLD for trunk/src/lib/graphics/text_engine
- Timestamp:
- Oct 10, 2005, 3:07:04 AM (20 years ago)
- Location:
- trunk/src/lib/graphics/text_engine
- Files:
-
- 4 edited
- 1 moved
-
default_font.xpm (moved) (moved from trunk/src/lib/graphics/text_engine/font.xpm)
-
font.cc (modified) (14 diffs)
-
font.h (modified) (4 diffs)
-
text_engine.cc (modified) (2 diffs)
-
text_engine.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/font.cc
r5343 r5347 24 24 #include <SDL/SDL_image.h> 25 25 #endif 26 #include " font.xpm"26 #include "default_font.xpm" 27 27 28 28 #include "debug.h" … … 32 32 33 33 /** 34 * constructs a Font 34 * constructs a Font out of a TTF-FIle 35 35 * @param fontFile the File to load the font from 36 36 * @param fontSize the Size of the Font in Pixels … … 41 41 42 42 this->setSize(fontSize); 43 this->setStyle("c"); 43 44 44 45 if (fontFile != NULL) 45 46 this->loadFont(fontFile); 46 47 this->setStyle("c");//TTF_STYLE_NORMAL); 48 49 this->fastTextureID = this->createFastTexture(); 50 51 52 // this->createAsciiImage("test.bmp"); 47 } 48 49 /** 50 * constructs a Font out of an ImageFile 51 * @param imageFile the ImageFile to load the Font From. 52 */ 53 Font::Font(const char* imageFile) 54 { 55 this->init(); 56 this->setName(imageFile); 57 // this->setSize(fontSize); 58 SDL_Surface* image = NULL; 59 if (imageFile != NULL) 60 image = IMG_Load(imageFile); 61 else 62 return; 63 if (image != NULL) 64 { 65 this->loadFontFromSDL_Surface(image); 66 SDL_FreeSurface(image); 67 } 68 else 69 PRINTF(1)("loading from surface %s failed: %s\n", imageFile, IMG_GetError()); 53 70 } 54 71 55 72 /** 56 73 * constructs a Font 57 * @param fontFile the File to load the font from 58 * @param fontSize the Size of the Font in Pixels 74 * @param xpmArray the xpm-ARRAY to load the font from 59 75 */ 60 76 Font::Font(char** xpmArray) 61 77 { 62 78 this->init(); 63 79 this->setName("XPM-array-font"); 64 80 // this->setSize(fontSize); 65 81 SDL_Surface* image = NULL; … … 73 89 else 74 90 PRINTF(1)("loading from surface failed: %s\n", IMG_GetError()); 75 76 91 } 77 92 … … 91 106 if (this->glyphArray[i] != NULL) 92 107 { 93 glDeleteLists(this->glyphArray[i]->displayList, 1); 108 if (this->glyphArray[i]->displayList != 0) 109 glDeleteLists(this->glyphArray[i]->displayList, 1); 94 110 delete this->glyphArray[i]; 95 111 } … … 97 113 delete[] this->glyphArray; 98 114 } 115 116 //! @todo check if we really do not need to delete the fastTextureID here. 117 // if (this->fastTextureID != 0) 118 // if(glIsTexture(this->fastTextureID)) 119 // glDeleteTextures(1, &this->fastTextureID); 99 120 100 121 // erease this font out of the memory. … … 123 144 bool Font::loadFont(const char* fontFile) 124 145 { 125 if (!this->getName()) 126 { 127 this->setName(fontFile); 128 129 this->font = TTF_OpenFont(this->getName(), this->fontSize); 130 if(!this->font) 131 { 132 PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError()); 146 // checking for existent Font. 147 if (this->font != NULL) 148 { 149 TTF_CloseFont(this->font); 150 this->font = NULL; 151 } 152 if (this->fastTextureID != 0) 153 { 154 if(glIsTexture(this->fastTextureID)) 155 glDeleteTextures(1, &this->fastTextureID); 156 this->fastTextureID = 0; 157 } 158 159 this->setName(fontFile); 160 this->font = TTF_OpenFont(this->getName(), this->fontSize); 161 162 if(this->font != NULL) 163 { 164 this->fastTextureID = this->createFastTexture(); 165 if (this->fastTextureID != 0) 166 return true; 167 else 133 168 return false; 134 }135 else136 return true;137 169 } 138 170 else 139 171 { 140 PRINTF( 2)("Font already initialized, unable to change it now.\n");172 PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError()); 141 173 return false; 142 174 } 175 143 176 } 144 177 … … 152 185 if(surface == NULL) 153 186 return false; 187 188 if (this->font != NULL) 189 { 190 TTF_CloseFont(this->font); 191 this->font = NULL; 192 } 193 if (this->fastTextureID != 0) 194 { 195 if(glIsTexture(this->fastTextureID)) 196 glDeleteTextures(1, &this->fastTextureID); 197 this->fastTextureID = 0; 198 } 199 154 200 this->fastTextureID = Text::loadTexture(surface, NULL); 155 201 … … 195 241 /** 196 242 * sets a specific renderStyle 197 * @param renderStyle the Style to render: a char-arraycontaining:198 i: italic, b: bold, u, underline243 * @param renderStyle the Style to render: a string (char-array) containing: 244 * i: italic, b: bold, u, underline 199 245 */ 200 246 void Font::setStyle(const char* renderStyle) … … 212 258 if (likely(this->font != NULL)) 213 259 TTF_SetFontStyle(this->font, this->renderStyle); 214 else215 PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");260 // else 261 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); 216 262 } 217 263 … … 363 409 { 364 410 Glyph* rg = new Glyph; 411 rg->displayList = 0; 365 412 rg->character = character; 366 413 if (likely (this->font!= NULL)) … … 537 584 * @returns the optimal size to use as the texture size 538 585 539 @todo: this algorithm can be a lot morefaster, althought it does586 @todo: this algorithm can be a lot faster, althought it does 540 587 not really matter within the init-context, and 128 glyphs. 541 588 … … 545 592 int Font::findOptimalFastTextureSize() 546 593 { 594 if (this->glyphArray == NULL) 595 return 0; 596 547 597 int i; 548 598 int x,y; // the counters … … 555 605 { 556 606 x = 0; y = 0; 557 for (i = 0; i < =FONT_HIGHEST_KNOWN_CHAR; i++)607 for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 558 608 { 559 609 if((tmpGlyph = this->glyphArray[i]) != NULL) -
trunk/src/lib/graphics/text_engine/font.h
r5344 r5347 31 31 //! A struct for handling glyphs 32 32 /** 33 a Glyph is one letter of a certain font33 * a Glyph is one letter of a certain font 34 34 */ 35 35 struct Glyph … … 56 56 /// FONT /// 57 57 //////////// 58 //! A class to handle a Font of a certain ttf-File , Size and Color.58 //! A class to handle a Font of a certain ttf-File/image-file, Size. 59 59 class Font : public BaseObject 60 60 { … … 64 64 Font(const char* fontFile, 65 65 unsigned int fontSize); 66 Font(const char* imageFile); 66 67 Font(char** xpmArray); 67 68 virtual ~Font(); … … 102 103 private: 103 104 static Font* defaultFont; //!< a default font, that is used, if other fonts were unable to be loaded. 104 // information about the Font105 // information about the Font 105 106 TTF_Font* font; //!< The font we use for this. 106 107 unsigned int fontSize; //!< The size of the font in pixels. each Font has one size. -
trunk/src/lib/graphics/text_engine/text_engine.cc
r5344 r5347 76 76 delete textIterator; 77 77 } 78 // delete all remaining fonts ( this is done in the ResourceManager)78 // delete all remaining fonts (There should not be Anything to do here) 79 79 tList<BaseObject>* fontList = ClassList::getList(CL_FONT); 80 80 if (fontList != NULL) … … 127 127 /** 128 128 * outputs some nice Debug information 129 130 @todo there should also be something outputted about Font131 */129 * 130 * @todo there should also be something outputted about Font 131 */ 132 132 void TextEngine::debug() const 133 133 { -
trunk/src/lib/graphics/text_engine/text_engine.h
r5344 r5347 1 1 /*! 2 2 * @file text_engine.h 3 * Definition of textEngine, the Font and the Text4 5 Text is the text outputed.6 Font is a class that loads a certain ttf-file with a specific height into memory7 TextEngine is used to manage the all the different Fonts that might be included8 9 for more information see the specific classes.10 11 !! IMPORTANT !! When using ttf fonts clear the license issues prior to12 adding them to orxonox. This is really important, because we do not want13 to offend anyone.14 */3 * Definition of textEngine, the Font and the Text 4 * 5 * Text is the text outputed. 6 * Font is a class that loads a certain ttf-file with a specific height into memory 7 * TextEngine is used to manage the all the different Fonts that might be included 8 * 9 * for more information see the specific classes. 10 * 11 * !! IMPORTANT !! When using ttf fonts clear the license issues prior to 12 * adding them to orxonox. This is really important, because we do not want 13 * to offend anyone. 14 */ 15 15 16 16 #ifndef _TEXT_ENGINE_H … … 26 26 class Text; 27 27 28 /////////////////// 29 /// TEXT-ENGINE /// 30 /////////////////// 31 //! A singleton Class that operates as a Handler for generating and rendering Text in 2D 28 //! A singleton Class that operates as a Handler initializing FONTS. 32 29 class TextEngine : public BaseObject 33 30 {
Note: See TracChangeset
for help on using the changeset viewer.










