1 | #ifndef __MATERIAL_H
|
---|
2 | #define __MATERIAL_H
|
---|
3 |
|
---|
4 | #include "glInterface.h"
|
---|
5 | #include "common.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemoEngine
|
---|
9 | {
|
---|
10 |
|
---|
11 | class Texture;
|
---|
12 | class RenderState;
|
---|
13 |
|
---|
14 |
|
---|
15 | class RgbaColor
|
---|
16 | {
|
---|
17 |
|
---|
18 | public:
|
---|
19 |
|
---|
20 | float r, g, b, a;
|
---|
21 |
|
---|
22 | RgbaColor(): r(1), g(1), b(1), a(1)
|
---|
23 | {}
|
---|
24 |
|
---|
25 | RgbaColor(float _r, float _g, float _b, float _a): r(_r), g(_g), b(_b), a(_a)
|
---|
26 | {}
|
---|
27 |
|
---|
28 | friend RgbaColor RandomColor(float a = 0.0f, float b = 1.0f);
|
---|
29 | };
|
---|
30 |
|
---|
31 |
|
---|
32 | // Forward declarations
|
---|
33 | RgbaColor RandomColor(float a, float b);
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | class Material
|
---|
38 | {
|
---|
39 | friend class ResourceManager;
|
---|
40 |
|
---|
41 | public:
|
---|
42 |
|
---|
43 | /** Sets default material (ambient intensity 0.2f, diffuse intensity 1.0f)
|
---|
44 | */
|
---|
45 | Material();
|
---|
46 |
|
---|
47 | /** Sets ambient and diffuse color to color
|
---|
48 | */
|
---|
49 | Material(const RgbaColor &color);
|
---|
50 |
|
---|
51 | friend Material RandomMaterial();
|
---|
52 |
|
---|
53 | inline Texture *GetTexture() const { return mTexture; }
|
---|
54 |
|
---|
55 | inline RgbaColor GetAmbient() const { return mAmbientColor; }
|
---|
56 | inline RgbaColor GetDiffuse() const { return mDiffuseColor; }
|
---|
57 | inline RgbaColor GetSpecular() const { return mSpecularColor; }
|
---|
58 | inline RgbaColor GetEmmisive() const { return mEmmisiveColor; }
|
---|
59 |
|
---|
60 | inline void SetTexture(Texture *texture) { mTexture = texture; }
|
---|
61 |
|
---|
62 | inline void SetAmbient(const RgbaColor &color) { mAmbientColor = color; }
|
---|
63 | inline void SetDiffuse(const RgbaColor &color) { mDiffuseColor = color; }
|
---|
64 | inline void SetSpecular(const RgbaColor &color) { mSpecularColor = color; }
|
---|
65 | inline void SetEmmisive(const RgbaColor &color) { mEmmisiveColor = color; }
|
---|
66 |
|
---|
67 | inline void SetAlphaTestEnabled(bool alpha) { mAlphaTestEnabled = alpha; }
|
---|
68 | inline void SetCullFaceEnabled(bool cull) { mCullFaceEnabled = cull; }
|
---|
69 |
|
---|
70 | inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; }
|
---|
71 | inline bool IsCullFaceEnabled() const { return mCullFaceEnabled; }
|
---|
72 |
|
---|
73 | /** Renders this material.
|
---|
74 | */
|
---|
75 | void Render(RenderState *state);
|
---|
76 | /** Initialize the material with default values
|
---|
77 | */
|
---|
78 | void InitMaterial();
|
---|
79 |
|
---|
80 | protected:
|
---|
81 |
|
---|
82 | ///////////
|
---|
83 |
|
---|
84 | RgbaColor mDiffuseColor;
|
---|
85 | RgbaColor mSpecularColor;
|
---|
86 | RgbaColor mAmbientColor;
|
---|
87 | RgbaColor mEmmisiveColor;
|
---|
88 |
|
---|
89 | bool mAlphaTestEnabled;
|
---|
90 | bool mCullFaceEnabled;
|
---|
91 | /// the associated texture
|
---|
92 | Texture *mTexture;
|
---|
93 | };
|
---|
94 |
|
---|
95 |
|
---|
96 | extern Material RandomMaterial();
|
---|
97 |
|
---|
98 | }
|
---|
99 |
|
---|
100 | #endif
|
---|