add renderMaterial(), call glDrawElements()
This commit is contained in:
parent
aafacfb3f9
commit
f3d9a3b437
@ -22,6 +22,7 @@ private:
|
||||
void initgl();
|
||||
void display();
|
||||
void setProjection();
|
||||
void renderMaterial(const WFObj::Material & m);
|
||||
|
||||
WFObj m_obj;
|
||||
GLuint m_list;
|
||||
@ -127,6 +128,15 @@ void Viewer::display()
|
||||
glTexCoordPointer(2, GL_FLOAT, stride,
|
||||
(GLvoid *) m_obj.getTextureCoordOffset());
|
||||
}
|
||||
for (map<string, WFObj::Material>::iterator it = m_obj.getMaterials().begin();
|
||||
it != m_obj.getMaterials().end();
|
||||
it++)
|
||||
{
|
||||
renderMaterial(it->second);
|
||||
glDrawElements(GL_TRIANGLES, it->second.num_vertices,
|
||||
GL_UNSIGNED_SHORT,
|
||||
(GLvoid *) (sizeof(GLushort) * it->second.first_vertex));
|
||||
}
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
@ -195,3 +205,19 @@ void Viewer::run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::renderMaterial(const WFObj::Material & m)
|
||||
{
|
||||
if (m.flags & WFObj::Material::SHININESS_BIT)
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, m.shininess);
|
||||
if (m.flags & WFObj::Material::AMBIENT_BIT)
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, &m.ambient[0]);
|
||||
if (m.flags & WFObj::Material::DIFFUSE_BIT)
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, &m.diffuse[0]);
|
||||
if (m.flags & WFObj::Material::SPECULAR_BIT)
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, &m.specular[0]);
|
||||
if (m.flags & WFObj::Material::TEXTURE_BIT)
|
||||
{
|
||||
cerr << "error: textured materials not implemented yet" << endl;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user