Changeset bae0911 in opengl-game


Ignore:
Timestamp:
May 10, 2019, 9:09:49 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
caa2359
Parents:
155a7cf
Message:

Update logging code to send all errors to the log file as well as the console

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TODO.txt

    r155a7cf rbae0911  
    22==========
    33-Change the logger class to use cout instead of printf. Consider how easy variable argument support would be.
    4 -Change all error messages to use the logger class so they get printed to the log file as well.
     4 - What I really need to do is completely refactor the logger class to return an ofstream to the logger file
     5   and use streaming to send output to it. The log file can be closed in the destructor.
    56-Add code to allow for resizing/maximizing the window
    6 -Add logic to make imgui element placement depedent on the window size so it works in fullscreen
     7 - Doesn't seem to be necessary on OSX anymore, check that in works on Window and Linux, including removing
     8   the window title bar in fullscreen mode and bringing it back in windowed mode
    79-Check the book's "Printing Parameters from the GL Context" to output a bunch of OpenGL context params
    810-Move some common functions into a Utils class
     
    1315-Fix the texture-mapping code to not flip the texture upside down.
    1416-Make sure fullscreen works correctly on OSX. Check the book to see how to handle Retina Display.
     17-Change all error messages to use the logger class so they get printed to the log file as well.
    1518
    1619NEW TODO
  • logger.cpp

    r155a7cf rbae0911  
    55#include <cstdarg>
    66#include <iostream>
    7 
    8 using namespace std;
    97
    108bool restart_gl_log() {
     
    1513   }
    1614   time_t now = time(NULL);
    17    char* date = ctime(&now);
    18    fprintf(file, "GL_LOG_FILE log. local time %s\n", date);
     15   string date(ctime(&now));
     16   fprintf(file, "GL_LOG_FILE log. local time %s\n", date.c_str());
    1917   fclose(file);
    2018   return true;
    2119}
    2220
    23 bool gl_log(const char* message, ...) {
     21bool gl_log(const string message, ...) {
    2422   va_list argptr;
    2523   FILE* file = fopen(GL_LOG_FILE, "a");
     
    2826      return false;
    2927   }
    30    va_start(argptr, message);
    31    vfprintf(file, message, argptr);
     28   va_start(argptr, message.c_str());
     29   vfprintf(file, message.c_str(), argptr);
    3230   va_end(argptr);
    3331   fprintf(file, "\n");
     
    3634}
    3735
    38 bool gl_log_err(const char* message, ...) {
     36bool gl_log_err(const string message, ...) {
    3937   va_list argptr;
    4038   FILE* file = fopen(GL_LOG_FILE, "a");
     
    4341      return false;
    4442   }
    45    va_start(argptr, message);
    46    vfprintf(file, message, argptr);
     43   va_start(argptr, message.c_str());
     44   vfprintf(file, message.c_str(), argptr);
    4745   va_end(argptr);
    4846   fprintf(file, "\n");
    49    va_start(argptr, message);
    50    vfprintf(stderr, message, argptr);
     47   va_start(argptr, message.c_str());
     48   vfprintf(stderr, message.c_str(), argptr);
    5149   va_end(argptr);
    5250   fprintf(stderr, "\n");
  • logger.h

    r155a7cf rbae0911  
    11#ifndef LOGGER_H
    22#define LOGGER_H
     3
     4#include <string>
     5
     6using namespace std;
    37
    48#define GL_LOG_FILE "gl.log"
    59
    610bool restart_gl_log();
    7 bool gl_log(const char* message, ...);
    8 bool gl_log_err(const char* message, ...);
     11bool gl_log(const string message, ...);
     12bool gl_log_err(const string message, ...);
    913
    1014#endif
  • new-game.cpp

    r155a7cf rbae0911  
    301301   cout << "New OpenGL Game" << endl;
    302302
    303    if (!restart_gl_log()) {}
    304    gl_log("starting GLFW\n%s\n", glfwGetVersionString());
     303   restart_gl_log();
     304   gl_log("starting GLFW\n%s", glfwGetVersionString());
    305305
    306306   glfwSetErrorCallback(glfw_error_callback);
    307307   if (!glfwInit()) {
    308       cerr << "ERROR: could not start GLFW3" << endl;
     308      gl_log_err("ERROR: could not start GLFW3");
    309309      return 1;
    310310   }
     
    337337
    338338   if (!window) {
    339       cerr << "ERROR: could not open window with GLFW3" << endl;;
     339      gl_log_err("ERROR: could not open window with GLFW3");
    340340      glfwTerminate();
    341341      return 1;
     
    403403   const GLubyte* version = glGetString(GL_VERSION);
    404404   cout << "Renderer: " << renderer << endl;
    405    cout << "OpenGL version supported " << version << endl;
     405   cout << "Supported OpenGL version: " << version << endl;
     406
     407   gl_log("Renderer: %s", renderer);
     408   gl_log("Supported OpenGL version: %s", version);
    406409
    407410   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    976979
    977980void glfw_error_callback(int error, const char* description) {
    978    gl_log_err("GLFW ERROR: code %i msg: %s\n", error, description);
     981   gl_log_err("GLFW ERROR: code %i msg: %s", error, description);
    979982}
    980983
     
    12171220
    12181221  if (!image_data) {
    1219     cerr << "ERROR: could not load " << file_name << endl;
     1222    gl_log_err("ERROR: could not load %s", file_name.c_str());
    12201223  }
    12211224
    12221225  // Not Power-of-2 check
    12231226  if ((*x & (*x - 1)) != 0 || (*y & (*y - 1)) != 0) {
    1224      cerr << "WARNING: texture " << file_name << " is not power-of-2 dimensions" << endl;
     1227     gl_log_err("WARNING: texture %s is not power-of-2 dimensions", file_name.c_str());
    12251228  }
    12261229
Note: See TracChangeset for help on using the changeset viewer.