Changeset 8755 in orxonox.OLD for branches/fontdata/src/lib/graphics/text_engine/font.cc
- Timestamp:
- Jun 23, 2006, 8:24:28 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/fontdata/src/lib/graphics/text_engine/font.cc
r8754 r8755 17 17 18 18 #include "font.h" 19 #include "text.h"20 19 21 20 #ifdef HAVE_SDL_IMAGE_H … … 24 23 #include <SDL/SDL_image.h> 25 24 #endif 25 26 26 #include "default_font.xpm" 27 27 … … 33 33 : data(Font::defaultFontData) 34 34 { 35 printf("Font()\n"); 35 36 this->init(); 36 37 … … 45 46 : data(Font::defaultFontData) 46 47 { 48 printf("Font(const std::string& fontFile, unsigned int renderSize)\n"); 47 49 this->init(); 48 50 49 51 assert(data.get() != NULL); 50 52 this->data->renderSize = renderSize; 51 53 this->setStyle("c"); … … 62 64 : data(Font::defaultFontData) 63 65 { 66 printf("Font(const std::string& imageFile)\n"); 64 67 this->init(); 65 68 … … 87 90 : data(Font::defaultFontData) 88 91 { 92 printf("Font(char** xpmArray)\n"); 93 89 94 this->init(); 90 95 this->setName("XPM-array-font"); … … 99 104 } 100 105 else 101 PRINTF(1)(" loading from surfacefailed: %s\n", IMG_GetError());106 PRINTF(1)("Loading from XPM-array failed: %s\n", IMG_GetError()); 102 107 } 103 108 … … 119 124 this->setClassID(CL_FONT, "Font"); 120 125 if (Font::defaultFontData.get() == NULL) 121 Font::defaultFontData = initDefaultFont(); 122 } 123 124 FontDataPointer Font::defaultFontData = FontDataPointer(NULL); //initDefaultFont(); 125 126 { 127 Font::initDefaultFont(); 128 this->data = Font::defaultFontData; 129 } 130 } 131 132 FontDataPointer Font::defaultFontData(NULL); 133 134 /** 135 * @brief initializes the default font 136 */ 137 void Font::initDefaultFont() 138 { 139 // temporarily create a Font. 140 Font::defaultFontData = FontDataPointer(new FontData); 141 // apply the Data. 142 printf("before: %p\n", defaultFontData.get()); 143 Font::defaultFontData = Font(font_xpm).data; 144 printf("after: %p\n", defaultFontData.get()); 145 } 126 146 127 147 /** … … 140 160 { 141 161 this->createFastTexture(); 142 return (this->getTexture() != 0); 162 if (this->getTexture() != 0) 163 return true; 164 else 165 { 166 this->data = Font::defaultFontData; 167 return false; 168 } 143 169 } 144 170 else 145 171 { 146 172 PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError()); 173 this->data = Font::defaultFontData; 147 174 return false; 148 175 } … … 156 183 bool Font::loadFontFromSDL_Surface(SDL_Surface* surface) 157 184 { 185 if(surface == NULL) 186 return false; 187 158 188 this->data = FontDataPointer (new FontData()); 159 189 // loading to a texture. 160 if(surface == NULL) 190 191 bool hasAlpha; 192 SDL_Surface* newSurf = Texture::prepareSurface(surface, hasAlpha); 193 if (newSurf != NULL) 194 { 195 this->data->setSurface(newSurf); 196 this->data->setAlpha(hasAlpha); 197 this->data->setTexture(Texture::loadTexToGL(newSurf)); 198 } 199 else 200 { 201 this->data = Font::defaultFontData; 161 202 return false; 162 163 if (this->data->fontTTF != NULL)164 {165 TTF_CloseFont(this->data->fontTTF);166 this->data->fontTTF = NULL;167 }168 bool hasAlpha;169 SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);170 if (newSurf != NULL)171 {172 this->setSurface(newSurf);173 this->setAlpha(hasAlpha);174 this->setTexture(Texture::loadTexToGL(newSurf));175 203 } 176 204 … … 289 317 } 290 318 291 /**292 * @brief initializes the default font293 */294 FontDataPointer Font::initDefaultFont()295 {296 Font::defaultFontData = FontDataPointer(new FontData);297 return Font(font_xpm).data;298 }299 319 300 320 /** … … 466 486 // sprintf( outName, "%s-glyphs.bmp", this->getName()); 467 487 // SDL_SaveBMP(tmpSurf, outName); 468 this-> setAlpha(true);469 if (this-> setSurface(tmpSurf))470 (this-> setTexture(Texture::loadTexToGL(tmpSurf)));488 this->data->setAlpha(true); 489 if (this->data->setSurface(tmpSurf)) 490 (this->data->setTexture(Texture::loadTexToGL(tmpSurf))); 471 491 return true; 472 492 }
Note: See TracChangeset
for help on using the changeset viewer.