Changeset 8755 in orxonox.OLD for branches/fontdata
- Timestamp:
- Jun 23, 2006, 8:24:28 PM (18 years ago)
- Location:
- branches/fontdata/src/lib/graphics/text_engine
- Files:
-
- 3 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 } -
branches/fontdata/src/lib/graphics/text_engine/font.h
r8754 r8755 11 11 #define _FONT_H 12 12 13 #include " texture.h"13 #include "material.h" 14 14 15 15 #include "font_data.h" … … 17 17 18 18 //! A class to handle a Font of a certain ttf-File/image-file, Size. 19 class Font : public Texture19 class Font : public BaseObject /* TODO Material it should be */ 20 20 { 21 21 22 22 public: 23 23 Font(); 24 Font(const std::string& fontFile, 25 unsigned int renderSize); 24 Font(const std::string& fontFile, unsigned int renderSize); 26 25 Font(const std::string& imageFile); 27 26 Font(char** xpmArray); … … 31 30 bool operator==(const Font& font) const { return this->data == font.data; }; 32 31 33 // font 32 33 /// LOADING new Fonts 34 34 bool loadFontFromTTF(const std::string& fontFile); 35 35 bool loadFontFromSDL_Surface(SDL_Surface* surface); … … 42 42 inline TTF_Font* getTTF() const { return this->data->getTTF(); }; 43 43 44 inline GLuint getTexture() const { return this->data->getTexture(); }; 45 46 44 47 int getMaxHeight() const; 45 48 int getMaxAscent() const; … … 49 52 //inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; }; 50 53 51 52 53 54 void createAsciiImage(const std::string& fileName, unsigned int size) const; 54 55 55 56 void debug() const ; 57 56 58 private: 57 59 void init(); … … 60 62 bool createFastTexture(); 61 63 62 63 64 void initGlyphs(Uint16 from, Uint16 count); 64 65 int findOptimalFastTextureSize(); 65 66 66 67 static FontDataPointer initDefaultFont(); 67 static void initDefaultFont(); 68 68 69 69 private: -
branches/fontdata/src/lib/graphics/text_engine/text.cc
r8754 r8755 33 33 34 34 // initialize this Text 35 this->_font = NULL;36 35 this->_size = textSize; 37 36 this->setSizeY2D(textSize);
Note: See TracChangeset
for help on using the changeset viewer.