[2842] | 1 | /*! |
---|
[7785] | 2 | * @file material.h |
---|
| 3 | * @brief Contains the Material Class that handles Material for 3D-Objects. |
---|
| 4 | * @todo free SDL-surface when deleting Material. |
---|
| 5 | * @todo delete imgNameWithPath after use creation. |
---|
| 6 | */ |
---|
[2842] | 7 | |
---|
[2776] | 8 | #ifndef _MATERIAL_H |
---|
| 9 | #define _MATERIAL_H |
---|
[4584] | 10 | #include "base_object.h" |
---|
[2804] | 11 | |
---|
[7785] | 12 | |
---|
[4584] | 13 | #if HAVE_CONFIG_H |
---|
| 14 | #include <config.h> |
---|
[3140] | 15 | #endif /* HAVE_CONFIG_H */ |
---|
| 16 | |
---|
[7785] | 17 | #include <vector> |
---|
[6769] | 18 | #include "texture.h" |
---|
[8376] | 19 | #include "color.h" |
---|
[6769] | 20 | |
---|
[5405] | 21 | // FORWARD DECLARATIONS // |
---|
[3140] | 22 | |
---|
[2842] | 23 | //! Class to handle Materials. |
---|
[4584] | 24 | class Material : public BaseObject |
---|
[2776] | 25 | { |
---|
[8619] | 26 | public: |
---|
| 27 | Material (const std::string& mtlName = ""); |
---|
| 28 | virtual ~Material (); |
---|
[2778] | 29 | |
---|
[8619] | 30 | void loadParams(const TiXmlElement* root); |
---|
[6622] | 31 | |
---|
[8619] | 32 | Material& operator=(const Material& material); |
---|
[2778] | 33 | |
---|
[8619] | 34 | bool select () const; |
---|
| 35 | bool activateTextureUnit(unsigned int textureNumber); |
---|
| 36 | static void unselect(); |
---|
[8376] | 37 | |
---|
[8619] | 38 | void setIllum (int illum); |
---|
| 39 | int getIllumModel() const { return this->illumModel; }; |
---|
[2776] | 40 | |
---|
[8619] | 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); |
---|
[7785] | 49 | |
---|
[8619] | 50 | Color& diffuseColor() { return diffuse; }; |
---|
| 51 | const Color& diffuseColor() const { return diffuse; }; |
---|
[7785] | 52 | |
---|
[8619] | 53 | // MAPPING // |
---|
| 54 | void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); |
---|
[8761] | 55 | void setDiffuseMap(const TextureDataPointer& texturePointer, unsigned int textureNumber = 0); |
---|
[8619] | 56 | void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); |
---|
| 57 | void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); |
---|
| 58 | void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); |
---|
[7785] | 59 | |
---|
[8619] | 60 | void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); |
---|
| 61 | void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); |
---|
| 62 | void setBump(const std::string& bump); |
---|
[7785] | 63 | |
---|
[8619] | 64 | GLuint diffuseTextureID(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; |
---|
[7785] | 65 | |
---|
[8619] | 66 | const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; }; |
---|
[7785] | 67 | |
---|
[8619] | 68 | static void addTexturePath(const std::string& pathName); |
---|
[6622] | 69 | |
---|
[8761] | 70 | static const std::string& blendFuncToString(GLenum blendFunc); |
---|
| 71 | static GLenum stringToBlendFunc(const std::string& blendFuncString); |
---|
[7785] | 72 | |
---|
[8761] | 73 | void debug() const; |
---|
[7785] | 74 | |
---|
[8619] | 75 | public: |
---|
| 76 | static const GLenum glTextureArbs[]; //!< The Texture ARB's |
---|
| 77 | |
---|
| 78 | static const GLenum glBlendFuncParams[]; |
---|
| 79 | static const std::string blendFuncNames[]; |
---|
| 80 | |
---|
| 81 | static unsigned int getMaxTextureUnits(); |
---|
| 82 | |
---|
| 83 | private: |
---|
| 84 | static const Material* selectedMaterial; //!< The currently selected material. |
---|
| 85 | |
---|
| 86 | int illumModel; //!< The IlluminationModel is either flat or smooth. |
---|
| 87 | Color diffuse; //!< The diffuse color of the Material. (also transparency.) |
---|
| 88 | Color ambient; //!< The ambient color of the Material. |
---|
| 89 | Color specular; //!< The specular color of the Material. |
---|
| 90 | float shininess; //!< The shininess of the Material. |
---|
| 91 | GLenum sFactor; //!< The Blending Factor for the Source. |
---|
| 92 | GLenum tFactor; //!< The Blending Factor for the Destination. |
---|
| 93 | |
---|
| 94 | std::vector<Texture> textures; //!< An Array of Textures. |
---|
| 95 | |
---|
| 96 | Texture* ambientTexture; //!< The ambient texture of the Material. |
---|
| 97 | Texture* specularTexture; //!< The specular texture of the Material. |
---|
[8370] | 98 | }; |
---|
[7785] | 99 | |
---|
[2776] | 100 | #endif |
---|