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

Revision 2844, 2.2 KB checked in by mattausch, 16 years ago (diff)

lod starting to work

RevLine 
[2747]1#include "common.h"
2#include "Material.h"
[2756]3#include "Texture.h"
4#include "glInterface.h"
[2769]5#include "RenderState.h"
[2747]6
[2756]7
[2776]8namespace CHCDemoEngine
[2751]9{
[2747]10
[2819]11CGparameter Material::sDiffuseParam;
12CGparameter Material::sDiffuseTexParam;
[2822]13CGparameter Material::sAmbientParam;
14CGparameter Material::sAmbientTexParam;
[2819]15
[2822]16
[2769]17RgbaColor RandomColor(float a, float b)
[2747]18{
[2769]19        return RgbaColor(a + Random(b), a + Random(b), a + Random(b), 1);
[2747]20}
21
22
[2756]23void Material::InitMaterial()
24{
25        mTexture = NULL;
[2769]26        mAlphaTestEnabled = false;
[2844]27        mCullFaceEnabled = true;
[2756]28
[2795]29        mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f);
[2769]30        mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f);
[2818]31        mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f);
[2795]32        mEmmisiveColor = RgbaColor(.0f, .0f, .0f, 1.0f);
[2756]33}
34
35
[2795]36Material::Material()
[2756]37{
38        InitMaterial();
39}
[2755]40
[2756]41
[2769]42Material::Material(const RgbaColor &color):
[2756]43mDiffuseColor(color),
[2755]44mAmbientColor(color),
[2795]45mSpecularColor(0, 0, 0, 1),
[2756]46mTexture(NULL)
[2755]47{
48}
49
50
[2747]51Material RandomMaterial()
52{
53        float a = 0.1f;
54        float b = 0.9f;
55
56        Material m;
57        m.mDiffuseColor = RandomColor(a, b);
58
59        return m;
60}
61
[2756]62
[2769]63void Material::Render(RenderState *state)
[2756]64{
[2844]65        state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled);
[2769]66
[2756]67        if (mTexture)
[2819]68        {
[2756]69                mTexture->Bind();
[2819]70        }
[2756]71        else
[2819]72        {
[2756]73                glBindTexture(GL_TEXTURE_2D, 0);
[2819]74        }
[2756]75
[2825]76        if (state->GetRenderType() == RenderState::DEFERRED)
77        {
78                if (mTexture)
79                {
80                        cgGLSetParameter4f(sAmbientTexParam, mEmmisiveColor.r, mEmmisiveColor.g, mEmmisiveColor.b, mEmmisiveColor.a);
81                        cgGLSetParameter4f(sDiffuseTexParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a);
82                }
83                else
84                {
85                        cgGLSetParameter4f(sAmbientParam, mEmmisiveColor.r, mEmmisiveColor.g, mEmmisiveColor.b, mEmmisiveColor.a);
86                        cgGLSetParameter4f(sDiffuseParam, mDiffuseColor.r, mDiffuseColor.g, mDiffuseColor.b, mDiffuseColor.a);
87                }
88        }
89        else if (state->GetRenderType() == RenderState::FIXED)
90        {
91                glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
92                glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
93                glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r);
94                glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
95        }
[2751]96}
[2756]97
98
99}
Note: See TracBrowser for help on using the repository browser.