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

Revision 2795, 1.4 KB checked in by mattausch, 17 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
22        mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f);
23        mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
24        //mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
25        mSpecularColor = RgbaColor(0.5f, 0.5f, 0.5f, 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
57//void Material::Render(RenderState *state)
58void Material::Render(RenderState *state)
59{
60        state->SetState(mTexture != NULL, mAlphaTestEnabled);
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.