Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Aug 25, 2005, 1:26:57 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: color is now a parameter of text not font

Location:
trunk/src/lib/graphics
Files:
3 edited

Legend:

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

    r5092 r5121  
    464464if (this->geTextCFPS == NULL)
    465465{
    466   this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0);
     466  this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC);
    467467  this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT);
    468468  this->geTextCFPS->setAbsCoor2D(5, 5);
     
    470470if (this->geTextMaxFPS == NULL)
    471471{
    472       this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0);
     472      this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC);
    473473      this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT);
    474474      this->geTextMaxFPS->setAbsCoor2D(5, 35);
     
    476476if (this->geTextMinFPS == NULL)
    477477{
    478       this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0);
     478      this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC);
    479479      this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT);
    480480      this->geTextMinFPS->setAbsCoor2D(5, 65);
  • trunk/src/lib/graphics/text_engine.cc

    r5115 r5121  
    6060  this->texture = 0;
    6161  this->blending = 1.0f;
     62  this->color = Vector(1.0, 1.0, 1.0);
    6263  this->setType(type);
    6364
     
    7576
    7677  if (this->text)
    77     delete []this->text;
     78    delete[] this->text;
    7879}
    7980
     
    130131
    131132/**
    132  *  sets a new color to the font
    133  * @param r Red
    134  * @param g Green
    135  * @param b Blue
    136 */
    137 void Text::setColor(Uint8 r, Uint8 g, Uint8 b)
    138 {
    139   this->color.r = r;
    140   this->color.g = g;
    141   this->color.b = b;
    142 }
    143 
    144 /**
    145133 *  creates a texture out of the given parameters
    146134
     
    154142    glDeleteTextures(1, &this->texture);
    155143  if (likely(this->font != NULL))
     144  {
     145    SDL_Color theColor = { (int)(this->color.x*255), (int)(this->color.y*255), (int)(this->color.z*255) };
    156146    tmpSurf = TTF_RenderText_Blended(this->font->font,
    157147                                     this->text,
    158                                      this->color);
     148                                     theColor);
     149  }
    159150  if (tmpSurf)
    160151    this->texture = loadTexture(tmpSurf, &this->texCoord);
     
    179170  // drawing this Text.
    180171  // setting the Blending effects
    181   glColor4f(1.0f,1.0f,1.0f, this->blending);
     172  glColor4f(this->color.x, this->color.y, this->color.z, this->blending);
    182173  glEnable(GL_BLEND);
    183174  glEnable(GL_TEXTURE_2D);
    184175  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
     176
     177  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    185178
    186179  if(type == TEXT_STATIC)
     
    234227    PRINT(0)("is bind to %s; ref=%p\n", this->getBindNode()->getName(), this->getBindNode());
    235228  PRINT(0)("Relative Position: (%d::%d)\n", this->posSize.x, this->posSize.y);
    236   PRINT(0)("Color: %d %d %d\n", this->color.r, this->color.g, this->color.b);
     229  PRINT(0)("Color: %0.2f %0.2f %0.2f\n", this->color.x, this->color.y, this->color.z);
    237230}
    238231
     
    349342 * @param b Blue value of the Font.
    350343*/
    351 Font::Font(const char* fontFile, unsigned int fontSize, Uint8 r, Uint8 g, Uint8 b)
     344Font::Font(const char* fontFile, unsigned int fontSize)
    352345{
    353346  this->setClassID(CL_FONT, "Font");
     
    364357  this->setStyle("c");//TTF_STYLE_NORMAL);
    365358
    366   this->setFastColor(r, g, b);
    367 
    368359  this->fastTextureID = this->createFastTexture();
    369360}
     
    381372      for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
    382373        delete this->glyphArray[i];
    383       delete []this->glyphArray;
     374      delete[] this->glyphArray;
    384375    }
    385376
     
    448439{
    449440  this->fontSize = fontSize;
    450 }
    451 
    452 /**
    453  *  sets a new color to the font
    454  * @param r Red
    455  * @param g Green
    456  * @param b Blue
    457 */
    458 void Font::setFastColor(Uint8 r, Uint8 g, Uint8 b)
    459 {
    460   this->fastColor.r = r;
    461   this->fastColor.g = g;
    462   this->fastColor.b = b;
    463441}
    464442
     
    538516
    539517  this->initGlyphs(32, numberOfGlyphs);
    540   this->glyphArray[32]->width = fontSize/3; //!< @todo find out the real size of a Space
     518  this->glyphArray[32]->width = fontSize/2; //!< @todo find out the real size of a Space
    541519
    542520  int rectSize = this->findOptimalFastTextureSize();
     
    589567          // reading in the new Glyph
    590568          if (likely(this->font != NULL))
    591             glyphSurf = TTF_RenderGlyph_Blended(this->font, i, this->fastColor);
     569          {
     570            SDL_Color white = {255, 255, 255};
     571            glyphSurf = TTF_RenderGlyph_Blended(this->font, i, white);
     572          }
    592573          if( glyphSurf != NULL )
    593574            {
     
    598579              tmpTexCoord.minU = (float)tmpRect.x/(float)tmpSurf->w;
    599580              tmpTexCoord.maxU = (float)(tmpRect.x +1 + tmpGlyph->width)/(float)tmpSurf->w;
    600               tmpTexCoord.minV = (float)tmpRect.y/(float)tmpSurf->w;
     581              tmpTexCoord.minV = (float)(tmpRect.y)/(float)tmpSurf->w;
    601582              tmpTexCoord.maxV = (float)(tmpRect.y+tmpGlyph->height)/(float)tmpSurf->w;
    602583              tmpGlyph->displayList = glGenLists(1);
     
    691672  int x,y; // the counters
    692673  int maxLineHeight;
    693   int size = 32;      // starting Value, we have to start somewhere 32 seems reasonable.
     674  unsigned int size = 32;  // starting Value, we have to start somewhere 32 seems reasonable. (take any small enough 2^i number)
    694675  bool sizeOK = false;
    695676  Glyph* tmpGlyph;
     
    815796   @see Text::Text
    816797*/
    817 Text* TextEngine::createText(const char* fontFile, unsigned int fontSize, int textType, Uint8 r, Uint8 g, Uint8 b)
     798Text* TextEngine::createText(const char* fontFile, unsigned int fontSize, int textType)
    818799{
    819800  Font* tmpFont;
     
    821802  Vector tmpVec;
    822803
    823   tmpVec = Vector(r, g, b);
    824   tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize, &tmpVec);
     804  tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, &fontSize);
    825805  if (!tmpFont)
    826806    {
  • trunk/src/lib/graphics/text_engine.h

    r5078 r5121  
    3434class PNode;
    3535class Font;
    36 template<class T> class tList;
    3736
    3837#define  TEXT_ALIGN_LEFT             E2D_ALIGN_LEFT
     
    113112  inline void setBlending(float blending) { this->blending = blending; };
    114113
    115   // Static Text
    116   void setColor(Uint8 r, Uint8 g, Uint8 b);
     114  /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */
     115  void setColor(float r, float g, float b) { this->color = Vector(r,g,b); };
    117116
    118117  void createTexture();
     
    133132  int               type;           //!< The type of this Font.
    134133  char*             text;           //!< The text to display
    135   SDL_Color         color;          //!< The color of the font.
     134  Vector            color;          //!< The color of the font.
    136135  float             blending;       //!< The blending intensity.
    137136
     
    152151 public:
    153152  Font(const char* fontFile,
    154        unsigned int fontSize = FONT_DEFAULT_SIZE,
    155        Uint8 r = FONT_DEFAULT_COLOR_R,
    156        Uint8 g = FONT_DEFAULT_COLOR_G,
    157        Uint8 b = FONT_DEFAULT_COLOR_B);
     153       unsigned int fontSize = FONT_DEFAULT_SIZE);
    158154
    159155  virtual ~Font();
     
    162158  bool setFont(const char* fontFile);
    163159  void setSize(unsigned int fontSize);
    164   void setFastColor(Uint8 r, Uint8 g, Uint8 b);
    165160  void setStyle(const char* renderStyle);
    166161
    167162  /** @returns a Pointer to the Array of Glyphs */
    168   inline Glyph** getGlyphArray() const {return glyphArray;}
     163  inline Glyph** getGlyphArray() const { return glyphArray; };
    169164  /** @returns the texture to the fast-texture */
    170165  inline GLuint getFastTextureID() const {return fastTextureID;}
     
    195190  Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
    196191  GLuint        fastTextureID;       //!< The fast textureID.
    197   SDL_Color     fastColor;           //!< A Color for the fast Texture.
    198192
    199193  tList<Text>*  textList;            //!< A list of texts this Font is mapped to.
     
    213207  Text* createText(const char* fontFile,
    214208                   unsigned int fontSize = FONT_DEFAULT_SIZE,
    215                    int textType = TEXT_DYNAMIC,
    216                    Uint8 r = FONT_DEFAULT_COLOR_R,
    217                    Uint8 g = FONT_DEFAULT_COLOR_G,
    218                    Uint8 b = FONT_DEFAULT_COLOR_B);
     209                   int textType = TEXT_DYNAMIC);
    219210
    220211  void debug() const;
     
    228219  static void disableFonts();
    229220  static bool checkVersion();
    230 
    231  private:
    232   //  tList<Font>* fontList;
    233 
    234221};
    235222
Note: See TracChangeset for help on using the changeset viewer.