diff --git a/Main.cpp b/Main.cpp index cf53916..df1af15 100644 --- a/Main.cpp +++ b/Main.cpp @@ -151,14 +151,18 @@ void configureOpenGL() //Lighting GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; - GLfloat mat_shininess[] = { 50.0 }; - GLfloat light_position[] = { 30.0, 30.0, 30.0, 0.0 }; + GLfloat mat_shininess[] = { 20.0 }; + GLfloat light_position[] = { 30.0, 30.0, 30.0, 1.0 }; + GLfloat light_diffuse[] = { 2.0, 2.0, 2.0, 1.0 }; + GLfloat light_ambient[] = { 2.0, 2.0, 2.0, 1.0 }; glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); diff --git a/Model.cpp b/Model.cpp index 0adaa02..b25e3d4 100644 --- a/Model.cpp +++ b/Model.cpp @@ -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; } diff --git a/Model.h b/Model.h index 703e059..77ea091 100644 --- a/Model.h +++ b/Model.h @@ -35,6 +35,14 @@ private: std::string name; Texture* texture; bool hasTexture; + + bool hasDiffuse; + Vec3f diffuseColor; + bool hasAmbient; + Vec3f ambientColor; + bool hasSpecular; + Vec3f specularColor; + }; class ObjGroup diff --git a/models/ship/HANDVAT.png b/models/ship/HANDVAT.png new file mode 100644 index 0000000..b9b4eb5 Binary files /dev/null and b/models/ship/HANDVAT.png differ diff --git a/models/ship/TextureZwaard.mtl b/models/ship/TextureZwaard.mtl new file mode 100644 index 0000000..6328409 --- /dev/null +++ b/models/ship/TextureZwaard.mtl @@ -0,0 +1,134 @@ +newmtl initialShadingGroup +illum 4 +Kd 0.22 0.22 0.22 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert2SG +illum 4 +Kd 0.50 0.32 0.25 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert3SG +illum 4 +Kd 0.45 0.45 0.45 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert3SG +illum 4 +Kd 0.45 0.45 0.45 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert4SG1 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert4SG2 +illum 4 +Kd 0.00 0.00 0.00 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +map_Kd ZWAARD.png +Ni 1.00 +newmtl pasted__lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert5SG1 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert5SG2 +illum 4 +Kd 0.00 0.00 0.00 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +map_Kd HANDVAT.png +Ni 1.00 +newmtl pasted__pasted__lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert4SG1 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert4SG2 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert4SG3 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG1 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG2 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG3 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__pasted__lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__pasted__lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 diff --git a/models/ship/ZWAARD.png b/models/ship/ZWAARD.png new file mode 100644 index 0000000..6c7467e Binary files /dev/null and b/models/ship/ZWAARD.png differ diff --git a/models/ship/Zwaard.mtl b/models/ship/Zwaard.mtl new file mode 100644 index 0000000..6328409 --- /dev/null +++ b/models/ship/Zwaard.mtl @@ -0,0 +1,134 @@ +newmtl initialShadingGroup +illum 4 +Kd 0.22 0.22 0.22 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert2SG +illum 4 +Kd 0.50 0.32 0.25 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert3SG +illum 4 +Kd 0.45 0.45 0.45 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert3SG +illum 4 +Kd 0.45 0.45 0.45 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert4SG1 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert4SG2 +illum 4 +Kd 0.00 0.00 0.00 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +map_Kd ZWAARD.png +Ni 1.00 +newmtl pasted__lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert5SG1 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__lambert5SG2 +illum 4 +Kd 0.00 0.00 0.00 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +map_Kd HANDVAT.png +Ni 1.00 +newmtl pasted__pasted__lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert4SG1 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert4SG2 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert4SG3 +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG1 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG2 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__lambert5SG3 +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__pasted__lambert4SG +illum 4 +Kd 0.12 0.12 0.12 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00 +newmtl pasted__pasted__pasted__lambert5SG +illum 4 +Kd 0.10 0.05 0.02 +Ka 0.00 0.00 0.00 +Tf 1.00 1.00 1.00 +Ni 1.00