Changeset 5767 in orxonox.OLD for trunk/src/lib/graphics
- Timestamp:
- Nov 24, 2005, 7:43:08 PM (19 years ago)
- Location:
- trunk/src/lib/graphics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/graphics_engine.cc
r5755 r5767 313 313 if (texList != NULL) 314 314 { 315 316 317 318 319 320 321 322 315 tIterator<BaseObject>* texIt = texList->getIterator(); 316 Texture* reTex = static_cast<Texture*>(texIt->firstElement()); 317 while (reTex != NULL) 318 { 319 reTex->rebuild(); 320 321 reTex = static_cast<Texture*>(texIt->nextElement()); 322 } 323 323 } 324 324 #endif /* __WIN32__ */ … … 584 584 if (this->geTextCFPS == NULL) 585 585 { 586 this->geTextCFPS = new Text("fonts/arial_black.ttf", 15 , TEXT_RENDER_DYNAMIC);586 this->geTextCFPS = new Text("fonts/arial_black.ttf", 15); 587 587 this->geTextCFPS->setName("curFPS"); 588 588 this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT); … … 591 591 if (this->geTextMaxFPS == NULL) 592 592 { 593 this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15 , TEXT_RENDER_DYNAMIC);593 this->geTextMaxFPS = new Text("fonts/arial_black.ttf", 15); 594 594 this->geTextMaxFPS->setName("MaxFPS"); 595 595 this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT); … … 598 598 if (this->geTextMinFPS == NULL) 599 599 { 600 this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15 , TEXT_RENDER_DYNAMIC);600 this->geTextMinFPS = new Text("fonts/arial_black.ttf", 15); 601 601 this->geTextMinFPS->setName("MinFPS"); 602 602 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT); -
trunk/src/lib/graphics/text_engine/font.h
r5421 r5767 54 54 class Font : public BaseObject 55 55 { 56 friend class Text;57 58 56 public: 59 57 Font(const char* fontFile, … … 77 75 /** @returns the default Font */ 78 76 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); -
trunk/src/lib/graphics/text_engine/text.cc
r5515 r5767 32 32 * @param type The renderType to display this font in 33 33 */ 34 Text::Text(const char* fontFile, unsigned int textSize , TEXT_RENDER_TYPE type)34 Text::Text(const char* fontFile, unsigned int textSize) 35 35 { 36 36 this->init(); … … 38 38 if (fontFile != NULL) 39 39 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 40 this->setType(type);41 40 this->setSizeY2D(this->size = textSize); 42 41 } … … 49 48 Text::~Text() 50 49 { 51 if (this->font != NULL && this->font != Font:: defaultFont)50 if (this->font != NULL && this->font != Font::getDefaultFont()) 52 51 ResourceManager::getInstance()->unload(this->font); 53 52 … … 68 67 this->externText = NULL; 69 68 this->setAlignment(TEXT_DEFAULT_ALIGNMENT); 70 this->texture = 0;71 69 this->blending = TEXT_DEFAULT_BLENDING; 72 70 this->color = TEXT_DEFAULT_COLOR; 73 71 this->size = TEXT_DEFAULT_SIZE; 74 this->setType(TEXT_RENDER_DYNAMIC);75 72 76 73 this->setText(NULL); … … 89 86 90 87 // unloading the Font if we alrady have one loaded. 91 if (this->font != NULL && this->font != Font:: defaultFont)88 if (this->font != NULL && this->font != Font::getDefaultFont()) 92 89 ResourceManager::getInstance()->unload(this->font); 93 90 this->font = NULL; … … 102 99 PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile); 103 100 } 104 }105 106 /**107 * sets the Type of this Text108 * @param type the type to set.109 */110 void Text::setType(TEXT_RENDER_TYPE type)111 {112 if (this->font != NULL && this->font->fontTTF)113 this->type = type;114 else115 this->type = TEXT_RENDER_DYNAMIC;116 101 } 117 102 … … 167 152 tmpText++; 168 153 } 169 this->setSizeX2D( this->width =width *this->getSizeY2D());154 this->setSizeX2D(width *this->getSizeY2D()); 170 155 } 171 }172 }173 174 175 /**176 * creates a texture out of the given parameters !! TEXT_STATIC !! - mode177 *178 * this has to be called every time by the user, to if changes were made.179 * this is only for TEXT_STATIC-mode180 */181 void Text::createTexture()182 {183 SDL_Surface* tmpSurf = NULL;184 if (this->texture)185 glDeleteTextures(1, &this->texture);186 if (likely(this->font != NULL))187 {188 SDL_Color theColor = { (int)(this->color.x*255), (int)(this->color.y*255), (int)(this->color.z*255) };189 tmpSurf = TTF_RenderText_Blended(this->font->fontTTF,190 this->text,191 theColor);192 }193 if (tmpSurf != NULL)194 {195 this->texture = loadTexture(tmpSurf, &this->texCoord);196 197 this->width = tmpSurf->w;198 this->height = tmpSurf->h;199 SDL_FreeSurface(tmpSurf);200 156 } 201 157 } … … 209 165 // transform for alignment. 210 166 if (this->getAlignment() == TEXT_ALIGN_RIGHT) 211 glTranslatef(-this-> width, 0, 0);167 glTranslatef(-this->getSizeX2D(), 0, 0); 212 168 else if (this->getAlignment() == TEXT_ALIGN_CENTER || this->getAlignment() == TEXT_ALIGN_SCREEN_CENTER) 213 glTranslatef(-this-> width/2, 0, 0);169 glTranslatef(-this->getSizeX2D()/2, 0, 0); 214 170 215 171 // drawing this Text. … … 222 178 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE ); 223 179 224 if(likely(type & TEXT_RENDER_DYNAMIC )) 225 { 226 Glyph** glyphArray; 227 if (likely (this->font != NULL)) 180 Glyph** glyphArray; 181 if (likely (this->font != NULL)) 182 { 183 glyphArray = this->font->getGlyphArray(); 184 glBindTexture(GL_TEXTURE_2D, font->getFastTextureID()); 185 } 186 else 187 { 188 if (unlikely(Font::getDefaultFont() == NULL)) 189 Font::initDefaultFont(); 190 glyphArray = Font::getDefaultFont()->getGlyphArray(); 191 glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getFastTextureID()); 192 } 193 const char* tmpText = this->externText; 194 if (this->externText == NULL) 195 tmpText = this->text; 196 if (likely(tmpText != NULL)) 197 { 198 glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0); 199 glRotatef(this->getAbsDir2D(), 0, 0, 1); 200 Glyph* tmpGlyph; 201 float posX = 0.0f; 202 while (likely(*tmpText != '\0')) 228 203 { 229 glyphArray = this->font->getGlyphArray(); 230 glBindTexture(GL_TEXTURE_2D, font->getFastTextureID()); 204 if(likely((tmpGlyph = glyphArray[*tmpText]) != NULL)) 205 { 206 glBegin(GL_QUADS); 207 208 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]); 209 glVertex2d(posX, 0); 210 211 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]); 212 glVertex2d(posX, this->size); 213 214 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]); 215 glVertex2d(posX+tmpGlyph->width*this->size, this->size); 216 217 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); 218 glVertex2d(posX+tmpGlyph->width*this->size, 0); 219 220 glEnd(); 221 glEndList(); 222 posX += tmpGlyph->advance * this->size; 223 } 224 ++tmpText; 231 225 } 232 else 233 { 234 if (unlikely(Font::getDefaultFont() == NULL)) 235 Font::initDefaultFont(); 236 glyphArray = Font::getDefaultFont()->getGlyphArray(); 237 glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getFastTextureID()); 238 } 239 const char* tmpText = this->externText; 240 if (this->externText == NULL) 241 tmpText = this->text; 242 if (likely(tmpText != NULL)) 243 { 244 glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0); 245 glRotatef(this->getAbsDir2D(), 0, 0, 1); 246 Glyph* tmpGlyph; 247 float posX = 0.0f; 248 while (likely(*tmpText != '\0')) 249 { 250 if(likely((tmpGlyph = glyphArray[*tmpText]) != NULL)) 251 { 252 glBegin(GL_QUADS); 253 254 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]); 255 glVertex2d(posX, 0); 256 257 glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]); 258 glVertex2d(posX, this->size); 259 260 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]); 261 glVertex2d(posX+tmpGlyph->width*this->size, this->size); 262 263 glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]); 264 glVertex2d(posX+tmpGlyph->width*this->size, 0); 265 266 glEnd(); 267 glEndList(); 268 posX += tmpGlyph->advance * this->size; 269 } 270 ++tmpText; 271 } 272 } 273 } 274 else //(if type & TEXT_RENDER_STATIC) 275 { 276 glBindTexture(GL_TEXTURE_2D, this->texture); 277 glBegin(GL_QUADS); 278 279 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); 280 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y ); 281 282 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 283 glVertex2f(this->getAbsCoor2D().x + this->width, this->getAbsCoor2D().y ); 284 285 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 286 glVertex2f(this->getAbsCoor2D().x + this->width, getAbsCoor2D().y + this->height); 287 288 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 289 glVertex2f(getAbsCoor2D().x, getAbsCoor2D().y + this->height); 290 291 glEnd(); 292 293 } 226 } 227 294 228 glPopMatrix(); 295 229 } -
trunk/src/lib/graphics/text_engine/text.h
r5427 r5767 26 26 struct SDL_Surface; 27 27 28 /**29 * STATIC means: a font, that is only one GL-face.30 ** it is very fast, and can be used for all text31 ** that does not have to be changed anymore, or if32 ** the the text should look very nice33 * DYNAMIC means: a very fast font, that will is build34 ** from multiple quads.35 ** Use this type, if you want to create fast changing36 ** text like a counter.37 */38 typedef enum TEXT_RENDER_TYPE39 {40 TEXT_RENDER_STATIC = 1,41 TEXT_RENDER_DYNAMIC = 242 };43 44 28 //! A Struct to handel Texture Coordinates for quads 45 29 struct TexCoord … … 55 39 { 56 40 public: 57 Text(const char* fontFile = NULL, unsigned int fontSize = TEXT_DEFAULT_SIZE , TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);41 Text(const char* fontFile = NULL, unsigned int fontSize = TEXT_DEFAULT_SIZE); 58 42 ~Text(); 59 43 void init(); … … 74 58 // void getSize(float &x, float& y) const { return this->size; }; 75 59 76 void setType(TEXT_RENDER_TYPE type);77 void createTexture();78 79 60 virtual void draw() const; 80 61 … … 88 69 Font* font; //!< Font of this text 89 70 90 TEXT_RENDER_TYPE type; //!< The type of this Font.91 71 char* text; //!< The text to display 92 72 const char* externText; //!< the text to Display from an external Source. … … 94 74 float blending; //!< The blending intensity. 95 75 float size; //!< The size of the Font. 96 97 // placement in openGL98 GLuint texture; //!< A GL-texture to hold the text (static Mode)99 TexCoord texCoord; //!< Texture-coordinates @todo fix this to have a struct100 float height;101 float width;102 76 }; 103 77
Note: See TracChangeset
for help on using the changeset viewer.