diff gldragon.cpp @ 47:9909014498f0

Add helper functions dmError() and dmMsg() and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Dec 2019 23:52:45 +0200
parents 0c75c5f5c6b6
children 0ae1ff609626
line wrap: on
line diff
--- a/gldragon.cpp	Thu Dec 05 22:45:21 2019 +0200
+++ b/gldragon.cpp	Thu Dec 05 23:52:45 2019 +0200
@@ -54,7 +54,7 @@
     bool res = SDL_GL_ExtensionSupported(name.c_str());
     void *ptr = SDL_GL_GetProcAddress(name.c_str());
 
-    printf(" - Checking '%s' : %s : %p\n",
+    dmMsg(" - Checking '%s' : %s : %p\n",
         name.c_str(),
         res ? "YES" : "no",
         ptr);
@@ -110,7 +110,7 @@
     // Attempt to initialize libSDL
     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS) != 0)
     {
-        printf("ERROR: Unable to initialize SDL: %s\n",
+        dmError("Unable to initialize SDL: %s\n",
             SDL_GetError());
         return false;
     }
@@ -135,14 +135,14 @@
             width, height,
             SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)) == NULL)
     {
-        printf("ERROR: Could not create SDL window: %s",
+        dmError("Could not create SDL window: %s",
             SDL_GetError());
         return false;
     }
 
     if ((dmGLContext = SDL_GL_CreateContext(dmWindow)) == NULL)
     {
-        printf("ERROR: Unable to create SDL OpenGL context: %s\n",
+        dmError("Unable to create SDL OpenGL context: %s\n",
             SDL_GetError());
         return false;
     }
@@ -178,7 +178,7 @@
 
     if (ret != 0)
     {
-        printf("ERROR: Could not set vsync mode to %s.\n",
+        dmError("Could not set vsync mode to %s.\n",
             msg.c_str());
         return false;
     }
@@ -188,15 +188,10 @@
         return false;
 
     // Dump some information
-    printf(
-        "GL_VENDOR   : %s\n"
-        "GL_RENDERER : %s\n"
-        "GL_VERSION  : %s\n"
-        "VSync mode  : %s\n",
-        glGetString(GL_VENDOR),
-        glGetString(GL_RENDERER),
-        glGetString(GL_VERSION),
-        msg.c_str());
+    dmMsg("GL_VENDOR   : %s\n", glGetString(GL_VENDOR));
+    dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER));
+    dmMsg("GL_VERSION  : %s\n", glGetString(GL_VERSION));
+    dmMsg("VSync mode  : %s\n", msg.c_str());
 
     // Setup the window and view port
     glViewport(0, 0, width, height);
@@ -360,13 +355,13 @@
         {
             char *buf = new char[bufLen];
             glGetShaderInfoLog(shader, bufLen, NULL, buf);
-            printf("ERROR: Shader compliation error:\n%s\n",
+            dmError("Shader compliation error:\n%s\n",
                 buf);
             delete buf;
         }
         else
         {
-            printf("ERROR: Shader compilation error occured, but no error information got.\n");
+            dmError("Shader compilation error occured, but no error information got.\n");
         }
         return false;
     }
@@ -453,7 +448,7 @@
         {
             if (optSetInputFilename)
             {
-                printf("ERROR: Please specify only one scene file.\n");
+                dmError("Please specify only one scene file.\n");
                 goto exit;
             }
 
@@ -461,7 +456,7 @@
             optInputFilename = std::string(arg);
             if (optInputFilename.empty())
             {
-                printf("ERROR: Invalid input filename.\n");
+                dmError("Invalid input filename.\n");
                 goto exit;
             }
 
@@ -491,7 +486,7 @@
 
     if (optWidth < 100 || optWidth > 8192 || optHeight < 100 || optHeight > 8192)
     {
-        printf("ERROR: Invalid window width or height (%d x %d).\n",
+        dmError("Invalid window width or height (%d x %d).\n",
             optWidth, optHeight);
         goto exit;
     }
@@ -502,7 +497,7 @@
 
     if (scene.models.size() == 0)
     {
-        printf("ERROR: Scenefile '%s' contains no models.\n",
+        dmError("Scenefile '%s' contains no models.\n",
             optInputFilename.c_str());
         goto exit;
     }
@@ -514,11 +509,11 @@
         scene.lights.push_back(light);
     }
 
-    printf("INFO: Loading %ld model(s) ..\n",
+    dmMsg("Loading %ld model(s) ..\n",
         scene.models.size());
 
     basePath = dmGetPath(optInputFilename);
-    printf("INFO: Model base path '%s'\n", basePath.c_str());
+    dmMsg("Scene base path '%s'\n", basePath.c_str());
 
     for (DMModel &model : scene.models)
     {