source: GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp @ 2756

Revision 2756, 1.2 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
6
7namespace CHCDemo
8{
9
10RgbColor RandomColor(float a, float b)
11{
12        return RgbColor(a + Random(b), a + Random(b), a + Random(b));
13}
14
15
16void Material::InitMaterial()
17{
18        mTexture = NULL;
19
20        mAmbientColor = RgbColor(0, 0, 0);
21        mDiffuseColor = RgbColor(1, 1, 1);
22        mSpecularColor = RgbColor(0, 0, 0);
23}
24
25
26Material::Material(): mId(0)
27{
28        InitMaterial();
29}
30
31
32Material::Material(int id):
33mId(id)
34{
35        InitMaterial();
36}
37
38
39Material::Material(const RgbColor &color):
40mDiffuseColor(color),
41mAmbientColor(color),
42mSpecularColor(0, 0, 0),
43mId(0),
44mTexture(NULL)
45{
46}
47
48
49int Material::GetId() const
50{
51        return mId;
52}
53
54
55Material RandomMaterial()
56{
57        float a = 0.1f;
58        float b = 0.9f;
59
60        Material m;
61        m.mDiffuseColor = RandomColor(a, b);
62
63        return m;
64}
65
66
67void Material::Render()
68{
69        if (mTexture)
70                mTexture->Bind();
71        else
72                glBindTexture(GL_TEXTURE_2D, 0);
73
74        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
75        glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
76        glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
77}
78
79
80}
Note: See TracBrowser for help on using the repository browser.