Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 7, 2005, 1:30:11 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: now the TextEngine generates Display-Lists

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc

    r3736 r3740  
    437437   */
    438438  int numberOfGlyphs = 90;
     439
    439440  this->initGlyphs(33, numberOfGlyphs);
     441
    440442  int rectSize = this->findOptimalFastTextureSize();
    441443
    442   PRINTF(1)("rectSize = %d\n", rectSize);
    443 
    444   SDL_Color tmpColor;
    445   tmpColor.r = tmpColor.g = tmpColor.b = 0;
     444  // setting default values. (maybe not needed afterwards)
     445  //  SDL_Color tmpColor;  tmpColor.r = tmpColor.g = tmpColor.b = 0;
     446  // Surface definition.
     447  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
    446448  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(
    447449                                               SDL_SWSURFACE,
     
    460462#endif
    461463                                               );
    462   SDL_Rect tmpRect;
    463464
    464465  tmpRect.x = 0; tmpRect.y = 0; tmpRect.w = tmpSurf->w; tmpRect.h = tmpSurf->h;
    465466  SDL_SetClipRect(tmpSurf, &tmpRect);
    466467  int maxLineHeight = 0;
    467   for ( int i = 33; i <= 122; i++ )
    468     {
    469       SDL_Surface* glyph = NULL;
    470       SDL_Surface* glyph2 = NULL;
     468
     469  // all the interessting Glyphs
     470  for (int i = 33; i <= 122; i++)
     471    {
     472      SDL_Surface* glyphSurf = NULL;
    471473      Glyph* tmpGlyph;
    472474
    473       tmpGlyph = this->glyphArray[i];
    474       if (tmpGlyph->height > maxLineHeight)
    475         maxLineHeight = tmpGlyph->height;
    476 
    477       if (tmpRect.x+tmpGlyph->width > tmpSurf->w)
     475      if (tmpGlyph = this->glyphArray[i])
    478476        {
    479           tmpRect.x = 0;
    480           tmpRect.y = tmpRect.y + maxLineHeight;
    481           printf("x:%d, y:%d\n", tmpRect.x, tmpRect.y);
     477          if (tmpGlyph->height > maxLineHeight)
     478            maxLineHeight = tmpGlyph->height;
     479         
     480          if (tmpRect.x+tmpGlyph->width > tmpSurf->w)
     481            {
     482              tmpRect.x = 0;
     483              tmpRect.y = tmpRect.y + maxLineHeight + 1;
     484              maxLineHeight = 0;
     485            }
     486          if (tmpRect.y + maxLineHeight > tmpSurf->h)
     487            {
     488              PRINTF(1)("Protection, so font cannot write over the boundraries error (this should not heappen\n");
     489              break;
     490            }
     491          // reading in the new Glyph
     492          glyphSurf = TTF_RenderGlyph_Blended(this->font,
     493                                              i,
     494                                              this->currentText->color);
     495          //                                     tmpColor);
     496          if( glyphSurf )
     497            {
     498              SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect);
     499              TexCoord tmpTexCoord;
     500              tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w;
     501              tmpTexCoord.maxU = (float)(tmpRect.x+tmpGlyph->width)/(float)tmpSurf->w;
     502              tmpTexCoord.minV = (float)tmpRect.y/(float)tmpSurf->w;
     503              tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w;
     504              tmpGlyph->displayList = glGenLists(1);
     505              glNewList(tmpGlyph->displayList, GL_COMPILE);
     506              glBegin(GL_QUADS);
     507              glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.minV);
     508              glVertex2d(0, 0);
     509              glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.maxV);
     510              glVertex2d(0, 1);
     511              glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.maxV);
     512              glVertex2d(1, 1);
     513              glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.minV);
     514              glVertex2d(1, 0);
     515              glEnd();
     516              glEndList();
     517              SDL_FreeSurface(glyphSurf);
     518
     519              tmpRect.x += tmpGlyph->width + 1;
     520
     521              // Outputting Glyphs to BMP-files.
     522              /*
     523                char outname[64];
     524                if (i < 10)
     525                sprintf( outname, "glyph-00%d.bmp", i );
     526                else if (i <100)
     527                sprintf( outname, "glyph-0%d.bmp", i );
     528                else
     529                sprintf( outname, "glyph-%d.bmp", i );
     530                SDL_SaveBMP(tmpSurf, outname);
     531              */
     532            }
    482533        }
    483       if (tmpRect.y +tmpGlyph->height > tmpSurf->h)
    484         {
    485           PRINTF(1)("Protection, so font cannot write over the boundraries error\n");
    486           break;
    487         }
    488 
    489 
    490       glyph = TTF_RenderGlyph_Shaded(this->font,
    491                                      i,
    492                                      this->currentText->color,
    493                                      tmpColor);
    494 
    495       if( glyph ) {
    496         char outname[64];
    497         if (i<10)
    498           sprintf( outname, "glyph-00%d.bmp", i );
    499         else if (i <100)
    500           sprintf( outname, "glyph-0%d.bmp", i );
    501         else
    502           sprintf( outname, "glyph-%d.bmp", i );
    503 
    504         SDL_SetColorKey (glyph, SDL_SRCCOLORKEY, 1);
    505         if (glyph->flags & SDL_SRCALPHA)
    506           printf("glyph-flags: %d\n", glyph->flags);
    507 
    508         SDL_BlitSurface(glyph, NULL, tmpSurf, &tmpRect);
    509         SDL_SaveBMP(tmpSurf, outname);
    510         tmpRect.x += tmpGlyph->width+1;
    511         delete tmpGlyph;
    512       }
    513     }
    514   /*
    515     tmpSurf = TTF_RenderText_Blended(this->font,
    516     this->name,
    517     this->currentText->color);
    518   */
     534    }
     535
     536  GLuint tmpRet = this->loadTexture(tmpSurf, NULL);
     537  SDL_FreeSurface(tmpSurf);
     538  return tmpRet;
    519539}
    520540
     
    537557  w = powerOfTwo(surface->w);
    538558  h = powerOfTwo(surface->h);
    539   texCoord->minU = 0.0f;
    540   texCoord->minV = 0.0f;
    541   texCoord->maxU = (GLfloat)surface->w / w;
    542   texCoord->maxV = (GLfloat)surface->h / h;
    543  
     559  if (texCoord)
     560    {
     561      texCoord->minU = 0.0f;
     562      texCoord->minV = 0.0f;
     563      texCoord->maxU = (GLfloat)surface->w / w;
     564      texCoord->maxV = (GLfloat)surface->h / h;
     565    }
    544566  image = SDL_CreateRGBSurface(
    545567                               SDL_SWSURFACE,
     
    631653   \todo: this algorithm can be a lot more faster, althought it does
    632654   not really matter within the init-context, and 128 glyphs.
     655
     656   This function searches for a 2^n sizes texture-size, this is for
     657   openGL-version < 1.2 compatibility. and because it is realy easy like this.
    633658*/
    634659int GLFont::findOptimalFastTextureSize(void)
     
    637662  int x,y; // the counters
    638663  int maxLineHeight;
    639   int size = 32; // starting Value, we have to start somewhere
     664  int size = 32;      // starting Value, we have to start somewhere 32 seems reasonable.
    640665  bool sizeOK = false;
    641666  Glyph* tmpGlyph;
Note: See TracChangeset for help on using the changeset viewer.