# HG changeset patch # User Matti Hamalainen # Date 1572943702 -7200 # Node ID 0fa9302e324d3d1bc13f70c84553593cd5fb0b2b # Parent c134a186912fe214cc32d96c3e8418556f470fe0 Cleanup. diff -r c134a186912f -r 0fa9302e324d glxdragon.cpp --- a/glxdragon.cpp Tue Nov 05 09:06:12 2019 +0200 +++ b/glxdragon.cpp Tue Nov 05 10:48:22 2019 +0200 @@ -199,6 +199,19 @@ { int maxIndices; + if (optUseShaders) + { + // Enable shader program + glUseProgram(mesh.id_prog); + } + else + { + // Set the color of the model + glEnable(GL_LIGHTING); + glColor3ub(0x90, 0x80, 0x90); + } + + // Render the model glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices); glVertexPointer(3, GL_FLOAT, 3 * 4 * 2, &mesh.vertices[0]); @@ -209,10 +222,16 @@ const int count = std::min(maxIndices, mesh.nfaces - n); glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_INT, &mesh.faces[n * 3]); } + + // Restore + if (optUseShaders) + { + glUseProgram(0); + } } -void dmPaintGL(Mesh &mesh) +void dmDrawBackground() { glClear(GL_DEPTH_BUFFER_BIT); @@ -226,11 +245,9 @@ glPushMatrix(); glLoadIdentity(); - + // Draw the background gradient glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); - - // Draw the background gradient glBegin(GL_QUADS); { glColor3ub(0x3B, 0x3B, 0x75); @@ -252,22 +269,6 @@ glPopMatrix(); glEnable(GL_DEPTH_TEST); - - // Render the model - if (optUseShaders) - { - // Enable shader program - glUseProgram(mesh.id_prog); - dmDrawModelVA(mesh); - glUseProgram(0); - } - else - { - // Set the color of the model - glEnable(GL_LIGHTING); - glColor3ub(0x90, 0x80, 0x90); - dmDrawModelVA(mesh); - } } @@ -417,7 +418,7 @@ int main(int argc, char *argv[]) { std::string modelVertStr, modelFragStr; - struct Mesh modelMesh; + Mesh modelMesh; bool exitFlag = false, optShowHelp = false; int startTime, cycleStart, cycleFrames = 0, totalFrames = 0; double totalTime; @@ -582,7 +583,8 @@ } // Render the next frame - dmPaintGL(modelMesh); + dmDrawBackground(); + dmDrawModelVA(modelMesh); // Draw the current frame SDL_GL_SwapWindow(dmWindow);