Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8571 in orxonox.OLD


Ignore:
Timestamp:
Jun 18, 2006, 9:52:32 PM (18 years ago)
Author:
bensch
Message:

Material should be fully loadable

Location:
branches/gui/src/lib/graphics
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/graphics/importer/material.cc

    r8376 r8571  
    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
     52void Material::loadParams(const TiXmlElement* root)
     53{
     54  LoadParam(root, "illum", this, Material, setIllum);
     55
     56  LoadParam(root, "diffuse-color", this, Material , setDiffuse);
     57  LoadParam(root, "ambient-color", this, Material , setAmbient);
     58  LoadParam(root, "specular-color", this, Material , setSpecular);
     59  LoadParam(root, "transparency", this, Material , setTransparency);
     60
     61  LoadParam(root, "tex", this, Material, setDiffuseMap);
     62  LoadParam(root, "blendfunc", this, Material, setBlendFuncS)
     63      .defaultValues("ZERO", "ZERO");
     64}
     65
     66
    4967/**
    5068 * @brief deletes a Material
     
    6583
    6684const 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 };
    7985
    8086
     
    104110 * @brief sets the material with which the following Faces will be painted
    105111 */
    106   bool Material::select() const
     112bool Material::select() const
    107113{
    108114  if (unlikely(this == Material::selectedMaterial))
    109       return true;
    110 
    111 /// !!  HACK !!! FIX THIS IN MODEL ///
     115    return true;
     116
     117  /// !!  HACK !!! FIX THIS IN MODEL ///
    112118  else if (likely(Material::selectedMaterial != NULL))
    113119  {
    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 //     }
     120    Material::unselect();
     121    //     for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
     122    //     {
     123    //         glActiveTexture(Material::glTextureArbs[i]);
     124    //         glBindTexture(GL_TEXTURE_2D, 0);
     125    //         glDisable(GL_TEXTURE_2D);
     126    //     }
    121127  }
    122128
     
    125131    for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i)
    126132    {
    127         glActiveTexture(Material::glTextureArbs[i]);
    128         //glBindTexture(GL_TEXTURE_2D, 0);
    129         glDisable(GL_TEXTURE_2D);
     133      glActiveTexture(Material::glTextureArbs[i]);
     134      //glBindTexture(GL_TEXTURE_2D, 0);
     135      glDisable(GL_TEXTURE_2D);
    130136    }
    131137  }
    132138
    133     // setting diffuse color
     139  // setting diffuse color
    134140  glColor4f (diffuse.r(), diffuse.g(), diffuse.b(), diffuse.a());
    135141  // setting ambient color
     
    161167  for(unsigned int i = 0; i < this->textures.size(); ++i)
    162168  {
    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());
     169    glActiveTexture(Material::glTextureArbs[i]);
     170    glEnable(GL_TEXTURE_2D);
     171    if(this->textures[i].hasAlpha())
     172    {
     173      glEnable(GL_BLEND);
     174    }
     175    glBindTexture(GL_TEXTURE_2D, this->textures[i].getTexture());
    170176  }
    171177  Material::selectedMaterial = this;
     
    179185{
    180186  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     }
     187  for(unsigned int i = 0; i < 8; ++i)
     188  {
     189    glActiveTexture(Material::glTextureArbs[i]);
     190    glBindTexture(GL_TEXTURE_2D, 0);
     191    glDisable(GL_TEXTURE_2D);
     192  }
    187193}
    188194
     
    252258  this->diffuse.a() = trans;
    253259}
     260
     261/**
     262 * @brief sets the Blend-Function Parameters
     263 * @param sFactor the Source Parameter.
     264 * @param tFactor the Desitnation Parameter.
     265 */
     266void Material::setBlendFuncS(const std::string& sFactor, const std::string& tFactor)
     267{
     268  this->setBlendFunc(Material::stringToBlendFunc(sFactor), Material::stringToBlendFunc(tFactor));
     269}
     270
     271
    254272
    255273/**
     
    354372  // HACK
    355373  glActiveTexture(textureNumber);
    356    glEnable(GL_TEXTURE_2D);
    357    glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture());
     374  glEnable(GL_TEXTURE_2D);
     375  glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture());
    358376  glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
    359377
     
    387405 */
    388406void Material::setBump(const std::string& bump)
    389 {
    390 }
     407{}
    391408
    392409
     
    400417  return maxTexUnits;
    401418}
     419
     420const GLenum Material::glTextureArbs[] =
     421{
     422  GL_TEXTURE0,
     423  GL_TEXTURE1,
     424  GL_TEXTURE2,
     425  GL_TEXTURE3,
     426  GL_TEXTURE4,
     427  GL_TEXTURE5,
     428  GL_TEXTURE6,
     429  GL_TEXTURE7
     430};
     431
     432
     433const std::string& Material::blendFuncToString(GLenum blendFunc)
     434{
     435  for (unsigned int i = 0; i < 9; ++i)
     436    if (blendFunc == glBlendFuncParams[i])
     437      return blendFuncNames[i];
     438  return blendFuncNames[0];
     439}
     440
     441GLenum Material::stringToBlendFunc(const std::string& blendFuncString)
     442{
     443  for (unsigned int i = 0; i < 9; ++i)
     444    if (blendFuncString == blendFuncNames[i])
     445      return glBlendFuncParams[i];
     446  return glBlendFuncParams[0];
     447}
     448
     449
     450
     451const GLenum Material::glBlendFuncParams[] =
     452  {
     453    GL_ZERO,
     454    GL_ONE,
     455    GL_DST_COLOR,
     456    GL_ONE_MINUS_DST_COLOR,
     457    GL_SRC_ALPHA,
     458    GL_ONE_MINUS_SRC_ALPHA,
     459    GL_DST_ALPHA,
     460    GL_ONE_MINUS_DST_ALPHA,
     461    GL_SRC_ALPHA_SATURATE
     462  };
     463
     464const std::string Material::blendFuncNames[] =
     465  {
     466    "ZERO",
     467    "ONE",
     468    "DST_COLOR",
     469    "ONE_MINUS_DST_COLOR",
     470    "SRC_ALPHA",
     471    "ONE_MINUS_SRC_ALPHA",
     472    "DST_ALPHA",
     473    "ONE_MINUS_DST_ALPHA",
     474    "SRC_ALPHA_SATURATE"
     475
     476  };
  • branches/gui/src/lib/graphics/importer/material.h

    r8448 r8571  
    2828    virtual ~Material ();
    2929
     30    void loadParams(const TiXmlElement* root);
     31
    3032    Material& operator=(const Material& material);
    3133
     
    4446    void setTransparency (float trans);
    4547    void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; };
     48    void setBlendFuncS(const std::string& sFactor, const std::string& tFactor);
    4649
    4750    const Color& getDiffuseColor() const { return diffuse; };
     
    6063    static void addTexturePath(const std::string& pathName);
    6164
     65    const std::string& blendFuncToString(GLenum blendFunc);
     66    GLenum stringToBlendFunc(const std::string& blendFuncString);
     67
     68
    6269  public:
    6370    static const GLenum glTextureArbs[];  //!< The Texture ARB's
     71
     72    static const GLenum glBlendFuncParams[];
     73    static const std::string blendFuncNames[];
    6474
    6575    static unsigned int getMaxTextureUnits();
  • branches/gui/src/lib/graphics/text_engine/text.cc

    r8539 r8571  
    2121#include "util/loading/resource_manager.h"
    2222#include "debug.h"
    23 
    24 using namespace std;
    2523
    2624/**
Note: See TracChangeset for help on using the changeset viewer.