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

Revision 2756, 1.2 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[2747]1#include "common.h"
2#include "Material.h"
[2756]3#include "Texture.h"
4#include "glInterface.h"
[2747]5
[2756]6
[2751]7namespace CHCDemo
8{
[2747]9
[2756]10RgbColor RandomColor(float a, float b)
[2747]11{
12        return RgbColor(a + Random(b), a + Random(b), a + Random(b));
13}
14
15
[2756]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
[2755]26Material::Material(): mId(0)
[2756]27{
28        InitMaterial();
29}
[2755]30
[2756]31
32Material::Material(int id):
33mId(id)
[2755]34{
[2756]35        InitMaterial();
[2755]36}
37
38
[2756]39Material::Material(const RgbColor &color):
40mDiffuseColor(color),
[2755]41mAmbientColor(color),
[2756]42mSpecularColor(0, 0, 0),
43mId(0),
44mTexture(NULL)
[2755]45{
46}
47
48
49int Material::GetId() const
50{
51        return mId;
52}
53
54
[2747]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
[2756]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);
[2751]77}
[2756]78
79
80}
Note: See TracBrowser for help on using the repository browser.