|
|
@@ -129,6 +129,28 @@ void Model::draw()
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
materials[g->materialIndex]->texture->bind();
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ glDisable(GL_TEXTURE_2D);
|
|
|
+
|
|
|
+ float color[4] = { 1, 0, 0, 1 };
|
|
|
+
|
|
|
+ if (materials[g->materialIndex]->hasDiffuse)
|
|
|
+ {
|
|
|
+ memcpy(color, materials[g->materialIndex]->diffuseColor.v, 3 * sizeof(float));
|
|
|
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
|
|
|
+ }
|
|
|
+ else if (materials[g->materialIndex]->hasAmbient)
|
|
|
+ {
|
|
|
+ memcpy(color, materials[g->materialIndex]->ambientColor.v, 3 * sizeof(float));
|
|
|
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
|
|
|
+ }
|
|
|
+ else if (materials[g->materialIndex]->hasSpecular)
|
|
|
+ {
|
|
|
+ memcpy(color, materials[g->materialIndex]->specularColor.v, 3 * sizeof(float));
|
|
|
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
for (auto &f : g->faces)
|
|
|
@@ -193,6 +215,21 @@ 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->hasDiffuse = true;
|
|
|
+ currentMaterial->diffuseColor = Vec3f(atof(params[1].c_str()), atof(params[2].c_str()), atof(params[3].c_str()));
|
|
|
+ }
|
|
|
+ else if (params[0] == "ka")
|
|
|
+ {
|
|
|
+ currentMaterial->hasAmbient = true;
|
|
|
+ currentMaterial->ambientColor = Vec3f(atof(params[1].c_str()), atof(params[2].c_str()), atof(params[3].c_str()));
|
|
|
+ }
|
|
|
+ else if (params[0] == "ks")
|
|
|
+ {
|
|
|
+ currentMaterial->hasSpecular = true;
|
|
|
+ currentMaterial->specularColor = 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;
|
|
|
}
|