Changeset 7785 in orxonox.OLD for trunk/src/lib/graphics/importer/material.cc
- Timestamp:
- May 24, 2006, 3:17:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/material.cc
r7676 r7785 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); 69 71 if (this->specularTexture != NULL) 70 72 ResourceManager::getInstance()->unload(this->specularTexture); 71 } 72 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 } 73 74 if (this == Material::selectedMaterial) 75 Material::selectedMaterial = NULL; 76 } 77 78 79 const Material* Material::selectedMaterial = NULL; 80 81 const GLenum Material::glTextureArbs[] = 82 { 83 GL_TEXTURE0, 84 GL_TEXTURE1, 85 GL_TEXTURE2, 86 GL_TEXTURE3, 87 GL_TEXTURE4, 88 GL_TEXTURE5, 89 GL_TEXTURE6, 90 GL_TEXTURE7 91 }; 92 93 94 /// TODO FIX THIS 95 // Material& Material::operator=(const Material& m) 96 // { 97 // this->setIllum(m.illumModel); 98 // this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]); 99 // this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]); 100 // this->setSpecular(m.specular[0],m.specular[1],m.specular[2]); 101 // this->setShininess(m.shininess); 102 // this->setTransparency(m.transparency); 103 // 104 // if (this->diffuseTexture != NULL) 105 // ResourceManager::getInstance()->unload(this->diffuseTexture); 106 // if (m.diffuseTexture != NULL) 107 // this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture); 108 // this->ambientTexture = NULL; /// FIXME 109 // this->specularTexture = NULL; /// FIXME 110 // 111 // this->setName(m.getName()); 112 // } 113 91 114 92 115 … … 94 117 * sets the material with which the following Faces will be painted 95 118 */ 96 bool Material::select () const 97 { 119 bool Material::select() const 120 { 121 if (unlikely(this == Material::selectedMaterial)) 122 return true; 123 124 98 125 // setting diffuse color 99 126 glColor4f (diffuse[0], diffuse[1], diffuse[2], this->transparency); 100 // glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);101 102 127 // setting ambient color 103 128 glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient); 104 105 129 // setting up Sprecular 106 130 glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular); 107 108 131 // setting up Shininess 109 132 glMaterialf(GL_FRONT, GL_SHININESS, this->shininess); 110 133 134 111 135 // setting the transparency 112 136 if (this->transparency < 1.0 || /* This allows alpha blending of 2D textures with the scene */ 113 ( this->diffuseTexture && this->diffuseTexture->hasAlpha()))137 (likely(!this->textures.empty() && this->textures[0] != NULL) && this->textures[0]->hasAlpha())) 114 138 { 115 139 glEnable(GL_BLEND); … … 117 141 } 118 142 else 119 { 120 glDisable(GL_BLEND); 121 //glColor4f(*(this->diffuse), *(this->diffuse+1), *(this->diffuse+2), 1); 122 } 143 { 144 glDisable(GL_BLEND); 145 } 123 146 124 147 … … 129 152 glShadeModel(GL_SMOOTH); 130 153 131 if (this->diffuseTexture != NULL) 154 if (likely(Material::selectedMaterial != NULL)) 155 { 156 for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i) 132 157 { 158 glActiveTexture(Material::glTextureArbs[i]); 159 glBindTexture(GL_TEXTURE_2D, 0); 160 glDisable(GL_TEXTURE_2D); 161 } 162 } 163 164 for(unsigned int i = 0; i < this->textures.size(); ++i) 165 { 166 if (likely(this->textures[i] != NULL)) 167 { 168 glActiveTexture(Material::glTextureArbs[i]); 133 169 glEnable(GL_TEXTURE_2D); 134 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 170 if(this->textures[i]->hasAlpha()) 171 { 172 glEnable(GL_BLEND); 173 } 174 glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture()); 135 175 } 136 else 137 { 138 glDisable(GL_TEXTURE_2D); 139 glBindTexture(GL_TEXTURE_2D, 0); 140 } 176 } 177 Material::selectedMaterial = this; 178 179 /* if (this->diffuseTexture != NULL) 180 { 181 glEnable(GL_TEXTURE_2D); 182 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 183 } 184 else 185 { 186 glDisable(GL_TEXTURE_2D); 187 glBindTexture(GL_TEXTURE_2D, 0); 188 }*/ 141 189 } 142 190 … … 162 210 /** 163 211 * Sets the Material Diffuse Color. 164 * @param r Red Color Channel. 212 * @param r Red Color Channel.a 165 213 * @param g Green Color Channel. 166 214 * @param b Blue Color Channel. … … 226 274 this->specular[2] = b; 227 275 this->specular[3] = 1.0; 228 276 } 229 277 230 278 /** … … 285 333 // MAPPING // 286 334 335 void Material::setDiffuseMap(Texture* texture, unsigned int textureNumber) 336 { 337 assert(textureNumber < Material::getMaxTextureUnits()); 338 339 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL) 340 ResourceManager::getInstance()->unload(this->textures[textureNumber]); 341 342 if (this->textures.size() <= textureNumber) 343 this->textures.resize(textureNumber+1, NULL); 344 345 //! @todo check if RESOURCE MANAGER is availiable 346 this->textures[textureNumber] = texture; 347 } 348 349 350 /** 351 * @brief Sets the Materials Diffuse Map 352 * @param dMap the Name of the Image to Use 353 */ 354 void Material::setDiffuseMap(const std::string& dMap, GLenum target, unsigned int textureNumber) 355 { 356 assert(textureNumber < Material::getMaxTextureUnits()); 357 358 PRINTF(5)("setting Diffuse Map %s\n", dMap.c_str()); 359 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL) 360 ResourceManager::getInstance()->unload(this->textures[textureNumber]); 361 362 if (this->textures.size() <= textureNumber) 363 this->textures.resize(textureNumber+1, NULL); 364 365 //! @todo check if RESOURCE MANAGER is availiable 366 if (!dMap.empty()) 367 { 368 369 this->textures[textureNumber] = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 370 } 371 else 372 { 373 this->textures[textureNumber] = NULL; 374 } 375 } 376 287 377 /** 288 378 * Sets the Materials Diffuse Map 289 * @param dMap the Name of the Image to Use 290 */ 291 void Material::setDiffuseMap(const std::string& dMap, GLenum target) 292 { 293 PRINTF(5)("setting Diffuse Map %s\n", dMap.c_str()); 294 if (this->diffuseTexture != NULL) 295 ResourceManager::getInstance()->unload(this->diffuseTexture); 296 297 //! @todo check if RESOURCE MANAGER is availiable 298 //! @todo Textures from .mtl-file need special care. 299 if (!dMap.empty()) 300 this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 379 * @param surface pointer to SDL_Surface which shall be used as texture 380 */ 381 void Material::setSDLDiffuseMap(SDL_Surface *surface, GLenum target, unsigned int textureNumber) 382 { 383 assert(textureNumber < Material::getMaxTextureUnits()); 384 385 386 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL) 387 ResourceManager::getInstance()->unload(this->textures[textureNumber]); 388 389 if (this->textures.size() <= textureNumber) 390 this->textures.resize(textureNumber+1, NULL); 391 392 if(surface != NULL) 393 { 394 this->textures[textureNumber] = new Texture(surface, GL_TEXTURE_2D); 395 } 301 396 else 302 this->diffuseTexture = NULL; 303 } 397 { 398 this->textures[textureNumber] = NULL; 399 } 400 401 } 402 304 403 305 404 /** … … 332 431 void Material::setBump(const std::string& bump) 333 432 { 334 335 } 433 } 434 435 436 437 int Material::getMaxTextureUnits() 438 { 439 int maxTexUnits = 0; 440 glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits); 441 return maxTexUnits; 442 }
Note: See TracChangeset
for help on using the changeset viewer.