make Material a public subclass, remove renderMaterial()
This commit is contained in:
parent
933c4b457a
commit
4e76817336
27
WFObj.cc
27
WFObj.cc
@ -370,7 +370,7 @@ void WFObj::loadMaterial(const std::string & name)
|
|||||||
else if (tokens[0] == "Ns")
|
else if (tokens[0] == "Ns")
|
||||||
{
|
{
|
||||||
m_materials[mat_name].shininess = atof(tokens[1].c_str());
|
m_materials[mat_name].shininess = atof(tokens[1].c_str());
|
||||||
m_materials[mat_name].flags |= Material::MAT_SHININESS;
|
m_materials[mat_name].flags |= Material::SHININESS_BIT;
|
||||||
}
|
}
|
||||||
else if (tokens[0] == "Ka")
|
else if (tokens[0] == "Ka")
|
||||||
{
|
{
|
||||||
@ -380,7 +380,7 @@ void WFObj::loadMaterial(const std::string & name)
|
|||||||
m_materials[mat_name].ambient[i] =
|
m_materials[mat_name].ambient[i] =
|
||||||
atof(tokens[i + 1].c_str());
|
atof(tokens[i + 1].c_str());
|
||||||
m_materials[mat_name].ambient[3] = 1.0;
|
m_materials[mat_name].ambient[3] = 1.0;
|
||||||
m_materials[mat_name].flags |= Material::MAT_AMBIENT;
|
m_materials[mat_name].flags |= Material::AMBIENT_BIT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cerr << "WFObj: error: 'Ka' material directive requires"
|
cerr << "WFObj: error: 'Ka' material directive requires"
|
||||||
@ -394,7 +394,7 @@ void WFObj::loadMaterial(const std::string & name)
|
|||||||
m_materials[mat_name].diffuse[i] =
|
m_materials[mat_name].diffuse[i] =
|
||||||
atof(tokens[i + 1].c_str());
|
atof(tokens[i + 1].c_str());
|
||||||
m_materials[mat_name].diffuse[3] = 1.0;
|
m_materials[mat_name].diffuse[3] = 1.0;
|
||||||
m_materials[mat_name].flags |= Material::MAT_DIFFUSE;
|
m_materials[mat_name].flags |= Material::DIFFUSE_BIT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cerr << "WFObj: error: 'Kd' material directive requires"
|
cerr << "WFObj: error: 'Kd' material directive requires"
|
||||||
@ -408,7 +408,7 @@ void WFObj::loadMaterial(const std::string & name)
|
|||||||
m_materials[mat_name].specular[i] =
|
m_materials[mat_name].specular[i] =
|
||||||
atof(tokens[i + 1].c_str());
|
atof(tokens[i + 1].c_str());
|
||||||
m_materials[mat_name].specular[3] = 1.0;
|
m_materials[mat_name].specular[3] = 1.0;
|
||||||
m_materials[mat_name].flags |= Material::MAT_SPECULAR;
|
m_materials[mat_name].flags |= Material::SPECULAR_BIT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cerr << "WFObj: error: 'Ks' material directive requires"
|
cerr << "WFObj: error: 'Ks' material directive requires"
|
||||||
@ -567,32 +567,13 @@ void WFObj::draw()
|
|||||||
it != m_faces.end();
|
it != m_faces.end();
|
||||||
it++)
|
it++)
|
||||||
{
|
{
|
||||||
glPushAttrib(GL_LIGHTING_BIT);
|
|
||||||
renderMaterial(m_materials[it->first]);
|
|
||||||
glDrawElements(GL_TRIANGLES, m_face_indices[it->first].second,
|
glDrawElements(GL_TRIANGLES, m_face_indices[it->first].second,
|
||||||
GL_UNSIGNED_SHORT,
|
GL_UNSIGNED_SHORT,
|
||||||
(GLvoid *) (sizeof(GLshort) * m_face_indices[it->first].first));
|
(GLvoid *) (sizeof(GLshort) * m_face_indices[it->first].first));
|
||||||
glPopAttrib();
|
|
||||||
}
|
}
|
||||||
glPopClientAttrib();
|
glPopClientAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WFObj::renderMaterial(const WFObj::Material & m)
|
|
||||||
{
|
|
||||||
if (m.flags & Material::MAT_SHININESS)
|
|
||||||
glMaterialf(GL_FRONT, GL_SHININESS, m.shininess);
|
|
||||||
if (m.flags & Material::MAT_AMBIENT)
|
|
||||||
glMaterialfv(GL_FRONT, GL_AMBIENT, &m.ambient[0]);
|
|
||||||
if (m.flags & Material::MAT_DIFFUSE)
|
|
||||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, &m.diffuse[0]);
|
|
||||||
if (m.flags & Material::MAT_SPECULAR)
|
|
||||||
glMaterialfv(GL_FRONT, GL_SPECULAR, &m.specular[0]);
|
|
||||||
if (m.flags & Material::MAT_TEXTURE)
|
|
||||||
{
|
|
||||||
cerr << "WFObj: error: textured materials not implemented yet" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WFObj::VertexRef::operator<(const VertexRef & other) const
|
bool WFObj::VertexRef::operator<(const VertexRef & other) const
|
||||||
{
|
{
|
||||||
if (vertex != other.vertex)
|
if (vertex != other.vertex)
|
||||||
|
39
WFObj.h
39
WFObj.h
@ -28,6 +28,25 @@ public:
|
|||||||
bool m_alloc;
|
bool m_alloc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Material
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum {
|
||||||
|
SHININESS_BIT = 0x01,
|
||||||
|
AMBIENT_BIT = 0x02,
|
||||||
|
DIFFUSE_BIT = 0x04,
|
||||||
|
SPECULAR_BIT = 0x08,
|
||||||
|
TEXTURE_BIT = 0x10
|
||||||
|
};
|
||||||
|
Material() : flags(0) {}
|
||||||
|
GLfloat shininess;
|
||||||
|
GLfloat ambient[4];
|
||||||
|
GLfloat diffuse[4];
|
||||||
|
GLfloat specular[4];
|
||||||
|
std::string texture;
|
||||||
|
int flags;
|
||||||
|
};
|
||||||
|
|
||||||
typedef bool (*loadfile_t)(const char *fname, Buffer & buff);
|
typedef bool (*loadfile_t)(const char *fname, Buffer & buff);
|
||||||
typedef GLuint (*loadtexture_t)(const char *fname);
|
typedef GLuint (*loadtexture_t)(const char *fname);
|
||||||
|
|
||||||
@ -71,25 +90,6 @@ protected:
|
|||||||
VertexRef vertices[3];
|
VertexRef vertices[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
class Material
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum {
|
|
||||||
MAT_SHININESS = 0x01,
|
|
||||||
MAT_AMBIENT = 0x02,
|
|
||||||
MAT_DIFFUSE = 0x04,
|
|
||||||
MAT_SPECULAR = 0x08,
|
|
||||||
MAT_TEXTURE = 0x10
|
|
||||||
};
|
|
||||||
Material() : flags(0) {}
|
|
||||||
GLfloat shininess;
|
|
||||||
GLfloat ambient[4];
|
|
||||||
GLfloat diffuse[4];
|
|
||||||
GLfloat specular[4];
|
|
||||||
std::string texture;
|
|
||||||
int flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* methods */
|
/* methods */
|
||||||
void clear();
|
void clear();
|
||||||
void processInputLine(const std::string & input);
|
void processInputLine(const std::string & input);
|
||||||
@ -101,7 +101,6 @@ protected:
|
|||||||
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
|
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
|
||||||
void loadMaterial(const std::string & name);
|
void loadMaterial(const std::string & name);
|
||||||
bool buildVBO();
|
bool buildVBO();
|
||||||
void renderMaterial(const Material & m);
|
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
std::vector<Vertex> m_vertices[VERTEX_TYPES];
|
std::vector<Vertex> m_vertices[VERTEX_TYPES];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user