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

Revision 3028, 1.3 KB checked in by mattausch, 16 years ago (diff)

debug version: what to do with shader programs??

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        mCullFaceEnabled = true;
22
23        mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f);
24        mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
25        mSpecularColor = RgbaColor(.0f, .0f, .0f, 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
57void Material::Render(RenderState *state)
58{
59        state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled);
60
61        state->SetTexture(mTexture);
62
63        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
64        glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
65        glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r);
66        glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
67}
68
69
70}
Note: See TracBrowser for help on using the repository browser.