From 509e94ac58cffe93357ef6764f1f835f8adf9f8b Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Thu, 3 Aug 2023 13:55:58 +0500 Subject: [PATCH] Iterators now use size_t, light parameters changed --- src/obj.cpp | 6 ++++-- src/opglwidget.cpp | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/obj.cpp b/src/obj.cpp index 62832b2..70abe15 100644 --- a/src/obj.cpp +++ b/src/obj.cpp @@ -86,9 +86,11 @@ void ObjectLoader::load_obj(string filename) { }; Material* ObjectLoader::get_mtl_ptr(string mtl_name) { - for (int i = 0; i < mtls.size(); i++) { + for (size_t i = 0; i < mtls.size(); i++) { if (mtls[i].name == mtl_name) { return &(mtls[i]); }; }; -}; +} + + diff --git a/src/opglwidget.cpp b/src/opglwidget.cpp index 23731be..a3a2ab4 100644 --- a/src/opglwidget.cpp +++ b/src/opglwidget.cpp @@ -14,11 +14,13 @@ void OPGLWidget::initializeGL() { glMatrixMode(GL_MODELVIEW); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); - GLfloat light_array[] = {0.4, 0.4, 0.4, 0.4}; - GLfloat light_position[] = {10.0, 20.0, 10.0, 1.0}; - glLightfv(GL_LIGHT0, GL_AMBIENT, light_array); - glLightfv(GL_LIGHT0, GL_DIFFUSE, light_array); - glLightfv(GL_LIGHT0, GL_SPECULAR, light_array); + GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0}; + GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; + GLfloat light_specular[] = {0.0, 0.5, 0.5, 0.2}; + GLfloat light_position[] = {4.0, 1.0, 6.0, 1.0}; + glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); } @@ -27,9 +29,10 @@ void OPGLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); reorient(); + glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT, GL_FILL); glBegin(GL_TRIANGLES); - for (int i = 0; i < obj.faces.size(); i++) { + for (size_t i = 0; i < obj.faces.size(); i++) { Material* mtl_ptr = obj.faces[i].mtl; if (mtl_idx != mtl_ptr->idx) { glMaterialfv(GL_FRONT, GL_AMBIENT, mtl_ptr -> ambient);