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

Revision 2960, 1.4 KB checked in by mattausch, 16 years ago (diff)
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        //mAmbientColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
25        mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
26        mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
27        mEmmisiveColor = RgbaColor(.0f, .0f, .0f, 1.0f);
28}
29
30
31Material::Material()
32{
33        InitMaterial();
34}
35
36
37Material::Material(const RgbaColor &color):
38mDiffuseColor(color),
39mAmbientColor(color),
40mSpecularColor(0, 0, 0, 1),
41mTexture(NULL)
42{
43}
44
45
46Material RandomMaterial()
47{
48        float a = 0.1f;
49        float b = 0.9f;
50
51        Material m;
52        m.mDiffuseColor = RandomColor(a, b);
53
54        return m;
55}
56
57
58void Material::Render(RenderState *state)
59{
60        state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled);
61
62        if (mTexture)
63                mTexture->Bind();
64        else
65                glBindTexture(GL_TEXTURE_2D, 0);
66
67        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
68        glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
69        glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r);
70        glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
71}
72
73
74}
Note: See TracBrowser for help on using the repository browser.