Changeset 5121 in orxonox.OLD for trunk/src/lib/graphics/text_engine.cc
- Timestamp:
- Aug 25, 2005, 1:26:57 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine.cc
r5115 r5121 60 60 this->texture = 0; 61 61 this->blending = 1.0f; 62 this->color = Vector(1.0, 1.0, 1.0); 62 63 this->setType(type); 63 64 … … 75 76 76 77 if (this->text) 77 delete []this->text;78 delete[] this->text; 78 79 } 79 80 … … 130 131 131 132 /** 132 * sets a new color to the font133 * @param r Red134 * @param g Green135 * @param b Blue136 */137 void Text::setColor(Uint8 r, Uint8 g, Uint8 b)138 {139 this->color.r = r;140 this->color.g = g;141 this->color.b = b;142 }143 144 /**145 133 * creates a texture out of the given parameters 146 134 … … 154 142 glDeleteTextures(1, &this->texture); 155 143 if (likely(this->font != NULL)) 144 { 145 SDL_Color theColor = { (int)(this->color.x*255), (int)(this->color.y*255), (int)(this->color.z*255) }; 156 146 tmpSurf = TTF_RenderText_Blended(this->font->font, 157 147 this->text, 158 this->color); 148 theColor); 149 } 159 150 if (tmpSurf) 160 151 this->texture = loadTexture(tmpSurf, &this->texCoord); … … 179 170 // drawing this Text. 180 171 // setting the Blending effects 181 glColor4f( 1.0f,1.0f,1.0f, this->blending);172 glColor4f(this->color.x, this->color.y, this->color.z, this->blending); 182 173 glEnable(GL_BLEND); 183 174 glEnable(GL_TEXTURE_2D); 184 175 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 176 177 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE ); 185 178 186 179 if(type == TEXT_STATIC) … … 234 227 PRINT(0)("is bind to %s; ref=%p\n", this->getBindNode()->getName(), this->getBindNode()); 235 228 PRINT(0)("Relative Position: (%d::%d)\n", this->posSize.x, this->posSize.y); 236 PRINT(0)("Color: % d %d %d\n", this->color.r, this->color.g, this->color.b);229 PRINT(0)("Color: %0.2f %0.2f %0.2f\n", this->color.x, this->color.y, this->color.z); 237 230 } 238 231 … … 349 342 * @param b Blue value of the Font. 350 343 */ 351 Font::Font(const char* fontFile, unsigned int fontSize , Uint8 r, Uint8 g, Uint8 b)344 Font::Font(const char* fontFile, unsigned int fontSize) 352 345 { 353 346 this->setClassID(CL_FONT, "Font"); … … 364 357 this->setStyle("c");//TTF_STYLE_NORMAL); 365 358 366 this->setFastColor(r, g, b);367 368 359 this->fastTextureID = this->createFastTexture(); 369 360 } … … 381 372 for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++) 382 373 delete this->glyphArray[i]; 383 delete []this->glyphArray;374 delete[] this->glyphArray; 384 375 } 385 376 … … 448 439 { 449 440 this->fontSize = fontSize; 450 }451 452 /**453 * sets a new color to the font454 * @param r Red455 * @param g Green456 * @param b Blue457 */458 void Font::setFastColor(Uint8 r, Uint8 g, Uint8 b)459 {460 this->fastColor.r = r;461 this->fastColor.g = g;462 this->fastColor.b = b;463 441 } 464 442 … … 538 516 539 517 this->initGlyphs(32, numberOfGlyphs); 540 this->glyphArray[32]->width = fontSize/ 3; //!< @todo find out the real size of a Space518 this->glyphArray[32]->width = fontSize/2; //!< @todo find out the real size of a Space 541 519 542 520 int rectSize = this->findOptimalFastTextureSize(); … … 589 567 // reading in the new Glyph 590 568 if (likely(this->font != NULL)) 591 glyphSurf = TTF_RenderGlyph_Blended(this->font, i, this->fastColor); 569 { 570 SDL_Color white = {255, 255, 255}; 571 glyphSurf = TTF_RenderGlyph_Blended(this->font, i, white); 572 } 592 573 if( glyphSurf != NULL ) 593 574 { … … 598 579 tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w; 599 580 tmpTexCoord.maxU = (float)(tmpRect.x +1 + tmpGlyph->width)/(float)tmpSurf->w; 600 tmpTexCoord.minV = (float) tmpRect.y/(float)tmpSurf->w;581 tmpTexCoord.minV = (float)(tmpRect.y)/(float)tmpSurf->w; 601 582 tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w; 602 583 tmpGlyph->displayList = glGenLists(1); … … 691 672 int x,y; // the counters 692 673 int maxLineHeight; 693 int size = 32; // starting Value, we have to start somewhere 32 seems reasonable.674 unsigned int size = 32; // starting Value, we have to start somewhere 32 seems reasonable. (take any small enough 2^i number) 694 675 bool sizeOK = false; 695 676 Glyph* tmpGlyph; … … 815 796 @see Text::Text 816 797 */ 817 Text* TextEngine::createText(const char* fontFile, unsigned int fontSize, int textType , Uint8 r, Uint8 g, Uint8 b)798 Text* TextEngine::createText(const char* fontFile, unsigned int fontSize, int textType) 818 799 { 819 800 Font* tmpFont; … … 821 802 Vector tmpVec; 822 803 823 tmpVec = Vector(r, g, b); 824 tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize, &tmpVec); 804 tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize); 825 805 if (!tmpFont) 826 806 {
Note: See TracChangeset
for help on using the changeset viewer.