1 | /*! |
---|
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 | */ |
---|
7 | |
---|
8 | #ifndef _MATERIAL_H |
---|
9 | #define _MATERIAL_H |
---|
10 | #include "base_object.h" |
---|
11 | |
---|
12 | |
---|
13 | #if HAVE_CONFIG_H |
---|
14 | #include <config.h> |
---|
15 | #endif /* HAVE_CONFIG_H */ |
---|
16 | |
---|
17 | #include <vector> |
---|
18 | #include "texture.h" |
---|
19 | |
---|
20 | // FORWARD DECLARATIONS // |
---|
21 | |
---|
22 | //! Class to handle Materials. |
---|
23 | class Material : public BaseObject |
---|
24 | { |
---|
25 | public: |
---|
26 | Material (const std::string& mtlName = ""); |
---|
27 | virtual ~Material (); |
---|
28 | |
---|
29 | Material& operator=(const Material& material); |
---|
30 | |
---|
31 | bool select () const; |
---|
32 | bool activateTextureUnit(unsigned int textureNumber); |
---|
33 | static void unselect(); |
---|
34 | |
---|
35 | void setIllum (int illum); |
---|
36 | int getIllumModel() const { return this->illumModel; }; |
---|
37 | void setDiffuse (float r, float g, float b); |
---|
38 | void setAmbient (float r, float g, float b); |
---|
39 | void setSpecular (float r, float g, float b); |
---|
40 | void setShininess (float shini); |
---|
41 | void setTransparency (float trans); |
---|
42 | void setBlendFunc(GLenum sFactor, GLenum tFactor) { this->sFactor = sFactor; this->tFactor = tFactor; }; |
---|
43 | |
---|
44 | void getDiffuseColor(float& r, float& g, float& b) const { r = diffuse[0], g = diffuse[1], b = diffuse[2]; } |
---|
45 | |
---|
46 | // MAPPING // |
---|
47 | void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); |
---|
48 | void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); |
---|
49 | void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); |
---|
50 | void renderToTexture(unsigned int textureNumber, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); |
---|
51 | |
---|
52 | void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D); |
---|
53 | void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D); |
---|
54 | void setBump(const std::string& bump); |
---|
55 | GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; }; |
---|
56 | |
---|
57 | static void addTexturePath(const std::string& pathName); |
---|
58 | |
---|
59 | public: |
---|
60 | static const GLenum glTextureArbs[]; //!< The Texture ARB's |
---|
61 | |
---|
62 | static unsigned int getMaxTextureUnits(); |
---|
63 | |
---|
64 | private: |
---|
65 | static const Material* selectedMaterial; //!< The currently selected material. |
---|
66 | |
---|
67 | int illumModel; //!< The IlluminationModel is either flat or smooth. |
---|
68 | float diffuse [4]; //!< The diffuse color of the Material. |
---|
69 | float ambient [4]; //!< The ambient color of the Material. |
---|
70 | float specular [4]; //!< The specular color of the Material. |
---|
71 | float shininess; //!< The shininess of the Material. |
---|
72 | float transparency; //!< The transperency of the Material. |
---|
73 | GLenum sFactor; //!< The Blending Factor for the Source. |
---|
74 | GLenum tFactor; //!< The Blending Factor for the Destination. |
---|
75 | |
---|
76 | std::vector<Texture> textures; //!< An Array of Textures. |
---|
77 | |
---|
78 | Texture* ambientTexture; //!< The ambient texture of the Material. |
---|
79 | Texture* specularTexture; //!< The specular texture of the Material. |
---|
80 | }; |
---|
81 | |
---|
82 | #endif |
---|