Changeset 5768 in orxonox.OLD for trunk/src/lib/graphics/text_engine
- Timestamp:
- Nov 24, 2005, 8:24:52 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/text_engine
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/font.cc
r5427 r5768 132 132 this->fontTTF = NULL; 133 133 this->glyphArray = NULL; 134 this->fastTextureID = 0;135 134 } 136 135 … … 149 148 this->fontTTF = NULL; 150 149 } 151 if (this->fastTextureID != 0) 152 { 153 if(glIsTexture(this->fastTextureID)) 154 glDeleteTextures(1, &this->fastTextureID); 155 this->fastTextureID = 0; 156 } 150 157 151 158 152 this->setName(fontFile); … … 161 155 if(this->fontTTF != NULL) 162 156 { 163 this->fastTextureID = this->createFastTexture(); 164 if (this->fastTextureID != 0) 165 return true; 166 else 167 return false; 157 this->createFastTexture(); 158 return (this->getTexture() != 0); 168 159 } 169 160 else … … 190 181 this->fontTTF = NULL; 191 182 } 192 if (this->fastTextureID != 0) 193 { 194 if(glIsTexture(this->fastTextureID)) 195 glDeleteTextures(1, &this->fastTextureID); 196 this->fastTextureID = 0; 197 } 198 199 this->fastTextureID = Text::loadTexture(surface, NULL); 183 if (this->prepareSurface(surface)) 184 this->loadTexToGL( ); 200 185 201 186 // initializing the Glyphs. … … 251 236 Font* Font::defaultFont = NULL; 252 237 238 /** 239 * creates and exports an Image, that has all the characters 240 * stored in a Array (as an image) 241 * @param fileName the File to write the image into. 242 */ 253 243 void Font::createAsciiImage(const char* fileName) 254 244 { … … 400 390 * creates a Fast-Texture of this Font 401 391 */ 402 GLuintFont::createFastTexture()392 bool Font::createFastTexture() 403 393 { 404 394 /* interesting GLYPHS: … … 500 490 // SDL_SaveBMP(tmpSurf, outName); 501 491 502 GLuint texture; 503 glGenTextures(1, &texture); 504 glBindTexture(GL_TEXTURE_2D, texture); 505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 507 glTexImage2D(GL_TEXTURE_2D, 508 0, 509 GL_RGBA, 510 tmpSurf->w, tmpSurf->h, 511 0, 512 GL_RGBA, 513 GL_UNSIGNED_BYTE, 514 tmpSurf->pixels); 515 SDL_FreeSurface(tmpSurf); 516 return texture; 492 if (this->setSurface(tmpSurf)) 493 loadTexToGL(); 517 494 } 518 495 -
trunk/src/lib/graphics/text_engine/font.h
r5767 r5768 11 11 #define _FONT_H 12 12 13 #include " base_object.h"13 #include "texture.h" 14 14 15 15 #include "glincl.h" … … 52 52 53 53 //! A class to handle a Font of a certain ttf-File/image-file, Size. 54 class Font : public BaseObject54 class Font : public Texture 55 55 { 56 56 public: … … 63 63 void init(); 64 64 65 // font65 // font 66 66 bool loadFontFromTTF(const char* fontFile); 67 67 bool loadFontFromSDL_Surface(SDL_Surface* surface); … … 71 71 /** @returns a Pointer to the Array of Glyphs */ 72 72 inline Glyph** getGlyphArray() const { return this->glyphArray; }; 73 /** @returns the texture to the fast-texture */ 74 inline GLuint getFastTextureID() const { return this->fastTextureID; }; 73 /** @returns the a pointer to the TTF */ 74 inline TTF_Font* getTTF() const { return this->fontTTF; }; 75 76 75 77 /** @returns the default Font */ 76 78 inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; }; 77 /** @returns the a pointer to the TTF */78 inline TTF_Font* getTTF() const { return this->fontTTF; };79 79 80 80 void createAsciiImage(const char* fileName); 81 81 static void initDefaultFont(); 82 82 static void removeDefaultFont(); 83 84 83 85 84 private: … … 89 88 Glyph* getGlyphMetrics(Uint16 character); 90 89 91 GLuintcreateFastTexture();90 bool createFastTexture(); 92 91 93 92 void initGlyphs(Uint16 from, Uint16 count); … … 104 103 105 104 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. 106 GLuint fastTextureID; //!< The fast textureID.107 105 }; 108 106 -
trunk/src/lib/graphics/text_engine/text.cc
r5767 r5768 38 38 if (fontFile != NULL) 39 39 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 40 this->setSizeY2D(t his->size = textSize);40 this->setSizeY2D(textSize); 41 41 } 42 42 … … 69 69 this->blending = TEXT_DEFAULT_BLENDING; 70 70 this->color = TEXT_DEFAULT_COLOR; 71 this->size = TEXT_DEFAULT_SIZE; 72 71 this->setSize(TEXT_DEFAULT_SIZE); 73 72 this->setText(NULL); 74 73 } … … 182 181 { 183 182 glyphArray = this->font->getGlyphArray(); 184 glBindTexture(GL_TEXTURE_2D, font->get FastTextureID());183 glBindTexture(GL_TEXTURE_2D, font->getTexture()); 185 184 } 186 185 else … … 189 188 Font::initDefaultFont(); 190 189 glyphArray = Font::getDefaultFont()->getGlyphArray(); 191 glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->get FastTextureID());190 glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getTexture()); 192 191 } 193 192 const char* tmpText = this->externText; … … 210 209 211 210 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]); 212 glVertex2d(posX, this-> size);211 glVertex2d(posX, this->getSizeY2D()); 213 212 214 213 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]); 215 glVertex2d(posX+tmpGlyph->width*this-> size, this->size);214 glVertex2d(posX+tmpGlyph->width*this->getSizeY2D(), this->getSizeY2D()); 216 215 217 216 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); 218 glVertex2d(posX+tmpGlyph->width*this-> size, 0);217 glVertex2d(posX+tmpGlyph->width*this->getSizeY2D(), 0); 219 218 220 219 glEnd(); 221 220 glEndList(); 222 posX += tmpGlyph->advance * this-> size;221 posX += tmpGlyph->advance * this->getSizeY2D(); 223 222 } 224 223 ++tmpText; -
trunk/src/lib/graphics/text_engine/text.h
r5767 r5768 54 54 void setColor(float r, float g, float b) { this->color = Vector(r, g, b); }; 55 55 /** sets the Size of the Font */ 56 void setSize(float size) { this->setSizeY2D( this->size =size); };56 void setSize(float size) { this->setSizeY2D(size); }; 57 57 /** @returns the Size of the Text */ 58 58 // void getSize(float &x, float& y) const { return this->size; }; … … 73 73 Vector color; //!< The color of the font. 74 74 float blending; //!< The blending intensity. 75 float size; //!< The size of the Font.76 75 }; 77 76
Note: See TracChangeset
for help on using the changeset viewer.