add draw() and renderMaterial()
This commit is contained in:
parent
fea2100741
commit
53d4bebbc2
33
WFObj.cc
33
WFObj.cc
@ -379,6 +379,7 @@ void WFObj::loadMaterial(const std::string & name)
|
||||
for (int i = 0; i < 3; i++)
|
||||
m_materials[mat_name].ambient[i] =
|
||||
atof(tokens[i + 1].c_str());
|
||||
m_materials[mat_name].ambient[3] = 1.0;
|
||||
m_materials[mat_name].flags |= Material::MAT_AMBIENT;
|
||||
}
|
||||
else
|
||||
@ -392,6 +393,7 @@ void WFObj::loadMaterial(const std::string & name)
|
||||
for (int i = 0; i < 3; i++)
|
||||
m_materials[mat_name].diffuse[i] =
|
||||
atof(tokens[i + 1].c_str());
|
||||
m_materials[mat_name].diffuse[3] = 1.0;
|
||||
m_materials[mat_name].flags |= Material::MAT_DIFFUSE;
|
||||
}
|
||||
else
|
||||
@ -405,6 +407,7 @@ void WFObj::loadMaterial(const std::string & name)
|
||||
for (int i = 0; i < 3; i++)
|
||||
m_materials[mat_name].specular[i] =
|
||||
atof(tokens[i + 1].c_str());
|
||||
m_materials[mat_name].specular[3] = 1.0;
|
||||
m_materials[mat_name].flags |= Material::MAT_SPECULAR;
|
||||
}
|
||||
else
|
||||
@ -542,6 +545,36 @@ bool WFObj::buildVBO()
|
||||
return true;
|
||||
}
|
||||
|
||||
void WFObj::draw()
|
||||
{
|
||||
if (!m_valid)
|
||||
return;
|
||||
for (map<string, vector<Face> >::iterator it = m_faces.begin();
|
||||
it != m_faces.end();
|
||||
it++)
|
||||
{
|
||||
glPushAttrib(GL_LIGHTING_BIT);
|
||||
renderMaterial(m_materials[it->first]);
|
||||
glPopAttrib();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if (vertex != other.vertex)
|
||||
|
10
WFObj.h
10
WFObj.h
@ -41,6 +41,7 @@ public:
|
||||
bool load(const char *fname);
|
||||
bool load(const Buffer &buff);
|
||||
const float * const getAABB() { return m_aabb; }
|
||||
void draw();
|
||||
|
||||
protected:
|
||||
/* types */
|
||||
@ -81,10 +82,10 @@ protected:
|
||||
MAT_TEXTURE = 0x10
|
||||
};
|
||||
Material() : flags(0) {}
|
||||
float shininess;
|
||||
float ambient[3];
|
||||
float diffuse[3];
|
||||
float specular[3];
|
||||
GLfloat shininess;
|
||||
GLfloat ambient[4];
|
||||
GLfloat diffuse[4];
|
||||
GLfloat specular[4];
|
||||
std::string texture;
|
||||
int flags;
|
||||
};
|
||||
@ -100,6 +101,7 @@ protected:
|
||||
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
|
||||
void loadMaterial(const std::string & name);
|
||||
bool buildVBO();
|
||||
void renderMaterial(const Material & m);
|
||||
|
||||
/* variables */
|
||||
std::vector<Vertex> m_vertices[VERTEX_TYPES];
|
||||
|
Loading…
x
Reference in New Issue
Block a user