Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 9, 2005, 11:25:04 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: fonts are now correctly loaded (from IMAGE) by the FontEngine

File:
1 edited

Legend:

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

    r5337 r5339  
    453453
    454454  this->fastTextureID = this->createFastTexture();
     455
     456
     457//  this->createAsciiImage("test.bmp");
    455458}
    456459
     
    472475  if (xpmArray != NULL)
    473476    this->loadFontFromXPMArray(xpmArray);
     477
    474478}
    475479
     
    569573      glNewList(glyph->displayList, GL_COMPILE); // Start Building A List
    570574       glBegin(GL_QUADS);                           // Use A Quad For Each Character
    571         glTexCoord2f(cx,1.0f-cy-0.0625f);            // Texture Coord (Bottom Left)
    572         glVertex2d(0,16);                            // Vertex Coord (Bottom Left)
    573         glTexCoord2f(cx+0.0625f,1.0f-cy-0.0625f);    // Texture Coord (Bottom Right)
    574         glVertex2i(16,16);                           // Vertex Coord (Bottom Right)
    575         glTexCoord2f(cx+0.0625f,1.0f-cy-0.001f);     // Texture Coord (Top Right)
     575        glTexCoord2f(cx, cy+0.001f);            // Texture Coord (Bottom Left)
     576        glVertex2d(0,-16);                            // Vertex Coord (Bottom Left)
     577        glTexCoord2f(cx+0.0625f, cy+0.001f);    // Texture Coord (Bottom Right)
     578        glVertex2i(16,-16);                           // Vertex Coord (Bottom Right)
     579        glTexCoord2f(cx+0.0625f, cy+0.0625f);     // Texture Coord (Top Right)
    576580        glVertex2i(16,0);                            // Vertex Coord (Top Right)
    577         glTexCoord2f(cx,1.0f-cy-0.001f);             // Texture Coord (Top Left)
     581        glTexCoord2f(cx, cy+0.0625f);             // Texture Coord (Top Left)
    578582        glVertex2i(0,0);                             // Vertex Coord (Top Left)
    579583       glEnd();                                     // Done Building Our Quad (Character)
     
    621625
    622626Font* Font::defaultFont = NULL;
     627
     628void Font::createAsciiImage(const char* fileName)
     629{
     630  if (this->font == NULL)
     631    return;
     632  int height = this->getMaxHeight();
     633
     634  //
     635  SDL_Color tmpColor = {0, 0, 0};
     636  // Surface definition.
     637  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
     638  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_SWSURFACE,
     639      height*16, height*16,
     640      32,
     641#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
     642                                               0x000000FF,
     643                                               0x0000FF00,
     644                                               0x00FF0000,
     645                                               0xFF000000
     646#else
     647                                                   0xFF000000,
     648                                               0x00FF0000,
     649                                               0x0000FF00,
     650                                               0x000000FF
     651#endif
     652                                                );
     653    tmpRect.x = 0; tmpRect.y = 0; tmpRect.w = tmpSurf->w; tmpRect.h = tmpSurf->h;
     654    SDL_SetClipRect(tmpSurf, &tmpRect);
     655    int maxLineHeight = 0;
     656
     657    int posX, posY;
     658  // all the interessting Glyphs
     659    for (posY = 0; posY < 16; posY++)
     660    {
     661      for (posX = 0; posX < 16; posX++)
     662      {
     663        SDL_Surface* glyphSurf = NULL;
     664        if (likely(this->font != NULL))
     665        {
     666          SDL_Color white = {255, 255, 255};
     667          glyphSurf = TTF_RenderGlyph_Blended(this->font, posX+16*posY, white);
     668        }
     669        if( glyphSurf != NULL )
     670        {
     671          tmpRect.x = height*posX;
     672          tmpRect.y = height*posY;
     673          SDL_SetAlpha(glyphSurf, 0, 0);
     674
     675          SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect);
     676          SDL_FreeSurface(glyphSurf);
     677              // Outputting Glyphs to BMP-files.
     678/*
     679          char outname[512];
     680          if (i < 10)
     681          sprintf( outname, "%s-glyph-00%d.bmp", this->getName(), i );
     682          else if (i <100)
     683          sprintf( outname, "%s-glyph-0%d.bmp", this->getName(), i );
     684          else
     685          sprintf( outname, "%s-glyph-%d.bmp", this->getName(), i );
     686          SDL_SaveBMP(tmpSurf, outname);*/
     687
     688        }
     689      }
     690    }
     691    SDL_SaveBMP(tmpSurf, fileName);
     692    SDL_FreeSurface(tmpSurf);
     693}
     694
    623695/**
    624696 * initializes the default font
     
    747819
    748820  // all the interessting Glyphs
    749   for (int i = 0; i <= 127; i++)
     821  for (int i = 0; i < 128; i++)
    750822    {
    751823      SDL_Surface* glyphSurf = NULL;
     
    882954    {
    883955      x = 0; y = 0;
    884       for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
     956      for (i = 0; i <= FONT_HIGHEST_KNOWN_CHAR; i++)
    885957        {
    886           if(tmpGlyph = this->glyphArray[i])
     958          if((tmpGlyph = this->glyphArray[i]) != NULL)
    887959            {
    888960              // getting the height of the highest Glyph in the Line.
     
    902974            }
    903975        }
    904       if (i == FONT_HIGHEST_KNOWN_CHAR)
     976      if (i >= FONT_HIGHEST_KNOWN_CHAR-1 || size > 8192)
    905977        sizeOK = true;
    906978      else
Note: See TracChangeset for help on using the changeset viewer.