Rev | Line | |
---|
[2747] | 1 | #include "common.h"
|
---|
| 2 | #include "Material.h"
|
---|
[2756] | 3 | #include "Texture.h"
|
---|
| 4 | #include "glInterface.h"
|
---|
[2747] | 5 |
|
---|
[2756] | 6 |
|
---|
[2751] | 7 | namespace CHCDemo
|
---|
| 8 | {
|
---|
[2747] | 9 |
|
---|
[2756] | 10 | RgbColor RandomColor(float a, float b)
|
---|
[2747] | 11 | {
|
---|
| 12 | return RgbColor(a + Random(b), a + Random(b), a + Random(b));
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 |
|
---|
[2756] | 16 | void 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] | 26 | Material::Material(): mId(0)
|
---|
[2756] | 27 | {
|
---|
| 28 | InitMaterial();
|
---|
| 29 | }
|
---|
[2755] | 30 |
|
---|
[2756] | 31 |
|
---|
| 32 | Material::Material(int id):
|
---|
| 33 | mId(id)
|
---|
[2755] | 34 | {
|
---|
[2756] | 35 | InitMaterial();
|
---|
[2755] | 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
[2756] | 39 | Material::Material(const RgbColor &color):
|
---|
| 40 | mDiffuseColor(color),
|
---|
[2755] | 41 | mAmbientColor(color),
|
---|
[2756] | 42 | mSpecularColor(0, 0, 0),
|
---|
| 43 | mId(0),
|
---|
| 44 | mTexture(NULL)
|
---|
[2755] | 45 | {
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | int Material::GetId() const
|
---|
| 50 | {
|
---|
| 51 | return mId;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
[2747] | 55 | Material 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 |
|
---|
| 67 | void 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.