Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7448 in orxonox.OLD


Ignore:
Timestamp:
Apr 29, 2006, 8:03:35 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: text-draw optimized

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/text.cc

    r7431 r7448  
    9696
    9797  // setting up the Text-Width if DYNAMIC
    98 //  if (this->type & TEXT_RENDER_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT && this->font != NULL)
     98  //  if (this->type & TEXT_RENDER_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT && this->font != NULL)
    9999  const Font* calcSizeFont = this->font;
    100100  if (calcSizeFont != NULL || (calcSizeFont = Font::getDefaultFont()) != NULL)
     
    122122void Text::draw() const
    123123{
     124  if (unlikely(this->text.empty()))
     125    return;
    124126  glPushMatrix();
    125127  // transform for alignment.
     
    135137  glEnable(GL_TEXTURE_2D);
    136138  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    137 
    138139  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    139140
    140   Glyph** glyphArray;
    141   if (likely (this->font != NULL))
    142   {
    143     glyphArray = this->font->getGlyphArray();
    144     glBindTexture(GL_TEXTURE_2D, font->getTexture());
    145   }
    146   else
    147   {
    148     if (unlikely(Font::getDefaultFont() == NULL))
    149       Font::initDefaultFont();
    150     glyphArray = Font::getDefaultFont()->getGlyphArray();
    151     glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getTexture());
    152   }
    153   if (likely(!this->text.empty()))
    154   {
    155     glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
    156     glRotatef(this->getAbsDir2D(), 0, 0, 1);
    157     Glyph* tmpGlyph;
    158     float posX = 0.0f;
    159 
    160     glBegin(GL_QUADS);
    161     for (unsigned int i = 0; i < this->text.size(); i++)
     141  Glyph** glyphArray = this->font->getGlyphArray();
     142  glBindTexture(GL_TEXTURE_2D, font->getTexture());
     143  glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
     144  glRotatef(this->getAbsDir2D(), 0, 0, 1);
     145
     146  Glyph* tmpGlyph;
     147  float posX = 0.0f;
     148  glBegin(GL_QUADS);
     149  for (unsigned int i = 0; i < this->text.size(); i++)
     150  {
     151    if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL))
    162152    {
    163       if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL))
    164       {
    165         glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    166         glVertex2d(posX+tmpGlyph->maxX*this->getSizeY2D(), 0);
    167 
    168         glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    169         glVertex2d(posX+tmpGlyph->maxX*this->getSizeY2D(), this->getSizeY2D());
    170 
    171         glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    172         glVertex2d(posX+tmpGlyph->minX*this->getSizeY2D(), this->getSizeY2D());
    173 
    174         glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    175         glVertex2d(posX+tmpGlyph->minX*this->getSizeY2D(), 0);
    176 
    177         posX += tmpGlyph->advance * this->getSizeY2D();
    178       }
     153      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
     154      glVertex2d(posX+tmpGlyph->maxX*this->getSizeY2D(), 0);
     155
     156      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
     157      glVertex2d(posX+tmpGlyph->maxX*this->getSizeY2D(), this->getSizeY2D());
     158
     159      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
     160      glVertex2d(posX+tmpGlyph->minX*this->getSizeY2D(), this->getSizeY2D());
     161
     162      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
     163      glVertex2d(posX+tmpGlyph->minX*this->getSizeY2D(), 0);
     164
     165      posX += tmpGlyph->advance * this->getSizeY2D();
    179166    }
    180     glEnd();
    181   }
    182 
     167  }
     168  glEnd();
    183169  glPopMatrix();
    184170}
     
    231217                               0xFF000000
    232218#else
    233                                    0xFF000000,
     219                               0xFF000000,
    234220                               0x00FF0000,
    235221                               0x0000FF00,
     
    237223#endif
    238224                              );
    239   if ( image == NULL ) {
     225  if ( image == NULL )
     226  {
    240227    return 0;
    241228  }
     
    244231  saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
    245232  saved_alpha = surface->format->alpha;
    246   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
     233  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
     234  {
    247235    SDL_SetAlpha(surface, 0, 0);
    248236  }
     
    256244
    257245  /* Restore the alpha blending attributes */
    258   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
     246  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
     247  {
    259248    SDL_SetAlpha(surface, saved_flags, saved_alpha);
    260249  }
Note: See TracChangeset for help on using the changeset viewer.