00001
00045
00046
#include <opengl/gl.h>
00047
#include <opengl/glu.h>
00048
#include <glut/glut.h>
00049
#include <vector>
00050
#include "CMaterialBank.h"
00051
00052
00056
00057
CMaterialBank *g_pMaterialBank;
00058
00059
00060
00064
00065
const GL_MATERIAL CMaterialBank::m_DefaultMaterials[] = {
00067 { 1.00f, 1.00f, 1.00f, 0.00f,
00068 RGBA_BLACK,
00069 RGBA_BLACK,
00070 RGBA_BLACK, 0.0f },
00071
00073 { 1.00f, 0.00f, 0.00f, 0.75f,
00074 RGBA_BLACK,
00075 RGBA_BLACK,
00076 RGBA_BLACK, 0.0f },
00077
00079 { 0.40f, 1.00f, 1.00f, 0.75f,
00080 RGBA_BLACK,
00081 RGBA_BLACK,
00082 RGBA_BLACK, 0.0f },
00083
00085 { 0.00f, 1.00f, 0.00f, 0.75f,
00086 RGBA_BLACK,
00087 RGBA_BLACK,
00088 RGBA_BLACK, 0.0f },
00089
00091 { 1.00f, 1.00f, 1.00f, 0.90f,
00092 RGBA_BLACK,
00093 RGBA_BLACK,
00094 RGBA_BLACK, 0.0f }
00095 };
00096
00097
00098
00099
00103
00104 CMaterialBank::CMaterialBank(
void)
00105 {
00106 m_CustomMaterials.reserve(CUSTOM_MATERIAL_BLOCK_SIZE);
00107 }
00108
00109
00110
00114
00115 CMaterialBank::~CMaterialBank(
void)
00116 {
00117 std::vector<GL_MATERIAL*>::iterator i;
00118
00119
for(i = m_CustomMaterials.begin(); i != m_CustomMaterials.end(); i++)
00120 m_CustomMaterials.erase(i);
00121 }
00122
00123
00124
00125
00135
00136 bool CMaterialBank::SetMaterial(
int iMaterial)
00137 {
00138
if((iMaterial < 0) || (iMaterial > MAX_MATERIALS)){
00139
GLSetMaterial(&m_DefaultMaterials[0]);
00140
return false;
00141 }
00142
00143
GLSetMaterial(&m_DefaultMaterials[iMaterial]);
00144
return true;
00145 }
00146
00147
00148
00155
00156 void CMaterialBank::GLSetMaterial(
const GL_MATERIAL* pMaterial)
00157 {
00158 glMaterialfv(GL_FRONT, GL_AMBIENT, (GLfloat*)&pMaterial->
Ambient);
00159 glMaterialfv(GL_FRONT, GL_SPECULAR, (GLfloat*)&pMaterial->
Specular);
00160 glMaterialfv(GL_FRONT, GL_SHININESS, (GLfloat*)&pMaterial->
Shininess);
00161 glMaterialfv(GL_FRONT, GL_DIFFUSE, (GLfloat*)&pMaterial->
Diffuse);
00162
00163 }
00164
00165
00166
00176
00177 bool CMaterialBank::SetCustomMaterial(
int iMaterial)
00178 {
00179
if((iMaterial>=0) && (iMaterial<(
int)m_CustomMaterials.size())){
00180
00181
GLSetMaterial(m_CustomMaterials[iMaterial]);
00182
return true;
00183 }
00184
00185
GLSetMaterial(&m_DefaultMaterials[0]);
00186
return false;
00187 }
00188
00189
00190
00191
00200
00201 bool CMaterialBank::GetMaterial(
int iMaterial,
GL_MATERIAL* pMaterial)
00202 {
00203
if((iMaterial<0) || (iMaterial>MAX_MATERIALS)){
00204
return false;
00205 }
00206 *pMaterial = m_DefaultMaterials[iMaterial];
00207
return true;
00208 }
00209
00210
00211
00212
00221
00222 bool CMaterialBank::GetCustomMaterial(
int iMaterial,
GL_MATERIAL* pMaterial)
00223 {
00224
if((iMaterial<0) || (iMaterial>(
int)m_CustomMaterials.size()))
00225
return false;
00226
00227 pMaterial = m_CustomMaterials[iMaterial];
00228
return true;
00229 }
00230
00231
00232
00233
00239
00240 void CMaterialBank::AddCustomMaterial(
GL_MATERIAL* pMaterial)
00241 {
00242 m_CustomMaterials.push_back(pMaterial);
00243 }
00244
00245
00246