[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" |
---|
| 19 | |
---|
[5405] | 20 | // FORWARD DECLARATIONS // |
---|
[3140] | 21 | |
---|
[2842] | 22 | //! Class to handle Materials. |
---|
[4584] | 23 | class Material : public BaseObject |
---|
[2776] | 24 | { |
---|
[7785] | 25 | public: |
---|
| 26 | Material (const std::string& mtlName = ""); |
---|
| 27 | virtual ~Material (); |
---|
[2778] | 28 | |
---|
[7785] | 29 | Material& operator=(const Material& material); |
---|
[6622] | 30 | |
---|
[7785] | 31 | bool select () const; |
---|
[2778] | 32 | |
---|
[7785] | 33 | void setIllum (int illum); |
---|
| 34 | int getIllumModel() const { return this->illumModel; }; |
---|
| 35 | void setDiffuse (float r, float g, float b); |
---|
| 36 | void setAmbient (float r, float g, float b); |
---|
| 37 | void setSpecular (float r, float g, float b); |
---|
| 38 | void setShininess (float shini); |
---|
| 39 | void setTransparency (float trans); |
---|
| 40 | void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; |
---|
[2776] | 41 | |
---|
[3070] | 42 | |
---|
[7785] | 43 | // TODO Move them out of here |
---|
| 44 | void setIllum (char* illum); |
---|
| 45 | void setDiffuse (char* rgb); |
---|
| 46 | void setAmbient (char* rgb); |
---|
| 47 | void setSpecular (char* rgb); |
---|
| 48 | void setShininess (char* shini); |
---|
| 49 | void setTransparency (char* trans); |
---|
[4466] | 50 | |
---|
[7919] | 51 | void getDiffuseColor(float& r, float& g, float& b) const { r = diffuse[0], g = diffuse[1], b = diffuse[2]; } |
---|
[7785] | 52 | |
---|
| 53 | // MAPPING // |
---|
[7788] | 54 | void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); |
---|
[7785] | 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 | |
---|
| 58 | void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); |
---|
| 59 | void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); |
---|
| 60 | void setBump(const std::string& bump); |
---|
[7788] | 61 | GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; |
---|
[7785] | 62 | |
---|
| 63 | static void addTexturePath(const std::string& pathName); |
---|
| 64 | |
---|
| 65 | public: |
---|
| 66 | static const GLenum glTextureArbs[]; //!< The Texture ARB's |
---|
| 67 | |
---|
| 68 | static int getMaxTextureUnits(); |
---|
| 69 | |
---|
[5866] | 70 | private: |
---|
[7785] | 71 | static const Material* selectedMaterial; //!< The currently selected material. |
---|
[6622] | 72 | |
---|
[7785] | 73 | int illumModel; //!< The IlluminationModel is either flat or smooth. |
---|
| 74 | float diffuse [4]; //!< The diffuse color of the Material. |
---|
| 75 | float ambient [4]; //!< The ambient color of the Material. |
---|
| 76 | float specular [4]; //!< The specular color of the Material. |
---|
| 77 | float shininess; //!< The shininess of the Material. |
---|
| 78 | float transparency; //!< The transperency of the Material. |
---|
| 79 | GLenum sFactor; |
---|
| 80 | GLenum tFactor; |
---|
| 81 | |
---|
[7788] | 82 | std::vector<Texture> textures; //!< An Array of Textures. |
---|
[7785] | 83 | |
---|
| 84 | Texture* ambientTexture; //!< The ambient texture of the Material. |
---|
| 85 | Texture* specularTexture; //!< The specular texture of the Material. |
---|
| 86 | |
---|
| 87 | |
---|
[2776] | 88 | }; |
---|
| 89 | #endif |
---|