Changeset 7788 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- May 24, 2006, 3:41:09 AM (18 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/material.cc
r7785 r7788 22 22 #include "debug.h" 23 23 #include "util/loading/resource_manager.h" 24 #include <stdlib.h> 25 #include <string.h> 26 27 //! @todo check if we are in RESOURCE MANAGER-mode 28 #include "util/loading/resource_manager.h" 29 30 using namespace std; 31 32 /** 33 * creates a Material. 24 25 /** 26 * @brief creates a Material. 34 27 * @param mtlName Name of the Material to be added to the Material List 35 28 */ … … 54 47 55 48 /** 56 *deletes a Material57 */49 * @brief deletes a Material 50 */ 58 51 Material::~Material() 59 52 { 60 53 PRINTF(5)("delete Material %s.\n", this->getName()); 61 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 54 69 55 if (this->ambientTexture != NULL) … … 115 101 116 102 /** 117 * sets the material with which the following Faces will be painted103 * @brief sets the material with which the following Faces will be painted 118 104 */ 119 105 bool Material::select() const … … 135 121 // setting the transparency 136 122 if (this->transparency < 1.0 || /* This allows alpha blending of 2D textures with the scene */ 137 (likely(!this->textures.empty() && this->textures[0] != NULL) && this->textures[0]->hasAlpha()))123 (likely(!this->textures.empty() && this->textures[0].hasAlpha()))) 138 124 { 139 125 glEnable(GL_BLEND); … … 164 150 for(unsigned int i = 0; i < this->textures.size(); ++i) 165 151 { 166 if (likely(this->textures[i] != NULL))167 {168 152 glActiveTexture(Material::glTextureArbs[i]); 169 153 glEnable(GL_TEXTURE_2D); 170 if(this->textures[i] ->hasAlpha())154 if(this->textures[i].hasAlpha()) 171 155 { 172 156 glEnable(GL_BLEND); 173 157 } 174 glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture()); 175 } 158 glBindTexture(GL_TEXTURE_2D, this->textures[i].getTexture()); 176 159 } 177 160 Material::selectedMaterial = this; … … 333 316 // MAPPING // 334 317 335 void Material::setDiffuseMap( Texture*texture, unsigned int textureNumber)318 void Material::setDiffuseMap(const Texture& texture, unsigned int textureNumber) 336 319 { 337 320 assert(textureNumber < Material::getMaxTextureUnits()); 338 321 339 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)340 ResourceManager::getInstance()->unload(this->textures[textureNumber]);341 342 322 if (this->textures.size() <= textureNumber) 343 this->textures.resize(textureNumber+1, NULL);323 this->textures.resize(textureNumber+1, Texture()); 344 324 345 325 //! @todo check if RESOURCE MANAGER is availiable … … 357 337 358 338 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 339 if (this->textures.size() <= textureNumber) 363 this->textures.resize(textureNumber+1, NULL);340 this->textures.resize(textureNumber+1, Texture()); 364 341 365 342 //! @todo check if RESOURCE MANAGER is availiable … … 367 344 { 368 345 369 this->textures[textureNumber] = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);346 this->textures[textureNumber] = *(Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target); 370 347 } 371 348 else 372 349 { 373 this->textures[textureNumber] = NULL;374 } 375 } 376 377 /** 378 * Sets the Materials Diffuse Map350 this->textures[textureNumber] = Texture(); 351 } 352 } 353 354 /** 355 * @brief Sets the Materials Diffuse Map 379 356 * @param surface pointer to SDL_Surface which shall be used as texture 380 357 */ … … 384 361 385 362 386 if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)387 ResourceManager::getInstance()->unload(this->textures[textureNumber]);388 389 363 if (this->textures.size() <= textureNumber) 390 this->textures.resize(textureNumber+1, NULL);364 this->textures.resize(textureNumber+1, Texture()); 391 365 392 366 if(surface != NULL) 393 367 { 394 this->textures[textureNumber] = newTexture(surface, GL_TEXTURE_2D);368 this->textures[textureNumber] = Texture(surface, GL_TEXTURE_2D); 395 369 } 396 370 else 397 371 { 398 this->textures[textureNumber] = NULL;399 } 400 401 } 402 403 404 /** 405 * Sets the Materials Ambient Map372 this->textures[textureNumber] = Texture(); 373 } 374 375 } 376 377 378 /** 379 * @brief Sets the Materials Ambient Map 406 380 * @param aMap the Name of the Image to Use 407 381 @todo implement this … … 414 388 415 389 /** 416 * Sets the Materials Specular Map390 * @brief Sets the Materials Specular Map 417 391 * @param sMap the Name of the Image to Use 418 392 @todo implement this … … 425 399 426 400 /** 427 * Sets the Materials Bumpiness401 * @brief Sets the Materials Bumpiness 428 402 * @param bump the Name of the Image to Use 429 403 * @todo implemet this 430 404 */ 431 405 void Material::setBump(const std::string& bump) -
trunk/src/lib/graphics/importer/material.h
r7785 r7788 53 53 54 54 // MAPPING // 55 void setDiffuseMap( Texture*texture, unsigned int textureNumber = 0);55 void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); 56 56 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 57 57 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); … … 60 60 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 61 61 void setBump(const std::string& bump); 62 GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i] ->getTexture() : 0; };62 GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; 63 63 64 64 static void addTexturePath(const std::string& pathName); … … 81 81 GLenum tFactor; 82 82 83 std::vector<Texture *> textures; //!< An Array of Textures.83 std::vector<Texture> textures; //!< An Array of Textures. 84 84 85 85 Texture* ambientTexture; //!< The ambient texture of the Material. -
trunk/src/lib/graphics/importer/texture.cc
r7785 r7788 103 103 104 104 105 Texture::Texture(const Texture& texture) 106 : data(texture.data) 107 { 108 this->setClassID(CL_TEXTURE, "Texture"); 109 this->priority = 0.5; 110 } 105 111 106 112 -
trunk/src/lib/graphics/importer/texture.h
r7785 r7788 30 30 bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D); 31 31 32 33 34 32 bool rebuild(); 35 33 36 34 bool setSurface(SDL_Surface* newSurface); 35 /** @returns true if the Surface has an Alpha Value. */ 37 36 bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; }; 38 37 bool setTexture(GLuint texture); … … 49 48 { 50 49 public: 51 52 public: 50 Texture(const Texture& texture); 53 51 Texture(GLenum target = GL_TEXTURE_2D); 54 52 Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
Note: See TracChangeset
for help on using the changeset viewer.