Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 14, 2005, 12:15:38 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: text renders as good as before, but now as Element2D

File:
1 edited

Legend:

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

    r4850 r4856  
    6161  this->blending = 1.0f;
    6262  this->setType(type);
    63   this->setPosition(0, 0);
    6463
    6564  this->setText(FONT_DEFAULT_TEXT);
     
    120119
    121120/**
    122  *  sets a Position.
    123  * @param x the x-position in pixels from the left border
    124  * @param y the y-position in pixels from the top border
    125 */
    126 void Text::setPosition(int x, int y)
    127 {
    128   this->posSize.x = x;
    129   this->posSize.y = y;
    130 }
    131 
    132 /**
    133  *  sets the text-alignment
    134  * @param alignment the alignment to set
    135 */
    136 void Text::setAlignment(TEXT_ALIGNMENT alignment)
    137 {
    138   this->alignment = alignment;
    139 }
    140 
    141 /**
    142121 *  sets a new color to the font
    143122 * @param r Red
     
    180159void Text::draw() const
    181160{
    182   // setting the Position of this Text.
    183   Vector pos;
    184   if (this->alignment == TEXT_ALIGN_SCREEN_CENTER)
    185     {
    186       pos.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->posSize.x;
    187       pos.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->posSize.y;
    188       pos.z = 0;
    189     }
    190   else if (this->bindNode)
    191     {
    192       GLdouble x = this->bindNode->getAbsCoor().x;
    193       GLdouble y = this->bindNode->getAbsCoor().y;
    194       GLdouble z = this->bindNode->getAbsCoor().z;
    195       GLdouble tmp[3];
    196       gluProject(x, y, z, GraphicsEngine::modMat, GraphicsEngine::projMat, GraphicsEngine::viewPort, tmp, tmp+1, tmp+2);
    197       pos.x = tmp[0] + this->posSize.x;
    198       pos.y = GraphicsEngine::getInstance()->getResolutionY() - tmp[1] + this->posSize.y;
    199       pos.z = tmp[2];
    200     }
    201   else
    202     {
    203       pos.x = this->posSize.x;
    204       pos.y = this->posSize.y;
    205       pos.z = 0;
    206     }
    207 
     161  printf("%s: %d %d, %f\n", this->getName(), absPos2D.x, absPos2D.y, absPos2D.depth);
     162
     163  glPushMatrix();
     164  // transform for alignment.
     165  if (this->alignment == TEXT_ALIGN_RIGHT)
     166    glTranslatef(-this->posSize.w, 0, 0);
     167  else if (this->alignment == TEXT_ALIGN_CENTER || this->alignment == TEXT_ALIGN_SCREEN_CENTER)
     168    glTranslatef(-this->posSize.w/2, 0, 0);
     169
     170  // drawing this Text.
    208171  // setting the Blending effects
    209172  glColor4f(1.0f,1.0f,1.0f, this->blending);
     
    212175  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    213176
    214   glPushMatrix();
    215   // transform for alignment.
    216   if (this->alignment == TEXT_ALIGN_RIGHT)
    217     glTranslatef(-this->posSize.w, 0, 0);
    218   else   if (this->alignment == TEXT_ALIGN_CENTER || this->alignment == TEXT_ALIGN_SCREEN_CENTER)
    219     glTranslatef(-this->posSize.w/2, 0, 0);
    220 
    221   // drawing this Text.
    222177  if(type == TEXT_STATIC)
    223178    {
    224179      glBindTexture(GL_TEXTURE_2D, this->texture);
    225       glEnable(GL_TEXTURE_2D);
    226180      glBegin(GL_QUADS);
    227181
    228182      glTexCoord2f(this->texCoord.minU, this->texCoord.minV);
    229       glVertex2f(pos.x,   pos.y  );
     183      glVertex2f(this->absPos2D.x,   this->absPos2D.y  );
    230184
    231185      glTexCoord2f(this->texCoord.maxU, this->texCoord.minV);
    232       glVertex2f(pos.x + this->posSize.w, pos.y  );
     186      glVertex2f(this->absPos2D.x + this->posSize.w, this->absPos2D.y  );
    233187
    234188      glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV);
    235       glVertex2f(pos.x + this->posSize.w, pos.y + this->posSize.h);
     189      glVertex2f(this->absPos2D.x + this->posSize.w, absPos2D.y + this->posSize.h);
    236190
    237191      glTexCoord2f(this->texCoord.minU, this->texCoord.maxV);
    238       glVertex2f(pos.x, pos.y + this->posSize.h);
     192      glVertex2f(absPos2D.x, absPos2D.y + this->posSize.h);
    239193
    240194      glEnd();
     
    245199      glBindTexture(GL_TEXTURE_2D, this->font->getFastTextureID());
    246200      //      glEnable(GL_TEXTURE_2D);
    247       glTranslatef(pos.x, pos.y, 0);
     201      glTranslatef(absPos2D.x, absPos2D.y, 0);
    248202
    249203      const char* tmpText = this->text;
     
    906860
    907861/**
    908  *  draws all the Texts that have been initialized
    909 */
    910 void TextEngine::draw() const
    911 {
    912   // entering 3D-mode
    913   GraphicsEngine::enter2DMode();
    914   glEnable(GL_TEXTURE_2D);
    915   glEnable(GL_BLEND);
    916   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    917 
    918   // drawing all the texts
    919   tIterator<Text>* textIterator = textList->getIterator();
    920   Text* drawText = textIterator->nextElement();
    921   while( drawText != NULL)
    922     {
    923       drawText->draw();
    924       drawText = textIterator->nextElement();
    925     }
    926   delete textIterator;
    927   // retruning to the previous mode
    928   GraphicsEngine::leave2DMode();
    929 }
    930 
    931 /**
    932862 *  outputs some nice Debug information
    933863
Note: See TracChangeset for help on using the changeset viewer.