Changeset 7510 in orxonox.OLD for branches/bsp_model/src/lib/graphics/importer/material.cc
- Timestamp:
- May 3, 2006, 2:37:13 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/material.cc
r7465 r7510 45 45 this->setTransparency(1.0); 46 46 47 this->diffuseTexture = NULL;48 47 this->ambientTexture = NULL; 49 48 this->specularTexture = NULL; … … 61 60 PRINTF(5)("delete Material %s.\n", this->getName()); 62 61 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 67 69 if (this->ambientTexture != NULL) 68 70 ResourceManager::getInstance()->unload(this->ambientTexture); … … 71 73 } 72 74 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 96 const 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 99 108 100 109 /** 101 110 * sets the material with which the following Faces will be painted 102 111 */ 103 bool Material::select 112 bool Material::select() const 104 113 { 105 114 // setting diffuse color 106 115 glColor4f (diffuse[0], diffuse[1], diffuse[2], this->transparency); 107 // glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);108 109 116 // setting ambient color 110 117 glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient); 111 112 118 // setting up Sprecular 113 119 glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular); 114 115 120 // setting up Shininess 116 121 glMaterialf(GL_FRONT, GL_SHININESS, this->shininess); 117 122 123 118 124 // setting the transparency 119 125 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())) 121 127 { 122 128 glEnable(GL_BLEND); … … 124 130 } 125 131 else 126 { 127 glDisable(GL_BLEND); 128 //glColor4f(*(this->diffuse), *(this->diffuse+1), *(this->diffuse+2), 1); 129 } 132 { 133 glDisable(GL_BLEND); 134 } 130 135 131 136 … … 136 141 glShadeModel(GL_SMOOTH); 137 142 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)) 139 147 { 148 glActiveTexture(Material::glTextureArbs[i]); 140 149 glEnable(GL_TEXTURE_2D); 141 glBindTexture(GL_TEXTURE_2D, this-> diffuseTexture->getTexture());150 glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture()); 142 151 } 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 }*/ 148 164 } 149 165 … … 233 249 this->specular[2] = b; 234 250 this->specular[3] = 1.0; 235 251 } 236 252 237 253 /** … … 296 312 * @param dMap the Name of the Image to Use 297 313 */ 298 void Material::setDiffuseMap(const std::string& dMap, GLenum target) 299 { 314 void Material::setDiffuseMap(const std::string& dMap, GLenum target, unsigned int textureNumber) 315 { 316 assert(textureNumber < Material::getMaxTextureUnits()); 317 300 318 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); 303 324 304 325 //! @todo check if RESOURCE MANAGER is availiable 305 //! @todo Textures from .mtl-file need special care.306 326 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 } 308 331 else 309 this->diffuseTexture = NULL; 332 { 333 this->textures[textureNumber] = NULL; 334 } 310 335 } 311 336 … … 339 364 void Material::setBump(const std::string& bump) 340 365 { 341 342 } 366 } 367 368 369 370 int 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.