Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

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

Location:
trunk/src/lib/graphics/text_engine
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/font.h

    r5421 r5767  
    5454class Font : public BaseObject
    5555{
    56   friend class Text;
    57 
    5856  public:
    5957    Font(const char* fontFile,
     
    7775    /** @returns the default Font */
    7876    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; };
    7979
    8080    void createAsciiImage(const char* fileName);
  • 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}
  • trunk/src/lib/graphics/text_engine/text.h

    r5427 r5767  
    2626struct SDL_Surface;
    2727
    28 /**
    29  * STATIC means: a font, that is only one GL-face.
    30  ** it is very fast, and can be used for all text
    31  ** that does not have to be changed anymore, or if
    32  ** the the text should look very nice
    33  * DYNAMIC means: a very fast font, that will is build
    34  ** from multiple quads.
    35  ** Use this type, if you want to create fast changing
    36  ** text like a counter.
    37  */
    38 typedef enum TEXT_RENDER_TYPE
    39 {
    40   TEXT_RENDER_STATIC      = 1,
    41   TEXT_RENDER_DYNAMIC     = 2
    42 };
    43 
    4428//! A Struct to handel Texture Coordinates for quads
    4529struct TexCoord
     
    5539{
    5640  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);
    5842    ~Text();
    5943    void init();
     
    7458//    void getSize(float &x, float& y) const { return this->size; };
    7559
    76     void setType(TEXT_RENDER_TYPE type);
    77     void createTexture();
    78 
    7960    virtual void draw() const;
    8061
     
    8869    Font*             font;           //!< Font of this text
    8970
    90     TEXT_RENDER_TYPE  type;           //!< The type of this Font.
    9171    char*             text;           //!< The text to display
    9272    const char*       externText;     //!< the text to Display from an external Source.
     
    9474    float             blending;       //!< The blending intensity.
    9575    float             size;           //!< The size of the Font.
    96 
    97   // placement in openGL
    98     GLuint            texture;        //!< A GL-texture to hold the text (static Mode)
    99     TexCoord          texCoord;       //!< Texture-coordinates @todo fix this to have a struct
    100     float             height;
    101     float             width;
    10276};
    10377
Note: See TracChangeset for help on using the changeset viewer.