2010-06-03 03:29:43 +02:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-12-01 07:52:39 +01:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2004-09-23 06:00:56 +02:00
|
|
|
#include "Material.h"
|
2010-06-30 23:41:04 +02:00
|
|
|
|
|
|
|
#include "lib/ogl.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/Game.h"
|
|
|
|
#include "ps/Overlay.h" // for CColor
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2004-09-23 07:10:03 +02:00
|
|
|
CMaterial NullMaterial;
|
|
|
|
|
2004-09-23 06:00:56 +02:00
|
|
|
// Values as taken straight from the Blue Book (god bless the Blue Book)
|
2004-09-23 07:10:03 +02:00
|
|
|
static SMaterialColor IdentityDiffuse(0.8f, 0.8f, 0.8f, 1.0f);
|
|
|
|
static SMaterialColor IdentityAmbient(0.2f, 0.2f, 0.2f, 1.0f);
|
|
|
|
static SMaterialColor IdentitySpecular(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
static SMaterialColor IdentityEmissive(0.0f, 0.0f, 0.0f, 1.0f);
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2006-11-07 03:48:27 +01:00
|
|
|
static SMaterialColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f);
|
2005-04-07 06:29:07 +02:00
|
|
|
|
2004-09-23 06:00:56 +02:00
|
|
|
CMaterial::CMaterial()
|
2004-09-24 05:52:03 +02:00
|
|
|
: m_Diffuse(IdentityDiffuse),
|
2005-04-07 06:29:07 +02:00
|
|
|
m_Ambient(IdentityAmbient),
|
|
|
|
m_Specular(IdentitySpecular),
|
|
|
|
m_Emissive(IdentityEmissive),
|
2004-09-23 06:00:56 +02:00
|
|
|
m_SpecularPower(0.0f),
|
2005-01-27 03:52:26 +01:00
|
|
|
m_Alpha(false),
|
2011-03-18 17:57:54 +01:00
|
|
|
m_PlayerID(INVALID_PLAYER),
|
|
|
|
m_TextureColor(BrokenColor),
|
|
|
|
m_UsePlayerColor(false),
|
|
|
|
m_UseTextureColor(false)
|
2004-09-23 06:00:56 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-09-24 05:52:03 +02:00
|
|
|
void CMaterial::Bind()
|
|
|
|
{
|
2005-10-12 06:16:41 +02:00
|
|
|
glMaterialf(GL_FRONT, GL_SHININESS, m_SpecularPower);
|
|
|
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, &m_Diffuse.r);
|
2004-10-30 23:57:46 +02:00
|
|
|
glMaterialfv(GL_FRONT, GL_AMBIENT, &m_Ambient.r);
|
|
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, &m_Specular.r);
|
|
|
|
glMaterialfv(GL_FRONT, GL_EMISSION, &m_Emissive.r);
|
2004-09-24 05:52:03 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
2004-09-24 05:52:03 +02:00
|
|
|
void CMaterial::Unbind()
|
2004-09-23 06:00:56 +02:00
|
|
|
{
|
2004-09-24 05:52:03 +02:00
|
|
|
}
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2004-09-24 05:52:03 +02:00
|
|
|
SMaterialColor CMaterial::GetDiffuse()
|
|
|
|
{
|
|
|
|
return m_Diffuse;
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
2004-09-24 05:52:03 +02:00
|
|
|
SMaterialColor CMaterial::GetAmbient()
|
2004-09-23 06:00:56 +02:00
|
|
|
{
|
2004-09-24 05:52:03 +02:00
|
|
|
return m_Ambient;
|
|
|
|
}
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2004-09-24 05:52:03 +02:00
|
|
|
SMaterialColor CMaterial::GetSpecular()
|
|
|
|
{
|
|
|
|
return m_Specular;
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SMaterialColor CMaterial::GetEmissive()
|
|
|
|
{
|
2004-09-24 05:52:03 +02:00
|
|
|
return m_Emissive;
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
2011-03-18 17:57:54 +01:00
|
|
|
SMaterialColor CMaterial::GetObjectColor()
|
|
|
|
{
|
|
|
|
if (m_UseTextureColor)
|
|
|
|
return m_TextureColor;
|
|
|
|
|
|
|
|
return GetPlayerColor();
|
|
|
|
}
|
|
|
|
|
2005-04-07 06:29:07 +02:00
|
|
|
SMaterialColor CMaterial::GetPlayerColor()
|
|
|
|
{
|
2011-03-18 17:57:54 +01:00
|
|
|
if (m_PlayerID == -1)
|
|
|
|
return BrokenColor;
|
2005-04-07 06:29:07 +02:00
|
|
|
|
2011-03-18 17:57:54 +01:00
|
|
|
CColor c(g_Game->GetPlayerColour(m_PlayerID));
|
|
|
|
return SMaterialColor(c.r, c.g, c.b, c.a);
|
|
|
|
}
|
2005-04-07 06:29:07 +02:00
|
|
|
|
2011-03-18 17:57:54 +01:00
|
|
|
void CMaterial::SetPlayerID(player_id_t id)
|
|
|
|
{
|
|
|
|
m_PlayerID = id;
|
|
|
|
}
|
2005-04-07 06:29:07 +02:00
|
|
|
|
2011-03-18 17:57:54 +01:00
|
|
|
void CMaterial::SetUsePlayerColor(bool use)
|
|
|
|
{
|
|
|
|
m_UsePlayerColor = use;
|
2005-04-07 06:29:07 +02:00
|
|
|
}
|
|
|
|
|
2011-03-18 17:57:54 +01:00
|
|
|
void CMaterial::SetUseTextureColor(bool use)
|
2005-04-07 06:29:07 +02:00
|
|
|
{
|
2011-03-18 17:57:54 +01:00
|
|
|
m_UseTextureColor = use;
|
2005-04-07 06:29:07 +02:00
|
|
|
}
|
|
|
|
|
2011-03-18 17:57:54 +01:00
|
|
|
void CMaterial::SetTextureColor(const CColor& colour)
|
2005-04-07 06:29:07 +02:00
|
|
|
{
|
|
|
|
m_TextureColor = SMaterialColor(colour.r, colour.g, colour.b, colour.a);
|
|
|
|
}
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
void CMaterial::SetTexture(const CStr& texture)
|
2004-09-24 05:52:03 +02:00
|
|
|
{
|
|
|
|
m_Texture = texture;
|
|
|
|
}
|
2004-09-23 06:00:56 +02:00
|
|
|
|
2006-07-20 16:37:58 +02:00
|
|
|
void CMaterial::SetVertexProgram(const CStr& prog)
|
2004-10-30 23:57:46 +02:00
|
|
|
{
|
|
|
|
m_VertexProgram = prog;
|
|
|
|
}
|
|
|
|
|
2006-07-20 16:37:58 +02:00
|
|
|
void CMaterial::SetFragmentProgram(const CStr& prog)
|
2004-10-30 23:57:46 +02:00
|
|
|
{
|
|
|
|
m_FragmentProgram = prog;
|
|
|
|
}
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
void CMaterial::SetDiffuse(const SMaterialColor& color)
|
2004-09-23 06:00:56 +02:00
|
|
|
{
|
2004-09-24 05:52:03 +02:00
|
|
|
m_Diffuse = color;
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
void CMaterial::SetAmbient(const SMaterialColor& color)
|
2004-09-23 06:00:56 +02:00
|
|
|
{
|
2004-09-24 05:52:03 +02:00
|
|
|
m_Ambient = color;
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
void CMaterial::SetSpecular(const SMaterialColor& color)
|
2004-09-23 06:00:56 +02:00
|
|
|
{
|
2004-09-24 05:52:03 +02:00
|
|
|
m_Specular = color;
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
void CMaterial::SetEmissive(const SMaterialColor& color)
|
2004-09-23 06:00:56 +02:00
|
|
|
{
|
2004-09-24 05:52:03 +02:00
|
|
|
m_Emissive = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMaterial::SetSpecularPower(float power)
|
|
|
|
{
|
|
|
|
m_SpecularPower = power;
|
2004-09-23 06:00:56 +02:00
|
|
|
}
|
|
|
|
|
2004-09-24 05:52:03 +02:00
|
|
|
void CMaterial::SetUsesAlpha(bool flag)
|
|
|
|
{
|
|
|
|
m_Alpha = flag;
|
|
|
|
}
|