changeset 8:628c42e94149

Clean up variable names.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 27 Oct 2019 22:24:43 +0200
parents 95dd5417e7de
children 87cb16492d91
files glxdragon.cpp
diffstat 1 files changed, 25 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/glxdragon.cpp	Sun Oct 27 22:20:17 2019 +0200
+++ b/glxdragon.cpp	Sun Oct 27 22:24:43 2019 +0200
@@ -44,9 +44,9 @@
 #define SET_FRAMES (180 * 2)
 
 
-bool opt_shaders = false;
-SDL_Window *sdl_window = NULL;
-SDL_GLContext sdl_glctx = NULL;
+bool optUseShaders = false;
+SDL_Window *dmWindow = NULL;
+SDL_GLContext dmGLContext = NULL;
 
 
 struct Mesh
@@ -79,7 +79,7 @@
     }
 
     // Attempt to create a window
-    if ((sdl_window = SDL_CreateWindow(title,
+    if ((dmWindow = SDL_CreateWindow(title,
             SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
             width, height,
             SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)) == NULL)
@@ -89,7 +89,7 @@
         return false;
     }
 
-    if ((sdl_glctx = SDL_GL_CreateContext(sdl_window)) == NULL)
+    if ((dmGLContext = SDL_GL_CreateContext(dmWindow)) == NULL)
     {
         printf("ERROR: Unable to create SDL OpenGL context: %s\n",
             SDL_GetError());
@@ -202,7 +202,7 @@
     glEnable(GL_DEPTH_TEST);
 
     // Render the model
-    if (opt_shaders)
+    if (optUseShaders)
     {
         // Enable shader program
         glUseProgram(mesh.id_prog);
@@ -258,7 +258,7 @@
     mesh.nfaces = nfaces;
     mesh.faces.resize(mesh.nfaces * 3);
 
-    for (int i = 0; i < nfaces; i++)
+    for (int i = 0; i < mesh.nfaces; i++)
     {
         in.seekg(1, std::ios::cur);
         in.read(reinterpret_cast<char*>(&mesh.faces[i * 3]), 3 * 4);
@@ -268,7 +268,7 @@
 }
 
 
-GLuint dmSetCompileShader(const GLenum stype, const std::string &src)
+GLuint dmCompileShader(const GLenum stype, const std::string &src)
 {
     GLuint shader = glCreateShader(stype);
     const char *tmp = src.c_str();
@@ -294,8 +294,8 @@
     struct Mesh dragonMesh;
     std::string dragonVS, dragonFS;
     std::clock_t startTime;
-    bool exitFlag = false, opt_showhelp = false;
-    int steps = 0;
+    bool exitFlag = false, optShowHelp = false;
+    int nframes = 0;
 
     // Check commandline argument for enabling shaders
 
@@ -304,14 +304,14 @@
         char *arg = argv[narg];
         if (strstr(arg, "help") != NULL ||
             strstr(arg, "?") != NULL)
-            opt_showhelp = true;
+            optShowHelp = true;
         else
         if (strstr(arg, "glsl") != NULL ||
             strstr(arg, "sha") != NULL)
-            opt_shaders = true;
+            optUseShaders = true;
     }
 
-    if (opt_showhelp)
+    if (optShowHelp)
     {
         printf(
             "Usage: %s [glsl]\n"
@@ -323,7 +323,7 @@
     if (!dmLoadMesh("dragon.mesh", dragonMesh, 100139, 200198))
         goto exit;
 
-    if (opt_shaders)
+    if (optUseShaders)
     {
         // Read shader files
         if (!dmReadText("dragon.frag", dragonFS) ||
@@ -336,10 +336,10 @@
         goto exit;
 
     // According to our mode ..
-    if (opt_shaders)
+    if (optUseShaders)
     {
-        dragonMesh.id_ps = dmSetCompileShader(GL_FRAGMENT_SHADER, dragonFS);
-        dragonMesh.id_vs = dmSetCompileShader(GL_VERTEX_SHADER, dragonVS);
+        dragonMesh.id_ps = dmCompileShader(GL_FRAGMENT_SHADER, dragonFS);
+        dragonMesh.id_vs = dmCompileShader(GL_VERTEX_SHADER, dragonVS);
         dmLinkMeshShaders(dragonMesh);
     }
     else
@@ -401,16 +401,16 @@
         dmPaintGL(dragonMesh);
 
         // Draw the current frame
-        SDL_GL_SwapWindow(sdl_window);
+        SDL_GL_SwapWindow(dmWindow);
 
         // Rotate for 2 degrees
         glRotatef(2.0f, 0, 1, 0);
 
         // Return true if a full rotation was done
-        if (steps++ == SET_FRAMES)
+        if (nframes++ == SET_FRAMES)
         {
-            // Reset steps
-            steps = 0;
+            // Reset nframes
+            nframes = 0;
 
             // Get the time it took to render a full turn
             double time = (double(std::clock() - startTime) * 1000.0f) / CLOCKS_PER_SEC;
@@ -425,11 +425,11 @@
     }
 
 exit:
-    if (sdl_glctx != NULL)
-        SDL_GL_DeleteContext(sdl_glctx);
+    if (dmGLContext != NULL)
+        SDL_GL_DeleteContext(dmGLContext);
 
-    if (sdl_window != NULL)
-        SDL_DestroyWindow(sdl_window);
+    if (dmWindow != NULL)
+        SDL_DestroyWindow(dmWindow);
 
     SDL_Quit();