source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp @ 2965

Revision 2965, 1.7 KB checked in by mattausch, 16 years ago (diff)

removed dirttexture stuff. started tonemapping stuff

Line 
1#include "common.h"
2#include "Material.h"
3#include "Texture.h"
4#include "glInterface.h"
5#include "RenderState.h"
6
7
8namespace CHCDemoEngine
9{
10
11RgbaColor RandomColor(float a, float b)
12{
13        return RgbaColor(a + Random(b), a + Random(b), a + Random(b), 1);
14}
15
16
17void Material::InitMaterial()
18{
19        mTexture = NULL;
20        mAlphaTestEnabled = false;
21        mCullFaceEnabled = true;
22
23        mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f);
24        mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
25        mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
26        mEmmisiveColor = RgbaColor(.0f, .0f, .0f, 1.0f);
27}
28
29
30Material::Material()
31{
32        InitMaterial();
33}
34
35
36Material::Material(const RgbaColor &color):
37mDiffuseColor(color),
38mAmbientColor(color),
39mSpecularColor(0, 0, 0, 1),
40mTexture(NULL)
41{
42}
43
44
45Material RandomMaterial()
46{
47        float a = 0.1f;
48        float b = 0.9f;
49
50        Material m;
51        m.mDiffuseColor = RandomColor(a, b);
52
53        return m;
54}
55
56
57void Material::Render(RenderState *state)
58{
59        state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled);
60
61        if (state->GetRenderPassType() == RenderState::DEFERRED)
62        {
63                if (mTexture)
64                {
65                        cgGLSetTextureParameter(RenderState::sTexParam, mTexture->GetId());
66                        cgGLEnableTextureParameter(RenderState::sTexParam);
67                }
68                else
69                {
70                        cgGLDisableTextureParameter(RenderState::sTexParam);
71                }
72        }
73        else
74        {
75                if (mTexture)
76                        mTexture->Bind();
77                else
78                        glBindTexture(GL_TEXTURE_2D, 0);
79        }
80
81        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
82        glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
83        glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r);
84        glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
85}
86
87
88}
Note: See TracBrowser for help on using the repository browser.