Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 20, 2006, 1:24:11 PM (18 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  };
Note: See TracChangeset for help on using the changeset viewer.