# HG changeset patch # User Matti Hamalainen # Date 1575237139 -7200 # Node ID 73a785323e8ade40e3a2f19f2384ffc248119f2d # Parent d640f2a34031e8fa68ff598bce176b107821c262 Rendering cleanups. diff -r d640f2a34031 -r 73a785323e8a dmmodel.h --- a/dmmodel.h Sun Dec 01 23:12:04 2019 +0200 +++ b/dmmodel.h Sun Dec 01 23:52:19 2019 +0200 @@ -176,6 +176,7 @@ scale.x = scale.y = scale.z = 0; translateSet = rotateSet = scaleSet = false; + diffuse.p.x = diffuse.p.z = 0.56471f; diffuse.p.y = 0.5f; diffuse.p.w = 1.0f; specular.p.x = specular.p.y = specular.p.z = 0.8f; specular.p.w = 1.0f; shininess = 96; } diff -r d640f2a34031 -r 73a785323e8a gldragon.cpp --- a/gldragon.cpp Sun Dec 01 23:12:04 2019 +0200 +++ b/gldragon.cpp Sun Dec 01 23:52:19 2019 +0200 @@ -162,14 +162,23 @@ } -void dmDrawModel(const DMModel &model) +void dmDrawModel(const DMSimpleScene &scene, const DMModel &model) { int maxIndices; + if (optUseShaders) + { + // Enable shader program + glUseProgram(model.id_prog); + glUniform1i(glGetUniformLocation(model.id_prog, "nlights"), scene.lights.size()); + } + + // Set the material of the model glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMateriali(GL_FRONT, GL_SHININESS, model.shininess); glMaterialfv(GL_FRONT, GL_SPECULAR, model.specular.values); + glColor4fv(model.diffuse.values); // Render the model glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices); @@ -196,6 +205,12 @@ const int count = std::min(maxIndices, model.nfaces - n); glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_INT, &model.faces[n * 3]); } + + // Restore + if (optUseShaders) + { + glUseProgram(0); + } } @@ -228,7 +243,6 @@ } glEnd(); - // Restore the 3D projection glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -237,32 +251,14 @@ glPopMatrix(); glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); // Draw models for (const DMModel &model : scene.models) { - if (optUseShaders) - { - // Enable shader program - glUseProgram(model.id_prog); - glUniform1i(glGetUniformLocation(model.id_prog, "nlights"), scene.lights.size()); - } - else - { - // Set the color of the model - glEnable(GL_LIGHTING); - glColor3ub(0x90, 0x80, 0x90); - } - glPushMatrix(); - dmDrawModel(model); + dmDrawModel(scene, model); glPopMatrix(); - - // Restore - if (optUseShaders) - { - glUseProgram(0); - } } }