Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 3, 2006, 2:37:13 PM (18 years ago)
Author:
bensch
Message:

orxonox/bsp_model: Material should support multiple Textures now

File:
1 edited

Legend:

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

    r7465 r7510  
    4545  this->setTransparency(1.0);
    4646
    47   this->diffuseTexture = NULL;
    4847  this->ambientTexture = NULL;
    4948  this->specularTexture = NULL;
     
    6160  PRINTF(5)("delete Material %s.\n", this->getName());
    6261
    63   if (this->diffuseTexture != NULL)
    64   {
    65     ResourceManager::getInstance()->unload(this->diffuseTexture);
    66   }
     62  while(!this->textures.empty())
     63  {
     64    if (this->textures.back() != NULL)
     65      ResourceManager::getInstance()->unload(this->textures.back());
     66    this->textures.pop_back();
     67  }
     68
    6769  if (this->ambientTexture != NULL)
    6870    ResourceManager::getInstance()->unload(this->ambientTexture);
     
    7173}
    7274
    73 Material& Material::operator=(const Material& m)
    74 {
    75   this->setIllum(m.illumModel);
    76   this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);
    77   this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);
    78   this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);
    79   this->setShininess(m.shininess);
    80   this->setTransparency(m.transparency);
    81 
    82   if (this->diffuseTexture != NULL)
    83     ResourceManager::getInstance()->unload(this->diffuseTexture);
    84   if (m.diffuseTexture != NULL)
    85     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);
    86   this->ambientTexture = NULL; /// FIXME
    87   this->specularTexture = NULL; /// FIXME
    88 
    89   this->setName(m.getName());
    90 }
    91  
    92 bool Material::select0() const
    93 {
    94   glActiveTextureARB(GL_TEXTURE0_ARB);
    95   glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
    96   glEnable(GL_TEXTURE_2D);
    97  
    98 }
     75
     76/// TODO FIX THIS
     77// Material& Material::operator=(const Material& m)
     78// {
     79//   this->setIllum(m.illumModel);
     80//   this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);
     81//   this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);
     82//   this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);
     83//   this->setShininess(m.shininess);
     84//   this->setTransparency(m.transparency);
     85//
     86//   if (this->diffuseTexture != NULL)
     87//     ResourceManager::getInstance()->unload(this->diffuseTexture);
     88//   if (m.diffuseTexture != NULL)
     89//     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);
     90//   this->ambientTexture = NULL; /// FIXME
     91//   this->specularTexture = NULL; /// FIXME
     92//
     93//   this->setName(m.getName());
     94// }
     95
     96const GLenum Material::glTextureArbs[] =
     97  {
     98    GL_TEXTURE0_ARB,
     99    GL_TEXTURE1_ARB,
     100    GL_TEXTURE2_ARB,
     101    GL_TEXTURE3_ARB,
     102    GL_TEXTURE4_ARB,
     103    GL_TEXTURE5_ARB,
     104    GL_TEXTURE6_ARB,
     105    GL_TEXTURE7_ARB
     106  };
     107
    99108
    100109/**
    101110 *  sets the material with which the following Faces will be painted
    102111 */
    103 bool Material::select () const
     112bool Material::select() const
    104113{
    105114  // setting diffuse color
    106115  glColor4f (diffuse[0], diffuse[1], diffuse[2], this->transparency);
    107 //  glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);
    108 
    109116  // setting ambient color
    110117  glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient);
    111 
    112118  // setting up Sprecular
    113119  glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular);
    114 
    115120  // setting up Shininess
    116121  glMaterialf(GL_FRONT, GL_SHININESS, this->shininess);
    117122
     123
    118124  // setting the transparency
    119125  if (this->transparency < 1.0 ||       /* This allows alpha blending of 2D textures with the scene */
    120       (this->diffuseTexture && this->diffuseTexture->hasAlpha()))
     126      (likely(!this->textures.empty() && this->textures[0] != NULL) && this->textures[0]->hasAlpha()))
    121127  {
    122128    glEnable(GL_BLEND);
     
    124130  }
    125131  else
    126     {
    127       glDisable(GL_BLEND);
    128       //glColor4f(*(this->diffuse), *(this->diffuse+1), *(this->diffuse+2), 1);
    129     }
     132  {
     133    glDisable(GL_BLEND);
     134  }
    130135
    131136
     
    136141    glShadeModel(GL_SMOOTH);
    137142
    138   if (this->diffuseTexture != NULL)
     143
     144  for(unsigned int i = 0; i < this->textures.size(); ++i)
     145  {
     146    if (likely(this->textures[i] != NULL))
    139147    {
     148      glActiveTexture(Material::glTextureArbs[i]);
    140149      glEnable(GL_TEXTURE_2D);
    141       glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
     150      glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture());
    142151    }
    143   else
    144     {
    145       glDisable(GL_TEXTURE_2D);
    146       glBindTexture(GL_TEXTURE_2D, 0);
    147     }
     152  }
     153
     154  /*  if (this->diffuseTexture != NULL)
     155      {
     156        glEnable(GL_TEXTURE_2D);
     157        glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture());
     158      }
     159    else
     160      {
     161        glDisable(GL_TEXTURE_2D);
     162        glBindTexture(GL_TEXTURE_2D, 0);
     163      }*/
    148164}
    149165
     
    233249  this->specular[2] = b;
    234250  this->specular[3] = 1.0;
    235  }
     251}
    236252
    237253/**
     
    296312 * @param dMap the Name of the Image to Use
    297313*/
    298 void Material::setDiffuseMap(const std::string& dMap, GLenum target)
    299 {
     314void Material::setDiffuseMap(const std::string& dMap, GLenum target, unsigned int textureNumber)
     315{
     316  assert(textureNumber < Material::getMaxTextureUnits());
     317
    300318  PRINTF(5)("setting Diffuse Map %s\n", dMap);
    301   if (this->diffuseTexture != NULL)
    302     ResourceManager::getInstance()->unload(this->diffuseTexture);
     319  if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
     320    ResourceManager::getInstance()->unload(this->textures[textureNumber]);
     321
     322  if (this->textures.size() <= textureNumber)
     323    this->textures.resize(textureNumber+1, NULL);
    303324
    304325  //! @todo check if RESOURCE MANAGER is availiable
    305   //! @todo Textures from .mtl-file need special care.
    306326  if (!dMap.empty())
    307     this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
     327  {
     328
     329    this->textures[textureNumber] = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
     330  }
    308331  else
    309     this->diffuseTexture = NULL;
     332  {
     333    this->textures[textureNumber] = NULL;
     334  }
    310335}
    311336
     
    339364void Material::setBump(const std::string& bump)
    340365{
    341 
    342 }
     366}
     367
     368
     369
     370int Material::getMaxTextureUnits()
     371{
     372  int maxTexUnits = 0;
     373  glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits);
     374  return maxTexUnits;
     375}
Note: See TracChangeset for help on using the changeset viewer.