#ifndef __MATERIAL_H #define __MATERIAL_H #include "glInterface.h" #include #include #include "common.h" namespace CHCDemoEngine { class Texture; class RenderState; class RgbaColor { public: float r, g, b, a; RgbaColor(): r(1), g(1), b(1), a(1) {} RgbaColor(float _r, float _g, float _b, float _a): r(_r), g(_g), b(_b), a(_a) {} friend RgbaColor RandomColor(float a = 0.0f, float b = 1.0f); }; // Forward declarations RgbaColor RandomColor(float a, float b); class Material { friend class ResourceManager; public: Material(); Material(const RgbaColor &color); friend Material RandomMaterial(); inline Texture *GetTexture() const { return mTexture; } inline RgbaColor GetAmbient() const { return mAmbientColor; } inline RgbaColor GetDiffuse() const { return mDiffuseColor; } inline RgbaColor GetSpecular() const { return mSpecularColor; } inline RgbaColor GetEmmisive() const { return mEmmisiveColor; } inline void SetTexture(Texture *texture) { mTexture = texture; } inline void SetAmbient(const RgbaColor &color) { mAmbientColor = color; } inline void SetDiffuse(const RgbaColor &color) { mDiffuseColor = color; } inline void SetSpecular(const RgbaColor &color) { mSpecularColor = color; } inline void SetEmmisive(const RgbaColor &color) { mEmmisiveColor = color; } inline void SetAlphaTestEnabled(bool alpha) { mAlphaTestEnabled = alpha; } inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; } /** Renders this material. */ void Render(RenderState *state); /** Initialize the material with default values */ void InitMaterial(); static CGparameter sDiffuseParam; static CGparameter sDiffuseTexParam; static CGparameter sAmbientParam; static CGparameter sAmbientTexParam; protected: /////////// RgbaColor mDiffuseColor; RgbaColor mSpecularColor; RgbaColor mAmbientColor; RgbaColor mEmmisiveColor; bool mAlphaTestEnabled; /// the assciated texture Texture *mTexture; }; extern Material RandomMaterial(); } #endif