changeset 17:0fa9302e324d

Cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Nov 2019 10:48:22 +0200
parents c134a186912f
children b1e75c65016d
files glxdragon.cpp
diffstat 1 files changed, 24 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- 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);