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++)
|
for (int i = 0; i < 3; i++)
|
||||||
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].flags |= Material::MAT_AMBIENT;
|
m_materials[mat_name].flags |= Material::MAT_AMBIENT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -392,6 +393,7 @@ void WFObj::loadMaterial(const std::string & name)
|
|||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
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].flags |= Material::MAT_DIFFUSE;
|
m_materials[mat_name].flags |= Material::MAT_DIFFUSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -405,6 +407,7 @@ void WFObj::loadMaterial(const std::string & name)
|
|||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
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].flags |= Material::MAT_SPECULAR;
|
m_materials[mat_name].flags |= Material::MAT_SPECULAR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -542,6 +545,36 @@ bool WFObj::buildVBO()
|
|||||||
return true;
|
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
|
bool WFObj::VertexRef::operator<(const VertexRef & other) const
|
||||||
{
|
{
|
||||||
if (vertex != other.vertex)
|
if (vertex != other.vertex)
|
||||||
|
10
WFObj.h
10
WFObj.h
@ -41,6 +41,7 @@ public:
|
|||||||
bool load(const char *fname);
|
bool load(const char *fname);
|
||||||
bool load(const Buffer &buff);
|
bool load(const Buffer &buff);
|
||||||
const float * const getAABB() { return m_aabb; }
|
const float * const getAABB() { return m_aabb; }
|
||||||
|
void draw();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* types */
|
/* types */
|
||||||
@ -81,10 +82,10 @@ protected:
|
|||||||
MAT_TEXTURE = 0x10
|
MAT_TEXTURE = 0x10
|
||||||
};
|
};
|
||||||
Material() : flags(0) {}
|
Material() : flags(0) {}
|
||||||
float shininess;
|
GLfloat shininess;
|
||||||
float ambient[3];
|
GLfloat ambient[4];
|
||||||
float diffuse[3];
|
GLfloat diffuse[4];
|
||||||
float specular[3];
|
GLfloat specular[4];
|
||||||
std::string texture;
|
std::string texture;
|
||||||
int flags;
|
int flags;
|
||||||
};
|
};
|
||||||
@ -100,6 +101,7 @@ 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