Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5767 in orxonox.OLD for trunk/src/lib/graphics/text_engine/text.cc


Ignore:
Timestamp:
Nov 24, 2005, 7:43:08 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: removed support for text-render-static

File:
1 edited

Legend:

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

    r5515 r5767  
    3232 * @param type The renderType to display this font in
    3333 */
    34 Text::Text(const char* fontFile, unsigned int textSize, TEXT_RENDER_TYPE type)
     34Text::Text(const char* fontFile, unsigned int textSize)
    3535{
    3636  this->init();
     
    3838  if (fontFile != NULL)
    3939    this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE);
    40   this->setType(type);
    4140  this->setSizeY2D(this->size = textSize);
    4241}
     
    4948Text::~Text()
    5049{
    51   if (this->font != NULL && this->font != Font::defaultFont)
     50  if (this->font != NULL && this->font != Font::getDefaultFont())
    5251    ResourceManager::getInstance()->unload(this->font);
    5352
     
    6867  this->externText = NULL;
    6968  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
    70   this->texture = 0;
    7169  this->blending = TEXT_DEFAULT_BLENDING;
    7270  this->color = TEXT_DEFAULT_COLOR;
    7371  this->size = TEXT_DEFAULT_SIZE;
    74   this->setType(TEXT_RENDER_DYNAMIC);
    7572
    7673  this->setText(NULL);
     
    8986
    9087  // 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())
    9289    ResourceManager::getInstance()->unload(this->font);
    9390  this->font = NULL;
     
    10299      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
    103100  }
    104 }
    105 
    106 /**
    107  *  sets the Type of this Text
    108  * @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   else
    115     this->type = TEXT_RENDER_DYNAMIC;
    116101}
    117102
     
    167152        tmpText++;
    168153      }
    169       this->setSizeX2D(this->width = width *this->getSizeY2D());
     154      this->setSizeX2D(width *this->getSizeY2D());
    170155    }
    171   }
    172 }
    173 
    174 
    175 /**
    176  *  creates a texture out of the given parameters !! TEXT_STATIC !! - mode
    177  *
    178  * this has to be called every time by the user, to if changes were made.
    179  * this is only for TEXT_STATIC-mode
    180  */
    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);
    200156  }
    201157}
     
    209165  // transform for alignment.
    210166  if (this->getAlignment() == TEXT_ALIGN_RIGHT)
    211     glTranslatef(-this->width, 0, 0);
     167    glTranslatef(-this->getSizeX2D(), 0, 0);
    212168  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);
    214170
    215171  // drawing this Text.
     
    222178  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    223179
    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'))
    228203    {
    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;
    231225    }
    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
    294228  glPopMatrix();
    295229}
Note: See TracChangeset for help on using the changeset viewer.