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

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