Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 20, 2006, 1:24:11 PM (19 years ago)
Author:
bensch
Message:

trunk: merged the gui-branche back.
merged with command:
svn merge -r8520:HEAD https://svn.orxonox.net/orxonox/branches/gui
no conflicts

Location:
trunk/src/lib/graphics
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/Makefile.am

    r8293 r8619  
    44noinst_LIBRARIES = libORXgraphics.a
    55
    6 libORXgraphics_a_SOURCES = graphics_engine.cc \
    7                            light.cc \
    8                            shader.cc \
    9                            \
    10                            render2D/render_2d.cc \
    11                            render2D/element_2d.cc \
    12                            render2D/image_plane.cc \
    13                            \
    14                            text_engine/text_engine.cc \
    15                            text_engine/text.cc \
    16                            text_engine/multi_line_text.cc \
    17                            text_engine/font.cc \
    18                            \
    19                            effects/graphics_effect.cc \
    20                            effects/atmospheric_engine.cc \
    21                            effects/weather_effect.cc \
    22                            effects/sun_effect.cc \
    23                            effects/fog_effect.cc \
    24                            effects/volfog_effect.cc \
    25                            effects/rain_effect.cc \
    26                            effects/snow_effect.cc \
    27                            effects/cloud_effect.cc \
    28                            effects/lightening_effect.cc \
    29                            effects/lense_flare.cc
     6libORXgraphics_a_SOURCES = \
     7                graphics_engine.cc \
     8                light.cc \
     9                shader.cc \
     10                \
     11                render2D/render_2d.cc \
     12                render2D/element_2d.cc \
     13                render2D/image_plane.cc \
     14                \
     15                text_engine/text_engine.cc \
     16                text_engine/text.cc \
     17                text_engine/multi_line_text.cc \
     18                text_engine/limited_width_text.cc \
     19                text_engine/font.cc \
     20                \
     21                effects/graphics_effect.cc \
     22                effects/atmospheric_engine.cc \
     23                effects/weather_effect.cc \
     24                effects/sun_effect.cc \
     25                effects/fog_effect.cc \
     26                effects/volfog_effect.cc \
     27                effects/rain_effect.cc \
     28                effects/snow_effect.cc \
     29                effects/cloud_effect.cc \
     30                effects/lightening_effect.cc \
     31                effects/lense_flare.cc
    3032
    3133noinst_HEADERS = graphics_engine.h \
     
    4042                 text_engine/text.h \
    4143                 text_engine/multi_line_text.h \
     44                 text_engine/limited_width_text.h \
    4245                 text_engine/font.h \
    4346                 text_engine/default_font.xpm \
  • trunk/src/lib/graphics/effects/lense_flare.cc

    r8495 r8619  
    4747    this->setClassID(CL_LENSE_FLARE, "LenseFlare");
    4848
    49     this->flareMatrix = new float[14];
    5049    /*          length                      image scale */
    5150    this->flareMatrix[0] = 1.0f;
  • trunk/src/lib/graphics/effects/lense_flare.h

    r8495 r8619  
    5151    bool                     bVisible;          //!< Checks visibility
    5252    Light*                   lightSource;        //!< reference to the sun (or primary light source)
    53     std::vector<ImagePlane*>  flares;             //!< the flares array
     53    std::vector<ImagePlane*> flares;             //!< the flares array
    5454
    5555    Vector2D                 flareVector;        //!< the axis to draw the flares on
     
    5757    Vector2D                 screenCenter;       //!< the vector marking the center of the screen
    5858
    59     float*                   flareMatrix;
     59    float                    flareMatrix[14];
    6060    Plane                    frustumPlane;       //!< plane that marks the view frustum
    6161};
  • trunk/src/lib/graphics/importer/material.cc

    r8376 r8619  
    2222#include "debug.h"
    2323#include "compiler.h"
     24
     25#include "loading/load_param.h"
     26
    2427#include "util/loading/resource_manager.h"
    2528
     
    4750}
    4851
     52Material& Material::operator=(const Material& material)
     53{
     54  this->illumModel = material.illumModel;
     55  this->diffuse = material.diffuse;
     56  this->specular = material.specular;
     57  this->ambient = material.ambient;
     58  this->shininess = material.shininess;
     59
     60  this->textures = material.textures;
     61  this->sFactor = material.sFactor;
     62  this->tFactor = material.tFactor;
     63  this->setName(material.getName());
     64
     65  return *this;
     66}
     67
     68
     69
     70void Material::loadParams(const TiXmlElement* root)
     71{
     72  LoadParam(root, "illum", this, Material, setIllum);
     73
     74  LoadParam(root, "diffuse-color", this, Material , setDiffuse);
     75  LoadParam(root, "ambient-color", this, Material , setAmbient);
     76  LoadParam(root, "specular-color", this, Material , setSpecular);
     77  LoadParam(root, "transparency", this, Material , setTransparency);
     78
     79  LoadParam(root, "tex", this, Material, setDiffuseMap);
     80  LoadParam(root, "blendfunc", this, Material, setBlendFuncS)
     81      .defaultValues("ZERO", "ZERO");
     82}
     83
     84
    4985/**
    5086 * @brief deletes a Material
     
    65101
    66102const Material* Material::selectedMaterial = NULL;
    67 
    68 const GLenum Material::glTextureArbs[] =
    69 {
    70   GL_TEXTURE0,
    71   GL_TEXTURE1,
    72   GL_TEXTURE2,
    73   GL_TEXTURE3,
    74   GL_TEXTURE4,
    75   GL_TEXTURE5,
    76   GL_TEXTURE6,
    77   GL_TEXTURE7
    78 };
    79103
    80104
     
    104128 * @brief sets the material with which the following Faces will be painted
    105129 */
    106   bool Material::select() const
     130bool Material::select() const
    107131{
    108132  if (unlikely(this == Material::selectedMaterial))
    109       return true;
    110 
    111 /// !!  HACK !!! FIX THIS IN MODEL ///
     133    return true;
     134
     135  /// !!  HACK !!! FIX THIS IN MODEL ///
    112136  else if (likely(Material::selectedMaterial != NULL))
    113137  {
    114   Material::unselect();
    115 //     for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
    116 //     {
    117 //         glActiveTexture(Material::glTextureArbs[i]);
    118 //         glBindTexture(GL_TEXTURE_2D, 0);
    119 //         glDisable(GL_TEXTURE_2D);
    120 //     }
     138    Material::unselect();
     139    //     for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
     140    //     {
     141    //         glActiveTexture(Material::glTextureArbs[i]);
     142    //         glBindTexture(GL_TEXTURE_2D, 0);
     143    //         glDisable(GL_TEXTURE_2D);
     144    //     }
    121145  }
    122146
     
    125149    for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
    126150    {
    127         glActiveTexture(Material::glTextureArbs[i]);
    128         //glBindTexture(GL_TEXTURE_2D, 0);
    129         glDisable(GL_TEXTURE_2D);
     151      glActiveTexture(Material::glTextureArbs[i]);
     152      //glBindTexture(GL_TEXTURE_2D, 0);
     153      glDisable(GL_TEXTURE_2D);
    130154    }
    131155  }
    132156
    133     // setting diffuse color
     157  // setting diffuse color
    134158  glColor4f (diffuse.r(), diffuse.g(), diffuse.b(), diffuse.a());
    135159  // setting ambient color
     
    161185  for(unsigned int i = 0; i < this->textures.size(); ++i)
    162186  {
    163       glActiveTexture(Material::glTextureArbs[i]);
    164       glEnable(GL_TEXTURE_2D);
    165       if(this->textures[i].hasAlpha())
    166       {
    167         glEnable(GL_BLEND);
    168       }
    169       glBindTexture(GL_TEXTURE_2D, this->textures[i].getTexture());
     187    glActiveTexture(Material::glTextureArbs[i]);
     188    glEnable(GL_TEXTURE_2D);
     189    if(this->textures[i].hasAlpha())
     190    {
     191      glEnable(GL_BLEND);
     192    }
     193    glBindTexture(GL_TEXTURE_2D, this->textures[i].getTexture());
    170194  }
    171195  Material::selectedMaterial = this;
     
    179203{
    180204  Material::selectedMaterial = NULL;
    181     for(unsigned int i = 0; i < 8; ++i)
    182     {
    183         glActiveTexture(Material::glTextureArbs[i]);
    184         glBindTexture(GL_TEXTURE_2D, 0);
    185         glDisable(GL_TEXTURE_2D);
    186     }
     205  for(unsigned int i = 0; i < 8; ++i)
     206  {
     207    glActiveTexture(Material::glTextureArbs[i]);
     208    glBindTexture(GL_TEXTURE_2D, 0);
     209    glDisable(GL_TEXTURE_2D);
     210  }
    187211}
    188212
     
    252276  this->diffuse.a() = trans;
    253277}
     278
     279/**
     280 * @brief sets the Blend-Function Parameters
     281 * @param sFactor the Source Parameter.
     282 * @param tFactor the Desitnation Parameter.
     283 */
     284void Material::setBlendFuncS(const std::string& sFactor, const std::string& tFactor)
     285{
     286  this->setBlendFunc(Material::stringToBlendFunc(sFactor), Material::stringToBlendFunc(tFactor));
     287}
     288
     289
    254290
    255291/**
     
    354390  // HACK
    355391  glActiveTexture(textureNumber);
    356    glEnable(GL_TEXTURE_2D);
    357    glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture());
     392  glEnable(GL_TEXTURE_2D);
     393  glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture());
    358394  glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
    359395
     
    387423 */
    388424void Material::setBump(const std::string& bump)
    389 {
    390 }
     425{}
    391426
    392427
     
    400435  return maxTexUnits;
    401436}
     437
     438const GLenum Material::glTextureArbs[] =
     439{
     440  GL_TEXTURE0,
     441  GL_TEXTURE1,
     442  GL_TEXTURE2,
     443  GL_TEXTURE3,
     444  GL_TEXTURE4,
     445  GL_TEXTURE5,
     446  GL_TEXTURE6,
     447  GL_TEXTURE7
     448};
     449
     450
     451/**
     452 * @param blendFunc the Enumerator to convert to a String.
     453 * @returns the matching String if found
     454 */
     455const std::string& Material::blendFuncToString(GLenum blendFunc)
     456{
     457  for (unsigned int i = 0; i < 9; ++i)
     458    if (blendFunc == Material::glBlendFuncParams[i])
     459      return Material::blendFuncNames[i];
     460  PRINTF(2)("Supplied an Invalid Enumerator to blendfunc %d\n", blendFunc);
     461  return Material::blendFuncNames[0];
     462}
     463
     464/**
     465 * @param blendFuncString the String to convert into a gl-enumeration
     466 * @returns the matching GL-enumeration if found.
     467 */
     468GLenum Material::stringToBlendFunc(const std::string& blendFuncString)
     469{
     470  for (unsigned int i = 0; i < 9; ++i)
     471    if (blendFuncString == Material::blendFuncNames[i])
     472      return Material::glBlendFuncParams[i];
     473  PRINTF(2)("BlendFunction %s not recognized using %s\n", blendFuncString.c_str(), Material::blendFuncNames[0].c_str());
     474  return Material::glBlendFuncParams[0];
     475}
     476
     477
     478const GLenum Material::glBlendFuncParams[] =
     479  {
     480    GL_ZERO,
     481    GL_ONE,
     482    GL_DST_COLOR,
     483    GL_ONE_MINUS_DST_COLOR,
     484    GL_SRC_ALPHA,
     485    GL_ONE_MINUS_SRC_ALPHA,
     486    GL_DST_ALPHA,
     487    GL_ONE_MINUS_DST_ALPHA,
     488    GL_SRC_ALPHA_SATURATE
     489  };
     490
     491const std::string Material::blendFuncNames[] =
     492  {
     493    "ZERO",
     494    "ONE",
     495    "DST_COLOR",
     496    "ONE_MINUS_DST_COLOR",
     497    "SRC_ALPHA",
     498    "ONE_MINUS_SRC_ALPHA",
     499    "DST_ALPHA",
     500    "ONE_MINUS_DST_ALPHA",
     501    "SRC_ALPHA_SATURATE"
     502
     503  };
  • trunk/src/lib/graphics/importer/material.h

    r8448 r8619  
    2424class Material : public BaseObject
    2525{
    26   public:
    27     Material (const std::string& mtlName = "");
    28     virtual ~Material ();
     26public:
     27  Material (const std::string& mtlName = "");
     28  virtual ~Material ();
    2929
    30     Material& operator=(const Material& material);
     30  void loadParams(const TiXmlElement* root);
    3131
    32     bool select () const;
    33     bool activateTextureUnit(unsigned int textureNumber);
    34     static void unselect();
     32  Material& operator=(const Material& material);
    3533
    36     void setIllum (int illum);
    37     int getIllumModel() const { return this->illumModel; };
     34  bool select () const;
     35  bool activateTextureUnit(unsigned int textureNumber);
     36  static void unselect();
    3837
    39     void setDiffuse (float r, float g, float b);
    40     void setDiffuseColor(const Color& diffuseColor) { this->diffuse = diffuseColor; };
    41     void setAmbient (float r, float g, float b);
    42     void setSpecular (float r, float g, float b);
    43     void setShininess (float shini);
    44     void setTransparency (float trans);
    45     void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; };
     38  void setIllum (int illum);
     39  int getIllumModel() const { return this->illumModel; };
    4640
    47     const Color& getDiffuseColor() const { return diffuse; };
     41  void setDiffuse (float r, float g, float b);
     42  void setDiffuseColor(const Color& diffuseColor) { this->diffuse = diffuseColor; };
     43  void setAmbient (float r, float g, float b);
     44  void setSpecular (float r, float g, float b);
     45  void setShininess (float shini);
     46  void setTransparency (float trans);
     47  void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; };
     48  void setBlendFuncS(const std::string& sFactor, const std::string& tFactor);
    4849
    49     // MAPPING //
    50     void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0);
    51     void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
    52     void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
    53     void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
     50  Color& diffuseColor() { return diffuse; };
     51  const Color& diffuseColor() const { return diffuse; };
    5452
    55     void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);
    56     void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D);
    57     void setBump(const std::string& bump);
    58     GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; };
     53  // MAPPING //
     54  void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0);
     55  void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
     56  void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
     57  void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
    5958
    60     static void addTexturePath(const std::string& pathName);
     59  void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);
     60  void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D);
     61  void setBump(const std::string& bump);
    6162
    62   public:
    63     static const GLenum glTextureArbs[];  //!< The Texture ARB's
     63  GLuint diffuseTextureID(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; };
    6464
    65     static unsigned int getMaxTextureUnits();
     65  const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; };
    6666
    67   private:
    68     static const Material* selectedMaterial; //!< The currently selected material.
     67  static void addTexturePath(const std::string& pathName);
    6968
    70     int              illumModel;       //!< The IlluminationModel is either flat or smooth.
    71     Color            diffuse;          //!< The diffuse color of the Material. (also transparency.)
    72     Color            ambient;          //!< The ambient color of the Material.
    73     Color            specular;         //!< The specular color of the Material.
    74     float            shininess;        //!< The shininess of the Material.
    75     GLenum           sFactor;          //!< The Blending Factor for the Source.
    76     GLenum           tFactor;          //!< The Blending Factor for the Destination.
     69  const std::string& blendFuncToString(GLenum blendFunc);
     70  GLenum stringToBlendFunc(const std::string& blendFuncString);
    7771
    78     std::vector<Texture> textures;     //!< An Array of Textures.
    7972
    80     Texture*         ambientTexture;   //!< The ambient texture of the Material.
    81     Texture*         specularTexture;  //!< The specular texture of the Material.
     73public:
     74  static const GLenum glTextureArbs[];  //!< The Texture ARB's
     75
     76  static const GLenum glBlendFuncParams[];
     77  static const std::string blendFuncNames[];
     78
     79  static unsigned int getMaxTextureUnits();
     80
     81private:
     82  static const Material* selectedMaterial; //!< The currently selected material.
     83
     84  int              illumModel;       //!< The IlluminationModel is either flat or smooth.
     85  Color            diffuse;          //!< The diffuse color of the Material. (also transparency.)
     86  Color            ambient;          //!< The ambient color of the Material.
     87  Color            specular;         //!< The specular color of the Material.
     88  float            shininess;        //!< The shininess of the Material.
     89  GLenum           sFactor;          //!< The Blending Factor for the Source.
     90  GLenum           tFactor;          //!< The Blending Factor for the Destination.
     91
     92  std::vector<Texture> textures;     //!< An Array of Textures.
     93
     94  Texture*         ambientTexture;   //!< The ambient texture of the Material.
     95  Texture*         specularTexture;  //!< The specular texture of the Material.
    8296};
    8397
  • trunk/src/lib/graphics/importer/texture_sequence.cc

    r8324 r8619  
    180180  }
    181181  bool success = this->addFrame(addSurface);
    182   delete addSurface;
     182  SDL_FreeSurface(addSurface);
    183183
    184184  return success;
  • trunk/src/lib/graphics/text_engine/multi_line_text.cc

    r8448 r8619  
    6161void MultiLineText::draw() const
    6262{
    63   if (unlikely(this->getText().empty()))
     63  if (unlikely(this->text().empty()))
    6464    return;
    6565  glPushMatrix();
     
    7676  glActiveTexture(GL_TEXTURE0);
    7777
    78   glColor4fv(&this->getColor()[0]);
     78  glColor4fv(&this->color()[0]);
    7979  glEnable(GL_BLEND);
    8080  glEnable(GL_TEXTURE_2D);
     
    8282  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    8383
    84   glBindTexture(GL_TEXTURE_2D, this->getFont()->getTexture());
     84  glBindTexture(GL_TEXTURE_2D, this->font()->getTexture());
    8585  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
    8686  glRotatef(this->getAbsDir2D(), 0, 0, 1);
     
    9292
    9393  glBegin(GL_QUADS);
    94   for (unsigned int i = 0; i < this->getText().size(); ++i)
     94  for (unsigned int i = 0; i < this->text().size(); ++i)
    9595  {
    9696    if (unlikely(this->lineEnds.size() > lineNumber && i == this->lineEnds[lineNumber]))
     
    9999      ++lineNumber;
    100100      posX = 0.0f;
    101       posY += this->lineSpacing + this->getSize(); //this->getFont()->getMaxHeight();
     101      posY += this->lineSpacing + this->size(); //this->font()->getMaxHeight();
    102102    }
    103103
    104     if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->getText()[i]]) != NULL))
     104    if(likely((tmpGlyph = this->font()->getGlyphArray()[this->text()[i]]) != NULL))
    105105    {
    106106      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    107       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY);
     107      glVertex2d(posX+tmpGlyph->maxX*this->size(), posY);
    108108
    109109      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    110       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY + this->getSize());
     110      glVertex2d(posX+tmpGlyph->maxX*this->size(), posY + this->size());
    111111
    112112      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    113       glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY+ this->getSize());
     113      glVertex2d(posX+tmpGlyph->minX*this->size(), posY+ this->size());
    114114
    115115      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    116       glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY);
     116      glVertex2d(posX+tmpGlyph->minX*this->size(), posY);
    117117
    118       posX += tmpGlyph->advance * this->getSize();
     118      posX += tmpGlyph->advance * this->size();
    119119    }
    120120  }
     
    132132  this->lineEnds.clear();
    133133  float width = 0.0f;
    134   float maxWidth = this->lineWidth / this->getSize();
     134  float maxWidth = this->lineWidth / this->size();
    135135
    136   for (unsigned int i = 0; i < this->getText().size(); i++)
     136  for (unsigned int i = 0; i < this->text().size(); i++)
    137137  {
    138     if (width > maxWidth || this->getText()[i] == '\n')
     138    if (width > maxWidth || this->text()[i] == '\n')
    139139    {
    140140      if (likely(i > 0))
    141141      {
    142142        this->lineEnds.push_back( i -1 );
    143         width = this->getFont()->getGlyphArray()[this->getText()[i-1]]->advance;
     143        width = this->font()->getGlyphArray()[this->text()[i-1]]->advance;
    144144      }
    145145      else
     
    148148
    149149    // Advance the Text.
    150     if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
    151       width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
     150    if(this->font()->getGlyphArray()[this->text()[i]] != NULL)
     151      width += this->font()->getGlyphArray()[this->text()[i]]->advance;
    152152  }
    153153  this->lineCount = lineEnds.size() + 1;
    154   this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->getFont()->getMaxHeight()));
     154  this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->font()->getMaxHeight()));
    155155}
    156156
     
    162162 printf("Debug %s::%s: %d lines\n", this->getClassName(), this->getName(), this->getLineCount());
    163163
    164  std::string tmpText = this->getText();
     164 std::string tmpText = this->text();
    165165 std::vector<unsigned int> ends = this->lineEnds;
    166166 ends.push_back(tmpText.size());
  • trunk/src/lib/graphics/text_engine/text.cc

    r8518 r8619  
    2222#include "debug.h"
    2323
    24 using namespace std;
    25 
    2624/**
    2725 * @brief creates a new Text Element
     
    3432
    3533  // initialize this Text
    36   this->font = NULL;
    37   this->size = textSize;
    38   this->setSizeY2D(size);
    39   this->color = TEXT_DEFAULT_COLOR;
     34  this->_font = NULL;
     35  this->_size = textSize;
     36  this->setSizeY2D(textSize);
     37  this->_color = TEXT_DEFAULT_COLOR;
    4038
    4139  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
     
    4745{
    4846  this->setClassID(CL_TEXT, "Text");
    49   this->font = NULL;
     47  this->_font = NULL;
    5048
    5149  *this = text;
     
    5856Text::~Text()
    5957{
    60   if (this->font != NULL && this->font != Font::getDefaultFont())
    61     ResourceManager::getInstance()->unload(this->font);
     58  if (this->_font != NULL && this->_font != Font::getDefaultFont())
     59    ResourceManager::getInstance()->unload(this->_font);
    6260}
    6361
     
    6967bool Text::operator==(const Text& text) const
    7068{
    71   return (this->text == text.text &&
    72           this->size == text.size &&
    73           this->font == text.font &&
    74           this->color == text.color);
     69  return (this->_text == text._text &&
     70          this->_size == text._size &&
     71          this->_font == text._font &&
     72          this->_color == text._color);
    7573}
    7674
     
    8280bool Text::operator==(const std::string& text) const
    8381{
    84   return (this->text == text);
     82  return (this->_text == text);
    8583}
    8684
     
    9290Text& Text::operator=(const Text& text)
    9391{
    94   this->size = text.size;
    95   this->color = text.color;
     92  this->_size = text._size;
     93  this->_color = text._color;
    9694  this->setAlignment(text.getAlignment());
    97   if (this->font != NULL)
    98     ResourceManager::getInstance()->unload(this->font);
    99 
    100   this->font = (Font*)ResourceManager::getInstance()->copy( text.font ); //!< HACK
    101 
    102   this->text = text.text;
     95  if (this->_font != NULL)
     96    ResourceManager::getInstance()->unload(this->_font);
     97
     98  this->_font = (Font*)ResourceManager::getInstance()->copy( text._font ); //!< HACK
     99
     100  this->_text = text._text;
    103101  return *this;
    104102}
     
    110108void Text::setText(const std::string& text)
    111109{
    112   this->text = text;
     110  this->_text = text;
    113111  this->setupTextWidth();
    114112}
     
    120118void Text::append(const std::string& appendText)
    121119{
    122   this->text += appendText;
     120  this->_text += appendText;
    123121  this->setupTextWidth();
    124122}
     
    129127void Text::appendCharacter(char character)
    130128{
    131   this->text += character;
     129  this->_text += character;
    132130  this->setupTextWidth();
    133131}
     
    141139{
    142140  this->append(appendText);
    143   return this->text;
     141  return this->_text;
    144142}
    145143
     
    152150void Text::removeCharacters(unsigned int chars)
    153151{
    154   if (text.size() > chars)
    155     this->text.resize(this->text.size()-chars);
    156   else if (!text.empty())
    157     text.clear();
     152  if (this->_text.size() > chars)
     153    this->_text.resize(this->_text.size()-chars);
     154  else if (!this->_text.empty())
     155    this->_text.clear();
    158156  this->setupTextWidth();
    159157}
     
    165163void Text::clear()
    166164{
    167   text.clear();
     165  this->_text.clear();
    168166  this->setupTextWidth();
    169167}
     
    177175{
    178176  Font* newFont = NULL;
    179   Font* oldFont = this->font;
     177  Font* oldFont = this->_font;
    180178
    181179  // load a new Font
     
    194192
    195193  // unloading the Font if we alrady have one loaded.
    196   this->font = newFont;
     194  this->_font = newFont;
    197195  if (oldFont != NULL && oldFont != Font::getDefaultFont())
    198196    ResourceManager::getInstance()->unload(oldFont);
     
    207205void Text::setSize(float size)
    208206{
    209   this->size = size;
     207  this->_size = size;
    210208  this->setSizeY2D(size);
    211209  this->setupTextWidth();
     
    218216void Text::draw() const
    219217{
    220   if (unlikely(this->text.empty()))
     218  if (unlikely(this->_text.empty()))
    221219    return;
    222220  glPushMatrix();
     
    230228  // drawing this Text.
    231229  // setting the Blending effects
    232   glColor4fv(&this->color[0]);
     230  glColor4fv(&this->_color[0]);
    233231
    234232
     
    240238  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
    241239
    242   glBindTexture(GL_TEXTURE_2D, font->getTexture());
     240  glBindTexture(GL_TEXTURE_2D, this->_font->getTexture());
    243241  glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
    244242  glRotatef(this->getAbsDir2D(), 0, 0, 1);
     
    247245  float posX = 0.0f;
    248246  glBegin(GL_QUADS);
    249   for (unsigned int i = 0; i < this->text.size(); i++)
     247  for (unsigned int i = 0; i < this->_text.size(); i++)
    250248  {
    251     if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->text[i]]) != NULL))
     249    if(likely((tmpGlyph = this->font()->getGlyphArray()[this->_text[i]]) != NULL))
    252250    {
    253251      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    254       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), 0);
     252      glVertex2d(posX+tmpGlyph->maxX*this->size(), 0);
    255253
    256254      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    257       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), this->getSize());
     255      glVertex2d(posX+tmpGlyph->maxX*this->size(), this->size());
    258256
    259257      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    260       glVertex2d(posX+tmpGlyph->minX*this->getSize(), this->getSize());
     258      glVertex2d(posX+tmpGlyph->minX*this->size(), this->size());
    261259
    262260      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    263       glVertex2d(posX+tmpGlyph->minX*this->getSize(), 0);
    264 
    265       posX += tmpGlyph->advance * this->getSize();
     261      glVertex2d(posX+tmpGlyph->minX*this->size(), 0);
     262
     263      posX += tmpGlyph->advance * this->size();
    266264    }
    267265  }
     
    278276{
    279277  float width = 0;
    280   for (unsigned int i = 0; i < this->text.size(); i++)
    281     if(this->font->getGlyphArray()[this->text[i]] != NULL)
    282       width += this->font->getGlyphArray()[this->text[i]]->advance;
    283   this->setSizeX2D(width * this->getSize());
     278  for (unsigned int i = 0; i < this->_text.size(); i++)
     279    if(this->_font->getGlyphArray()[this->_text[i]] != NULL)
     280      width += this->_font->getGlyphArray()[this->_text[i]]->advance;
     281  this->setSizeX2D(width * this->size());
    284282}
    285283
     
    290288void Text::debug() const
    291289{
    292   PRINT(0)("=== TEXT: %s (with Font:'%s')  displaying %s ===\n", this->getName(), this->font->getName(), this->text.c_str());
    293   PRINT(0)("Color: r=%0.2f g=%0.2f b=%0.2f a=%0.2f\n", this->color.r(), this->color.g(), this->color.b(), this->color.a());
    294 }
    295 
     290  PRINT(0)("=== TEXT: %s (with Font:'%s')  displaying %s ===\n", this->getName(), this->_font->getName(), this->_text.c_str());
     291  PRINT(0)("Color: r=%0.2f g=%0.2f b=%0.2f a=%0.2f\n", this->_color.r(), this->_color.g(), this->_color.b(), this->_color.a());
     292}
     293
  • trunk/src/lib/graphics/text_engine/text.h

    r8518 r8619  
    4545    void setFont(const std::string& fontFile, unsigned int renderSize);
    4646    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
    47     inline void setBlending(float blending) { this->color.a() = blending; };
     47    inline void setBlending(float blending) { this->_color.a() = blending; };
    4848    /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */
    49     void setColor(float r, float g, float b) { this->color = Color(r, g, b, this->color.a()); };
    50     void setColor(float r, float g, float b, float a) { this->color = Color(r, g, b, a); };
    51     void setColor(const Color& color) { this->color = color; };
     49    void setColor(float r, float g, float b) { this->_color = Color(r, g, b, this->_color.a()); };
     50    void setColor(float r, float g, float b, float a) { this->_color = Color(r, g, b, a); };
     51    void setColor(const Color& color) { this->_color = color; };
    5252    void setSize(float size);
    5353
     
    5555    /// RETRIEVE
    5656    /** @returns the String this Text displays */
    57     inline const std::string& getText() const { return this->text; };
     57    inline const std::string& text() const { return this->_text; };
    5858
    5959    /** @returns the pointer to the stored Font (not changeable) */
    60     inline const Font* const getFont() const { return this->font; };
     60    inline const Font* const font() const { return this->_font; };
    6161    /** @returns the Blending Value [0 invisible 1.0 full visible */
    62     inline float getBlending() const { return this->color.a(); };
     62    inline float blending() const { return this->_color.a(); };
    6363    /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */
    64     inline const Color& getColor() const { return this->color; };
     64    inline const Color& color() const { return this->_color; };
    6565    /** @returns the Size of the Text */
    66     inline float getSize() const { return this->size; };
     66    inline float size() const { return this->_size; };
    6767
    6868    virtual void draw() const;
     
    7676
    7777  private:
    78     Font*             font;           //!< Font of this text
     78    Font*             _font;           //!< Font of this text
    7979
    80     std::string       text;           //!< The text to display
    81     Color             color;          //!< The color of the font.
    82     float             size;           //!< The size of the Text.
     80    std::string       _text;           //!< The text to display
     81    Color             _color;          //!< The color of the font.
     82    float             _size;           //!< The size of the Text.
    8383};
    8484
Note: See TracChangeset for help on using the changeset viewer.