Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4856 in orxonox.OLD for orxonox/trunk/src/lib/graphics


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

Location:
orxonox/trunk/src/lib/graphics
Files:
5 edited

Legend:

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

    r4850 r4856  
    427427  }
    428428  Render2D::getInstance()->tick(dt);
    429 
    430429}
    431430
     
    450449      this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0);
    451450      this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
    452       this->geTextCFPS->setPosition(5, 5);
     451      this->geTextCFPS->setPosition2D(5, 5);
    453452      this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0);
    454453      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
    455       this->geTextMaxFPS->setPosition(5, 35);
     454      this->geTextMaxFPS->setPosition2D(5, 35);
    456455      this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 35, TEXT_DYNAMIC, 0, 255, 0);
    457456      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
    458       this->geTextMinFPS->setPosition(5, 65);
     457      this->geTextMinFPS->setPosition2D(5, 65);
    459458#endif /* NO_TEXT */
    460459    }
  • orxonox/trunk/src/lib/graphics/render2D/element_2d.cc

    r4847 r4856  
    4848  this->setClassID(CL_ELEMENT_2D, "Element2D");
    4949
     50  this->setPosition2D(0,0);
     51  this->setAlignment(E2D_ALIGN_CENTER);
     52
    5053  Render2D::getInstance()->registerElement2D(this);
    51 
    5254}
    5355
     
    5860void Element2D::positioning()
    5961{
    60   // setting the Position of this ELEM2D.
    61   if (this->bindNode)
     62
     63  // setting the Position of this 2D-Element.
     64  if (this->alignment == E2D_ALIGN_SCREEN_CENTER)
     65  {
     66    absPos2D.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->relPos2D[0];
     67    absPos2D.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->relPos2D[1];
     68    absPos2D.depth = 0;
     69  }
     70  else if (this->bindNode)
    6271  {
    6372    GLdouble projectPos[3];
  • orxonox/trunk/src/lib/graphics/render2D/element_2d.h

    r4850 r4856  
    2626typedef enum
    2727{
    28   E2D_ALIGN_NONE,
    29   E2D_ALIGN_LEFT,
    30   E2D_ALIGN_RIGHT,
    31   E2D_ALIGN_CENTER,
    32   E2D_ALIGN_SCREEN_CENTER
     28  E2D_ALIGN_NONE                =     0,
     29  E2D_ALIGN_LEFT                =     1,
     30  E2D_ALIGN_RIGHT               =     2,
     31  E2D_ALIGN_CENTER              =     4,
     32  E2D_ALIGN_SCREEN_CENTER       =     8
    3333} E2D_ALIGNMENT;
    3434
     
    3939  float       y;                 //!< The y-coordinate.
    4040  float       depth;             //!< The distance from the viewing plane.
    41 
    4241};
    4342
     
    4948    virtual ~Element2D();
    5049
    51     void setPosition2D(int xCoord, int yCoord);
    52     void setLayer(E2DLayer layer);
     50    /** @param xCoord the xCoordinate @param yCoord the y-Coordinate. These coordinates are Relative */
     51    inline void setPosition2D(int xCoord, int yCoord) { this->relPos2D[0] = xCoord; this->relPos2D[1] = yCoord; };
     52    /** this returns the Absolute Position on the screen set by positioning in the tick-phase */
     53    inline const Position2D& getPosition2D() { return this->absPos2D; };
     54    /** @param alignment the new Alignment of the 2D-Element */
     55    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
     56    /** @param layer the Layer this is drawn on */
     57    inline void setLayer(E2DLayer layer) { this->layer = layer; };
    5358    /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
    5459    inline void setVisibility(bool visible) { this->visible = visible; };
    5560    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
    56  // inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
     61   inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
    5762
    5863    /** @returns the visibility state */
     
    6873  protected:
    6974    const PNode*            bindNode;         //!< a node over which to display this 2D-element
     75    int                     relPos2D[2];      //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.)
     76    Position2D              absPos2D;         //!< The absolute position of the 2D-Element.
     77
     78    E2D_ALIGNMENT           alignment;        //!< How the Element is aligned around its Position
     79
    7080  private:
    7181    bool                    visible;
    72     int                     relPos2D[2];      //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.)
    73     Position2D              absPos2D;         //!< The absolute position of the 2D-Element.
    7482    E2DLayer                layer;
    7583
    76     E2D_ALIGNMENT           alignment;        //!< How the Element is aligned around its Position
    7784};
    7885
  • 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
  • orxonox/trunk/src/lib/graphics/text_engine.h

    r4850 r4856  
    3636template<class T> class tList;
    3737
    38 //! An enumerator for the text alignment.
    39  enum TEXT_ALIGNMENT
    40 {
    41   TEXT_ALIGN_LEFT,
    42   TEXT_ALIGN_RIGHT,
    43   TEXT_ALIGN_CENTER,
    44   TEXT_ALIGN_SCREEN_CENTER
    45 };
     38#define  TEXT_ALIGN_LEFT             E2D_ALIGN_LEFT
     39#define  TEXT_ALIGN_RIGHT            E2D_ALIGN_RIGHT
     40#define  TEXT_ALIGN_CENTER           E2D_ALIGN_CENTER
     41#define  TEXT_ALIGN_SCREEN_CENTER    E2D_ALIGN_SCREEN_CENTER
    4642
    4743/* some default values */
     
    114110  void setType(int type);
    115111  void setText(const char* text);
    116   void setPosition(int x, int y);
    117   void setAlignment(TEXT_ALIGNMENT alignment);
    118112  /** @param blending the blending intensity to set (between 0.0 and 1.0) */
    119   inline void setBlending(float blending) {this->blending = blending;}
     113  inline void setBlending(float blending) { this->blending = blending; };
    120114
    121115  // Static Text
     
    140134  char*             text;           //!< The text to display
    141135  SDL_Color         color;          //!< The color of the font.
    142   TEXT_ALIGNMENT    alignment;      //!< The aignment of the text.
    143136  float             blending;       //!< The blending intensity.
    144137
     
    228221  void flush();
    229222
    230   void draw() const;
    231 
    232223  void debug() const;
    233224
     
    243234 private:
    244235  //  tList<Font>* fontList;
    245   tList<Text>*       textList;      //!< a list of all texts of the textEngine
     236  tList<Text>*       textList;      //!< a list of all texts registered to the textEngine @todo this is overhead, do we need this??
    246237
    247238};
Note: See TracChangeset for help on using the changeset viewer.