Changeset 8619 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Jun 20, 2006, 1:24:11 PM (18 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/material.cc
r8376 r8619 22 22 #include "debug.h" 23 23 #include "compiler.h" 24 25 #include "loading/load_param.h" 26 24 27 #include "util/loading/resource_manager.h" 25 28 … … 47 50 } 48 51 52 Material& 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 70 void 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 49 85 /** 50 86 * @brief deletes a Material … … 65 101 66 102 const 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_TEXTURE778 };79 103 80 104 … … 104 128 * @brief sets the material with which the following Faces will be painted 105 129 */ 106 130 bool Material::select() const 107 131 { 108 132 if (unlikely(this == Material::selectedMaterial)) 109 110 111 /// !! HACK !!! FIX THIS IN MODEL ///133 return true; 134 135 /// !! HACK !!! FIX THIS IN MODEL /// 112 136 else if (likely(Material::selectedMaterial != NULL)) 113 137 { 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 // } 121 145 } 122 146 … … 125 149 for(unsigned int i = 0; i < Material::selectedMaterial->textures.size(); ++i) 126 150 { 127 128 129 151 glActiveTexture(Material::glTextureArbs[i]); 152 //glBindTexture(GL_TEXTURE_2D, 0); 153 glDisable(GL_TEXTURE_2D); 130 154 } 131 155 } 132 156 133 157 // setting diffuse color 134 158 glColor4f (diffuse.r(), diffuse.g(), diffuse.b(), diffuse.a()); 135 159 // setting ambient color … … 161 185 for(unsigned int i = 0; i < this->textures.size(); ++i) 162 186 { 163 164 165 166 167 168 169 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()); 170 194 } 171 195 Material::selectedMaterial = this; … … 179 203 { 180 204 Material::selectedMaterial = NULL; 181 182 183 184 185 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 } 187 211 } 188 212 … … 252 276 this->diffuse.a() = trans; 253 277 } 278 279 /** 280 * @brief sets the Blend-Function Parameters 281 * @param sFactor the Source Parameter. 282 * @param tFactor the Desitnation Parameter. 283 */ 284 void Material::setBlendFuncS(const std::string& sFactor, const std::string& tFactor) 285 { 286 this->setBlendFunc(Material::stringToBlendFunc(sFactor), Material::stringToBlendFunc(tFactor)); 287 } 288 289 254 290 255 291 /** … … 354 390 // HACK 355 391 glActiveTexture(textureNumber); 356 357 392 glEnable(GL_TEXTURE_2D); 393 glBindTexture(GL_TEXTURE_2D, this->textures[textureNumber].getTexture()); 358 394 glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); 359 395 … … 387 423 */ 388 424 void Material::setBump(const std::string& bump) 389 { 390 } 425 {} 391 426 392 427 … … 400 435 return maxTexUnits; 401 436 } 437 438 const 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 */ 455 const 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 */ 468 GLenum 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 478 const 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 491 const 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 }; -
trunk/src/lib/graphics/importer/material.h
r8448 r8619 24 24 class Material : public BaseObject 25 25 { 26 27 28 26 public: 27 Material (const std::string& mtlName = ""); 28 virtual ~Material (); 29 29 30 Material& operator=(const Material& material);30 void loadParams(const TiXmlElement* root); 31 31 32 bool select () const; 33 bool activateTextureUnit(unsigned int textureNumber); 34 static void unselect(); 32 Material& operator=(const Material& material); 35 33 36 void setIllum (int illum); 37 int getIllumModel() const { return this->illumModel; }; 34 bool select () const; 35 bool activateTextureUnit(unsigned int textureNumber); 36 static void unselect(); 38 37 39 void setDiffuse (float r, float g, float b); 40 void setDiffuseColor(const Color& diffuseColor) { this->diffuse = diffuseColor; }; 41 void setAmbient (float r, float g, float b); 42 void setSpecular (float r, float g, float b); 43 void setShininess (float shini); 44 void setTransparency (float trans); 45 void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; 38 void setIllum (int illum); 39 int getIllumModel() const { return this->illumModel; }; 46 40 47 const Color& getDiffuseColor() const { return diffuse; }; 41 void setDiffuse (float r, float g, float b); 42 void setDiffuseColor(const Color& diffuseColor) { this->diffuse = diffuseColor; }; 43 void setAmbient (float r, float g, float b); 44 void setSpecular (float r, float g, float b); 45 void setShininess (float shini); 46 void setTransparency (float trans); 47 void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; 48 void setBlendFuncS(const std::string& sFactor, const std::string& tFactor); 48 49 49 // MAPPING // 50 void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); 51 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 52 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 53 void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); 50 Color& diffuseColor() { return diffuse; }; 51 const Color& diffuseColor() const { return diffuse; }; 54 52 55 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 56 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 57 void setBump(const std::string& bump); 58 GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; 53 // MAPPING // 54 void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); 55 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 56 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 57 void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); 59 58 60 static void addTexturePath(const std::string& pathName); 59 void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); 60 void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); 61 void setBump(const std::string& bump); 61 62 62 public: 63 static const GLenum glTextureArbs[]; //!< The Texture ARB's 63 GLuint diffuseTextureID(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; 64 64 65 static unsigned int getMaxTextureUnits();65 const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; }; 66 66 67 private: 68 static const Material* selectedMaterial; //!< The currently selected material. 67 static void addTexturePath(const std::string& pathName); 69 68 70 int illumModel; //!< The IlluminationModel is either flat or smooth. 71 Color diffuse; //!< The diffuse color of the Material. (also transparency.) 72 Color ambient; //!< The ambient color of the Material. 73 Color specular; //!< The specular color of the Material. 74 float shininess; //!< The shininess of the Material. 75 GLenum sFactor; //!< The Blending Factor for the Source. 76 GLenum tFactor; //!< The Blending Factor for the Destination. 69 const std::string& blendFuncToString(GLenum blendFunc); 70 GLenum stringToBlendFunc(const std::string& blendFuncString); 77 71 78 std::vector<Texture> textures; //!< An Array of Textures.79 72 80 Texture* ambientTexture; //!< The ambient texture of the Material. 81 Texture* specularTexture; //!< The specular texture of the Material. 73 public: 74 static const GLenum glTextureArbs[]; //!< The Texture ARB's 75 76 static const GLenum glBlendFuncParams[]; 77 static const std::string blendFuncNames[]; 78 79 static unsigned int getMaxTextureUnits(); 80 81 private: 82 static const Material* selectedMaterial; //!< The currently selected material. 83 84 int illumModel; //!< The IlluminationModel is either flat or smooth. 85 Color diffuse; //!< The diffuse color of the Material. (also transparency.) 86 Color ambient; //!< The ambient color of the Material. 87 Color specular; //!< The specular color of the Material. 88 float shininess; //!< The shininess of the Material. 89 GLenum sFactor; //!< The Blending Factor for the Source. 90 GLenum tFactor; //!< The Blending Factor for the Destination. 91 92 std::vector<Texture> textures; //!< An Array of Textures. 93 94 Texture* ambientTexture; //!< The ambient texture of the Material. 95 Texture* specularTexture; //!< The specular texture of the Material. 82 96 }; 83 97 -
trunk/src/lib/graphics/importer/texture_sequence.cc
r8324 r8619 180 180 } 181 181 bool success = this->addFrame(addSurface); 182 delete addSurface;182 SDL_FreeSurface(addSurface); 183 183 184 184 return success;
Note: See TracChangeset
for help on using the changeset viewer.