Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Aug 25, 2005, 2:46:34 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: text is now Rendered as expected (in FastMode)

File:
1 edited

Legend:

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

    r5123 r5124  
    375375  this->setSize(fontSize);
    376376
    377   this->setFont(fontFile);
     377  this->loadFont(fontFile);
    378378
    379379  this->setStyle("c");//TTF_STYLE_NORMAL);
     
    383383
    384384/**
    385  *  destructs a font
     385 * destructs a font
     386 * this releases the memory a font uses to be opened.
    386387*/
    387388Font::~Font()
     
    407408 * @returns true if loaded, false if something went wrong, or if a font was loaded before.
    408409*/
    409 bool Font::setFont(const char* fontFile)
     410bool Font::loadFont(const char* fontFile)
    410411{
    411412  if (!this->fontFile)
     
    576577            maxLineHeight = tmpGlyph->height;
    577578
    578           if (tmpRect.x+tmpGlyph->width > tmpSurf->w)
     579          if (tmpRect.x+tmpGlyph->advance > tmpSurf->w)
    579580            {
    580581              tmpRect.x = 0;
     
    600601              TexCoord tmpTexCoord;
    601602              tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w;
    602               tmpTexCoord.maxU = (float)(tmpRect.x +1 + tmpGlyph->width)/(float)tmpSurf->w;
     603              tmpTexCoord.maxU = (float)(tmpRect.x + tmpGlyph->advance)/(float)tmpSurf->w;
    603604              tmpTexCoord.minV = (float)(tmpRect.y)/(float)tmpSurf->w;
    604605              tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w;
     
    608609              glBegin(GL_QUADS);
    609610              glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.minV);
    610               glVertex2d(0, 0);
     611              glVertex2d(0, - tmpGlyph->bearingY);
    611612              glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.maxV);
    612               glVertex2d(0, tmpGlyph->height);
     613              glVertex2d(0, tmpGlyph->height - tmpGlyph->bearingY);
    613614              glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.maxV);
    614               glVertex2d(tmpGlyph->width, tmpGlyph->height);
     615              glVertex2d(tmpGlyph->width, tmpGlyph->height - tmpGlyph->bearingY);
    615616              glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.minV);
    616               glVertex2d(tmpGlyph->width, 0);
     617              glVertex2d(tmpGlyph->width, - tmpGlyph->bearingY);
    617618              glEnd();
    618619              glEndList();
    619620              SDL_FreeSurface(glyphSurf);
    620621
    621               tmpRect.x += tmpGlyph->width + 2;
     622              tmpRect.x += tmpGlyph->advance;
    622623
    623624              // Outputting Glyphs to BMP-files.
     
    693694  int i;
    694695  int x,y; // the counters
    695   int maxLineHeight;
     696  int maxLineHeight = this->getMaxHeight();
    696697  unsigned int size = 32;  // starting Value, we have to start somewhere 32 seems reasonable. (take any small enough 2^i number)
    697698  bool sizeOK = false;
     
    701702    {
    702703      x = 0; y = 0;
    703       maxLineHeight = 0;
    704704      for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
    705705        {
     
    710710                maxLineHeight = tmpGlyph->height;
    711711
    712               if (x + tmpGlyph->width > size)
     712              if (x + tmpGlyph->advance > size)
    713713                {
    714714                  x = 0;
     
    718718              if (y + maxLineHeight + 1 > size)
    719719                break;
    720               x += tmpGlyph->width + 1;
     720              x += tmpGlyph->advance;
    721721
    722722            }
     
    727727        size *= 2;
    728728    }
    729   return size;
     729    return size;
    730730}
    731731
Note: See TracChangeset for help on using the changeset viewer.