Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5367 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Oct 12, 2005, 11:07:22 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: font do no more handle any displayLists of Glyphs

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

Legend:

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

    r5357 r5367  
    106106      if (this->glyphArray[i] != NULL)
    107107      {
    108         if (this->glyphArray[i]->displayList != 0)
    109           glDeleteLists(this->glyphArray[i]->displayList, 1);
    110108        delete this->glyphArray[i];
    111109      }
     
    204202  {
    205203    float cx,cy;
    206     Glyph* glyph;
     204    Glyph* tmpGlyph;
    207205    this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
    208206    for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
    209207    {
    210       glyph = this->glyphArray[i] = new Glyph;
    211       glyph->displayList = glGenLists(1);
    212       if (!glIsList(glyph->displayList))
    213       {
    214         PRINTF(2)("Error creating glList for Font character %c\n", i);
    215         this->glyphArray[i] = NULL;
    216         delete glyph;
    217         continue;
    218       }
     208      tmpGlyph = this->glyphArray[i] = new Glyph;
    219209      cx=(float)(i%16)/16.0f;                  // X Position Of Current Character
    220210      cy=(float)(i/16)/16.0f;                  // Y Position Of Current Character
    221       glNewList(glyph->displayList, GL_COMPILE); // Start Building A List
    222       glBegin(GL_QUADS);                           // Use A Quad For Each Character
    223       glTexCoord2f(cx, cy+0.001f);            // Texture Coord (Bottom Left)
    224       glVertex2d(0,-16);                            // Vertex Coord (Bottom Left)
    225       glTexCoord2f(cx+0.0625f, cy+0.001f);    // Texture Coord (Bottom Right)
    226       glVertex2i(16,-16);                           // Vertex Coord (Bottom Right)
    227       glTexCoord2f(cx+0.0625f, cy+0.0625f);     // Texture Coord (Top Right)
    228       glVertex2i(16,0);                            // Vertex Coord (Top Right)
    229       glTexCoord2f(cx, cy+0.0625f);             // Texture Coord (Top Left)
    230       glVertex2i(0,0);                             // Vertex Coord (Top Left)
    231       glEnd();                                     // Done Building Our Quad (Character)
    232 //       glTranslated(12,0,0);                        // Move To The Right Of The Character
    233       glEndList();                                 // Done Building The Display List
    234       this->glyphArray[i]->width = 12;
     211
     212      tmpGlyph->texCoord[0] = cx;
     213      tmpGlyph->texCoord[1] = cx+0.0625f;
     214      tmpGlyph->texCoord[2] = cy+0.001f;
     215      tmpGlyph->texCoord[3] = cy+0.0625f;
     216      tmpGlyph->width = 16;
     217      tmpGlyph->bearingX = 16;
     218      tmpGlyph->bearingY = 16;
     219      tmpGlyph->height = 16;
    235220    }
    236221  }
     
    292277                                               0xFF000000
    293278#else
    294                                                    0xFF000000,
     279                                               0xFF000000,
    295280                                               0x00FF0000,
    296281                                               0x0000FF00,
     
    322307        SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect);
    323308        SDL_FreeSurface(glyphSurf);
    324               // Outputting Glyphs to BMP-files.
    325 /*
    326         char outname[512];
    327         if (i < 10)
    328         sprintf( outname, "%s-glyph-00%d.bmp", this->getName(), i );
    329         else if (i <100)
    330         sprintf( outname, "%s-glyph-0%d.bmp", this->getName(), i );
    331         else
    332         sprintf( outname, "%s-glyph-%d.bmp", this->getName(), i );
    333         SDL_SaveBMP(tmpSurf, outname);*/
    334 
    335309      }
    336310    }
     
    409383{
    410384  Glyph* rg = new Glyph;
    411   rg->displayList = 0;
    412385  rg->character = character;
    413386  if (likely (this->font!= NULL))
     
    485458      if (tmpRect.y + maxLineHeight > tmpSurf->h)
    486459      {
    487         PRINTF(1)("Protection, so font cannot write over the boundraries error (this should not heappen\n");
     460        PRINTF(1)("Protection, so font cannot write over the boundraries (!!this should not heappen!!)\n");
    488461        break;
    489462      }
     
    499472
    500473        SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect);
    501         TexCoord tmpTexCoord;
    502         tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w;
    503         tmpTexCoord.maxU = (float)(tmpRect.x + tmpGlyph->advance)/(float)tmpSurf->w;
    504         tmpTexCoord.minV = (float)(tmpRect.y)/(float)tmpSurf->w;
    505         tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w;
    506         tmpGlyph->displayList = glGenLists(1);
    507 
    508         glNewList(tmpGlyph->displayList, GL_COMPILE);
    509         glBegin(GL_QUADS);
    510         glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.minV);
    511         glVertex2d(0, - tmpGlyph->bearingY);
    512         glTexCoord2f(tmpTexCoord.minU, tmpTexCoord.maxV);
    513         glVertex2d(0, tmpGlyph->height - tmpGlyph->bearingY);
    514         glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.maxV);
    515         glVertex2d(tmpGlyph->width, tmpGlyph->height - tmpGlyph->bearingY);
    516         glTexCoord2f(tmpTexCoord.maxU, tmpTexCoord.minV);
    517         glVertex2d(tmpGlyph->width, - tmpGlyph->bearingY);
    518         glEnd();
    519         glEndList();
     474        tmpGlyph->texCoord[0] = (float)tmpRect.x/(float)tmpSurf->w;
     475        tmpGlyph->texCoord[1] = (float)(tmpRect.x + tmpGlyph->advance)/(float)tmpSurf->w;
     476        tmpGlyph->texCoord[2] = (float)(tmpRect.y)/(float)tmpSurf->w;
     477        tmpGlyph->texCoord[3] = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w;
    520478        SDL_FreeSurface(glyphSurf);
    521479
  • trunk/src/lib/graphics/text_engine/font.h

    r5355 r5367  
    4747  int      advance;           //!< How big a Glyph would be in monospace-mode
    4848
    49   // OpenGL-specific
    50   //  TexCoord texCoord;      //!< A Texture Coordinate for this glyph.
    51   GLuint   displayList;       //!< DiplayList to render this Glyph.
     49  GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
    5250};
    5351
  • trunk/src/lib/graphics/text_engine/text.cc

    r5362 r5367  
    7070  this->blending = TEXT_DEFAULT_BLENDING;
    7171  this->color = TEXT_DEFAULT_COLOR;
     72  this->size = TEXT_DEFAULT_SIZE;
    7273  this->setType(TEXT_RENDER_DYNAMIC);
    7374
     
    240241    if (likely(tmpText != NULL))
    241242    {
     243      Glyph* tmpGlyph;
    242244      while (likely(*tmpText != '\0'))
    243245      {
    244         if(likely(glyphArray[*tmpText] != NULL))
     246        if(likely((tmpGlyph = glyphArray[*tmpText]) != NULL))
    245247        {
    246           glCallList(glyphArray[*tmpText]->displayList);
     248          glBegin(GL_QUADS);
     249          glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
     250          glVertex2d(0, - tmpGlyph->bearingY);
     251          glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
     252          glVertex2d(0, tmpGlyph->height - tmpGlyph->bearingY);
     253          glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
     254          glVertex2d(tmpGlyph->width, tmpGlyph->height - tmpGlyph->bearingY);
     255          glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
     256          glVertex2d(tmpGlyph->width, - tmpGlyph->bearingY);
     257          glEnd();
     258          glEndList();
    247259          glTranslatef(glyphArray[*tmpText]->width, 0, 0);
    248260        }
  • trunk/src/lib/graphics/text_engine/text.h

    r5362 r5367  
    6060    void setFont(const char* fontFile, unsigned int fontSize);
    6161
    62     void setType(TEXT_RENDER_TYPE type);
    6362    void setText(const char* text, bool isExtern = false);
     63
    6464    /** @returns the String this Text displays */
    6565    inline const char* getText() const { return (externText == NULL)?this->text:this->externText; };
     
    6868    /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */
    6969    void setColor(float r, float g, float b) { this->color = Vector(r,g,b); };
     70    /** sets the Size of the Font */
     71    void setSize(float size) { this->size = size; };
    7072
     73    void setType(TEXT_RENDER_TYPE type);
    7174    void createTexture();
    7275
     
    8790    Vector            color;          //!< The color of the font.
    8891    float             blending;       //!< The blending intensity.
     92    float             size;           //!< The size of the Font.
    8993
    9094  // placement in openGL
Note: See TracChangeset for help on using the changeset viewer.