Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3768 in orxonox.OLD for orxonox/branches/textEngine/src


Ignore:
Timestamp:
Apr 9, 2005, 6:45:12 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: some more simple movement around classes

Location:
orxonox/branches/textEngine/src/lib/graphics/font
Files:
2 edited

Legend:

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

    r3767 r3768  
    3737
    3838////////////
     39/// TEXT ///
     40////////////
     41
     42Text::Text(void)
     43{
     44
     45}
     46
     47Text::~Text(void)
     48{
     49
     50}
     51
     52
     53void Text::setBindNode(PNode* bindNode)
     54{
     55  this->bindNode = bindNode;
     56}
     57
     58/**
     59   \brief sets the Type of this Text
     60   \param type the type to set.
     61*/
     62void Text::setType(int type)
     63{
     64  this->type = type;
     65}
     66
     67
     68/**
     69   \brief Sets a new Text to the font
     70   \param text the new text to set
     71*/
     72void Text::setText(const char* text)
     73{
     74  if (this->text)
     75    delete []this->text;
     76  this->text = new char[strlen(text)+1];
     77  strcpy(this->text, text);
     78}
     79
     80/**
     81   \brief sets a Position.
     82   \param x the x-position in pixels from the left border
     83   \param y the y-position in pixels from the top border
     84*/
     85void Text::setPosition(int x, int y)
     86{
     87  this->posSize.x = x;
     88  this->posSize.y = y;
     89}
     90
     91
     92/**
     93   \brief draws the Font
     94   \todo FIX this is to slow/static
     95*/
     96void Text::draw(void)
     97{
     98  // storing all the Transformation Matrices.
     99
     100  GLdouble modMat[16];
     101  GLdouble projMat[16];
     102  GLint viewPort[4];
     103  glGetDoublev(GL_PROJECTION_MATRIX, projMat);
     104  glGetDoublev(GL_MODELVIEW_MATRIX, modMat);
     105  glGetIntegerv(GL_VIEWPORT, viewPort);
     106//    this->enter2DMode();
     107
     108
     109  // setting the Position of this Text.
     110  Vector pos;
     111  if (this->bindNode)
     112    {
     113      GLdouble x = this->bindNode->getAbsCoor().x;
     114      GLdouble y = this->bindNode->getAbsCoor().y;
     115      GLdouble z = this->bindNode->getAbsCoor().z;
     116      GLdouble tmp[3];
     117      gluProject(x, y, z, modMat, projMat, viewPort, tmp, tmp+1, tmp+2);
     118      printf("test %f %f %f,\n", tmp[0], tmp[1], tmp[2]);
     119      pos.x = tmp[0] + this->posSize.x;
     120      pos.y = GraphicsEngine::getInstance()->getResolutionY() - tmp[1] + this->posSize.y;
     121      pos.z = tmp[2];
     122    }
     123  else
     124    {
     125      pos.x = this->posSize.x;
     126      pos.y = this->posSize.y;
     127      pos.z = 0;
     128    }
     129
     130  // drawing this Text.
     131  if(type == TEXT_STATIC)
     132    {
     133      glBindTexture(GL_TEXTURE_2D, this->texture);
     134      glEnable(GL_TEXTURE_2D);
     135      glBegin(GL_QUADS);
     136     
     137      glTexCoord2f(this->texCoord.minU, this->texCoord.minV);
     138      glVertex2i(pos.x,   pos.y  );
     139     
     140      glTexCoord2f(this->texCoord.maxU, this->texCoord.minV);
     141      glVertex2i(pos.x + this->posSize.w, pos.y  );
     142     
     143      glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV);
     144      glVertex2i(pos.x + this->posSize.w, pos.y + this->posSize.h);
     145     
     146      glTexCoord2f(this->texCoord.minU, this->texCoord.maxV);
     147      glVertex2i(pos.x, pos.y + this->posSize.h);
     148     
     149      glEnd();
     150    }
     151  else //(if type & TEXT_DYNAMIC)
     152    {
     153      Glyph** glyphArray = this->font->getGlyphArray();
     154      glBindTexture(GL_TEXTURE_2D, this->font->getFastTextureID());
     155      //      glEnable(GL_TEXTURE_2D);
     156      glTranslatef(pos.x, pos.y, 0);
     157
     158      printf("%d, %d\n", this->font->getFastTextureID(), glyphArray[65]->displayList);
     159      char* tmpText = this->text;
     160      while (*tmpText != '\0')
     161        {
     162          if(glyphArray[*tmpText])
     163            {
     164              glCallList(glyphArray[*tmpText]->displayList);
     165              glTranslatef(glyphArray[*tmpText]->width, 0, 0);
     166            }
     167          tmpText++;
     168        }
     169    }
     170  //  this->leave2DMode();
     171}
     172
     173
     174
     175////////////
    39176/// FONT ///
    40177////////////
    41 
    42178/**
    43179   \brief constructs a Font
     
    66202 
    67203  this->setSize(fontSize);
    68   this->setType(TEXT_DYNAMIC);
    69  
    70   this->currentText->renderStyle = TTF_STYLE_NORMAL;
    71 
     204  this->setStyle(TTF_STYLE_NORMAL);
    72205  this->setFont(fontFile);
    73206
    74   this->setPosition(0, 0);
    75 
    76   this->setText(FONT_DEFAULT_TEXT);
     207
     208  this->currentText->setType(TEXT_DYNAMIC);
     209  this->currentText->setPosition(0, 0);
     210
     211  this->currentText->setText(FONT_DEFAULT_TEXT);
    77212 
    78213  this->setColor(r, g, b);
     
    128263}
    129264
    130 void Font::setBindNode(PNode* bindNode)
    131 {
    132   this->currentText->bindNode = bindNode;
    133 }
    134 
    135 /**
    136    \brief sets the Type of this Text
    137    \param type the type to set.
    138 */
    139 void Font::setType(int type)
    140 {
    141   this->currentText->type = type;
    142 }
    143 
    144 
    145 /**
    146    \brief Sets a new Text to the font
    147    \param text the new text to set
    148 */
    149 void Font::setText(const char* text)
    150 {
    151   if (this->currentText->text)
    152     delete []this->currentText->text;
    153   this->currentText->text = new char[strlen(text)+1];
    154   strcpy(this->currentText->text, text);
    155 }
    156 
    157265/**
    158266   \brief sets a specific renderStyle
     
    162270void Font::setStyle(char* renderStyle)
    163271{
    164   this->currentText->renderStyle = TTF_STYLE_NORMAL;
     272  this->renderStyle = TTF_STYLE_NORMAL;
    165273 
    166274  for (int i = 0; i < strlen(renderStyle); i++)
    167275    if (strncmp(renderStyle+i, "b", 1) == 0)
    168       this->currentText->renderStyle |= TTF_STYLE_BOLD;
     276      this->renderStyle |= TTF_STYLE_BOLD;
    169277    else if (strncmp(renderStyle+i, "i", 1) == 0)
    170       this->currentText->renderStyle |= TTF_STYLE_ITALIC;
     278      this->renderStyle |= TTF_STYLE_ITALIC;
    171279    else if (strncmp(renderStyle+i, "u", 1) == 0)
    172       this->currentText->renderStyle |= TTF_STYLE_UNDERLINE;
     280      this->renderStyle |= TTF_STYLE_UNDERLINE;
    173281
    174282  if (this->font)
    175     TTF_SetFontStyle(this->font, this->currentText->renderStyle);
     283    TTF_SetFontStyle(this->font, this->renderStyle);
    176284  else
    177285    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
    178286}
     287
     288
    179289
    180290/**
     
    198308  this->currentText->color.g = g;
    199309  this->currentText->color.b = b;
    200 }
    201 
    202 /**
    203    \brief sets a Position.
    204    \param x the x-position in pixels from the left border
    205    \param y the y-position in pixels from the top border
    206 */
    207 void Font::setPosition(int x, int y)
    208 {
    209   this->currentText->textPosSize.x = x;
    210   this->currentText->textPosSize.y = y;
    211 }
    212 
    213 /**
    214    \brief draws the Font
    215    \todo FIX this is to slow/static
    216 */
    217 void Font::draw(void)
    218 {
    219   // storing all the Transformation Matrices.
    220   GLdouble modMat[16];
    221   GLint viewPort[4];
    222   glGetDoublev(GL_PROJECTION_MATRIX, this->projMat);
    223   glGetDoublev(GL_MODELVIEW_MATRIX, modMat);
    224   glGetIntegerv(GL_VIEWPORT, viewPort);
    225   this->enter2DMode();
    226 
    227   // setting the Position of this Text.
    228   Vector pos;
    229   if (this->currentText->bindNode)
    230     {
    231       GLdouble x = this->currentText->bindNode->getAbsCoor().x;
    232       GLdouble y = this->currentText->bindNode->getAbsCoor().y;
    233       GLdouble z = this->currentText->bindNode->getAbsCoor().z;
    234       GLdouble tmp[3];
    235       gluProject(x, y, z, modMat, projMat, viewPort, tmp, tmp+1, tmp+2);
    236       printf("test %f %f %f,\n", tmp[0], tmp[1], tmp[2]);
    237       pos.x = tmp[0] + this->currentText->textPosSize.x;
    238       pos.y = GraphicsEngine::getInstance()->getResolutionY() - tmp[1] + this->currentText->textPosSize.y;
    239       pos.z = tmp[2];
    240     }
    241   else
    242     {
    243       pos.x = this->currentText->textPosSize.x;
    244       pos.y = this->currentText->textPosSize.y;
    245       pos.z = 0;
    246     }
    247 
    248   // drawing this Text.
    249   if(currentText->type == TEXT_STATIC)
    250     {
    251       glBindTexture(GL_TEXTURE_2D, this->currentText->texture);
    252       glEnable(GL_TEXTURE_2D);
    253       glBegin(GL_QUADS);
    254      
    255       glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.minV);
    256       glVertex2i(pos.x,   pos.y  );
    257      
    258       glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.minV);
    259       glVertex2i(pos.x + this->currentText->textPosSize.w, pos.y  );
    260      
    261       glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.maxV);
    262       glVertex2i(pos.x + this->currentText->textPosSize.w, pos.y + this->currentText->textPosSize.h);
    263      
    264       glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.maxV);
    265       glVertex2i(pos.x, pos.y + this->currentText->textPosSize.h);
    266      
    267       glEnd();
    268     }
    269   else //(if currentText->type & TEXT_DYNAMIC)
    270     {
    271       glBindTexture(GL_TEXTURE_2D, this->fastTextureID);
    272       //      glEnable(GL_TEXTURE_2D);
    273       glTranslatef(pos.x, pos.y, 0);
    274 
    275       printf("%d, %d\n", this->fastTextureID, glyphArray[65]->displayList);
    276       char* tmpText = this->currentText->text;
    277       while (*tmpText != '\0')
    278         {
    279           if(glyphArray[*tmpText])
    280             {
    281               glCallList(this->glyphArray[*tmpText]->displayList);
    282               glTranslatef(this->glyphArray[*tmpText]->width, 0, 0);
    283             }
    284           tmpText++;
    285         }
    286     }
    287   this->leave2DMode();
    288310}
    289311
     
    304326    this->currentText->texture = loadTexture(tmpSurf, &this->currentText->texCoord);
    305327
    306   this->currentText->textPosSize.w = tmpSurf->w;
    307   this->currentText->textPosSize.h = tmpSurf->h;
     328  this->currentText->posSize.w = tmpSurf->w;
     329  this->currentText->posSize.h = tmpSurf->h;
    308330  SDL_FreeSurface(tmpSurf);
    309331}
     
    748770
    749771
    750 void m_inverse(const float *m, float *out)
    751 {
    752     float det;
    753     det=  m[0]*m[5]*m[10];
    754     det+= m[4]*m[9]*m[2];
    755     det+= m[8]*m[1]*m[6];
    756     det-= m[8]*m[5]*m[2];
    757     det-= m[4]*m[1]*m[10];
    758     det-= m[0]*m[9]*m[6];
    759    
    760     if(det!= 0.0)
    761         det=1.0/det;
    762     out[0]=  (m[5]*m[10]-m[9]*m[6])*det;
    763     out[1]= -(m[1]*m[10]-m[9]*m[2])*det;
    764     out[2]=  (m[1]*m[6]-m[5]*m[2])*det;
    765     out[3]= 0.0;
    766     out[4]= -(m[4]*m[10]-m[8]*m[6])*det;
    767     out[5]=  (m[0]*m[10]-m[8]*m[2])*det;
    768     out[6]= -(m[0]*m[6]-m[4]*m[2])*det;
    769     out[7]= 0.0;
    770     out[8]=  (m[4]*m[9]-m[8]*m[5])*det;
    771     out[9]= -(m[0]*m[9]-m[8]*m[1])*det;
    772     out[10]= (m[0]*m[5]-m[4]*m[1])*det;
    773     out[11]= 0.0;
    774     out[12]=- (m[12]*out[0]+m[13]*out[4]+m[14]*out[8]);
    775     out[13]=- (m[12]*out[1]+m[13]*out[5]+m[14]*out[9]);
    776     out[14]=- (m[12]*out[2]+m[13]*out[6]+m[14]*out[10]);
    777     out[15]= 1.0;
    778 }
    779 
    780 
    781 Vector mvMult(const float *mat, const Vector* vec)
    782 {
    783   Vector tmp;
    784   tmp.x = mat[0]*vec->x+mat[1]*vec->y+mat[2]*vec->z;
    785   tmp.y = mat[4]*vec->x+mat[5]*vec->y+mat[6]*vec->z;
    786   tmp.z = mat[8]*vec->x+mat[9]*vec->y+mat[10]*vec->z;
    787   return tmp;
    788 }
    789 
    790 
    791 
    792 
    793 
    794 
    795 
    796 
    797 
    798 
    799 
    800 
    801 
    802 
    803 
     772
     773
     774
     775
     776
     777
     778
     779///////////////////
     780/// TEXT-ENGINE ///
     781///////////////////
    804782/**
    805783   \brief standard constructor
  • orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h

    r3767 r3768  
    2626// FORWARD DECLARATION
    2727class PNode;
     28class Font;
    2829template<class T> class tList;
    2930
     
    8586};
    8687
     88////////////
     89/// TEXT ///
     90////////////
    8791//! Represents one textElement.
    8892class Text
    8993{
    9094 public:
     95  Text(void);
     96  ~Text(void);
     97
     98  void setBindNode(PNode* bindNode);
     99
     100  void setType(int type);
     101  void setText(const char* text);
     102  void setPosition(int x, int y);
     103
     104  virtual void draw(void);
     105
     106
     107  Font* font;
     108
    91109  int type;                      //!< The type of this Font.
    92110  char* text;                    //!< The text to display
     
    95113  GLuint texture;                //!< A GL-texture to hold the text
    96114  TexCoord texCoord;             //!< Texture-coordinates \todo fix this to have a struct
    97   SDL_Rect textPosSize;          //!< An SDL-Rectangle representing the position and size of the Text on the screen.
    98   int renderStyle;               //!< The Renderstyle
     115  SDL_Rect posSize;          //!< An SDL-Rectangle representing the position and size of the Text on the screen.
    99116 
    100117  PNode* bindNode;               //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
    101118};
    102119
    103 
     120////////////
     121/// FONT ///
     122////////////
    104123//! A class to handle a Font of a certain ttf-File, Size and Color.
    105124class Font
     
    114133  void setSize(unsigned int fontSize);
    115134  void setColor(Uint8 r, Uint8 g, Uint8 b);
    116 
    117   // text
    118   void setBindNode(PNode* bindNode);
    119   void setType(int type);
    120   void setText(const char* text);
    121135  void setStyle(char* renderStyle);
    122   void setPosition(int x, int y);
     136
     137  inline Glyph** getGlyphArray(void) {return glyphArray;}
     138  inline GLuint getFastTextureID(void) {return fastTextureID;}
    123139  void createTexture(void);
    124140 
    125   virtual void draw(void);
    126 
     141 
    127142 private:
    128143  // general purpose
     
    133148  char* fontFile;                   //!< The fontfile from whitch the font was loaded.
    134149  unsigned int fontSize;            //!< The size of the font in pixels. each Font has one size.
     150  int renderStyle;               //!< The Renderstyle
    135151 
    136152  Glyph** glyphArray;               //!< An Array of all the Glyphs stored in the Array of Glyphs.
     
    159175
    160176};
    161 
    162 void m_inverse(const float *m, float *out);
    163 Vector mvMult(const float *mat, const Vector* vec);
    164177
    165178
     
    183196  static TextEngine* singletonRef;
    184197
     198  tList<Font>* fontList;
     199
    185200};
    186201
Note: See TracChangeset for help on using the changeset viewer.