added diffuse / ambient obj parsing

This commit is contained in:
Jannick van Ballegooijen
2016-05-12 12:17:56 +02:00
parent 049fb28ffc
commit 11f07b154b
7 changed files with 289 additions and 1 deletions
+13
View File
@@ -129,6 +129,15 @@ void Model::draw()
glEnable(GL_TEXTURE_2D);
materials[g->materialIndex]->texture->bind();
}
else
{
glDisable(GL_TEXTURE_2D);
float color[4] = { 1, 0, 0, 1 };
memcpy(color, materials[g->materialIndex]->diffuseColor.v, 3 * sizeof(float));
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
}
glBegin(GL_TRIANGLES);
for (auto &f : g->faces)
@@ -193,6 +202,10 @@ void Model::loadMaterialFile(std::string fileName, std::string dirName)
currentMaterial->hasTexture = true;
currentMaterial->texture = new Texture(dirName + "/" + params[1]);
}
else if (params[0] == "kd")
{
currentMaterial->diffuseColor = Vec3f(atof(params[1].c_str()), atof(params[2].c_str()), atof(params[3].c_str()));
}
else
std::cout << "Didn't parse " << params[0] << " in material file" << std::endl;
}