Changeset 98f06d9 in opengl-game


Ignore:
Timestamp:
May 24, 2019, 8:01:34 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
a23fc08
Parents:
d9b6a1c
Message:

Add support for ofstream to logger.cpp

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rd9b6a1c r98f06d9  
    55
    66gl.log
     7game.log
    78crash.log
    89
  • TODO.txt

    rd9b6a1c r98f06d9  
    11TODO
    22==========
    3 -Change the logger class to use cout instead of printf. Consider how easy variable argument support would be.
    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.
    63-Add code to allow for resizing/maximizing the window
    74 - Doesn't seem to be necessary on OSX anymore, check that in works on Window and Linux, including removing
    85   the window title bar in fullscreen mode and bringing it back in windowed mode
     6 -Update the IMGUI code in a generic way to support this as well
    97-Check the book's "Printing Parameters from the GL Context" to output a bunch of OpenGL context params
    108-Move some common functions into a Utils class
     
    1614-Make sure fullscreen works correctly on OSX. Check the book to see how to handle Retina Display.
    1715-Change all error messages to use the logger class so they get printed to the log file as well.
     16-Change the logger class to use cout instead of printf. Consider how easy variable argument support would be.
     17 - What I really need to do is completely refactor the logger class to return an ofstream to the logger file
     18   and use streaming to send output to it. The log file can be closed in the destructor.
    1819
    1920NEW TODO
  • logger.cpp

    rd9b6a1c r98f06d9  
    5252   return true;
    5353}
     54
     55ofstream ofs;
     56
     57void open_log() {
     58   ofs.open(LOG_FILE, ios::out);
     59
     60   time_t now = time(NULL);
     61   string date(ctime(&now));
     62   ofs << "LOG_FILE log. local time " << date << endl;
     63}
     64
     65ofstream& get_log() {
     66   return ofs;
     67}
     68
     69void close_log() {
     70   ofs.close();
     71}
  • logger.h

    rd9b6a1c r98f06d9  
    33
    44#include <string>
     5#include <fstream>
    56
    67using namespace std;
    78
    89#define GL_LOG_FILE "gl.log"
     10#define LOG_FILE "game.log"
     11
     12extern ofstream ofs;
    913
    1014bool restart_gl_log();
     
    1216bool gl_log_err(const string message, ...);
    1317
     18void open_log();
     19ofstream& get_log();
     20void close_log();
     21
    1422#endif
  • new-game.cpp

    rd9b6a1c r98f06d9  
    346346   gl_log("starting GLFW\n%s", glfwGetVersionString());
    347347
     348   open_log();
     349   get_log() << "starting GLFW" << endl;
     350   get_log() << glfwGetVersionString() << endl;
     351
    348352   glfwSetErrorCallback(glfw_error_callback);
    349353   if (!glfwInit()) {
    350354      gl_log_err("ERROR: could not start GLFW3");
     355      cerr << "ERROR: could not start GLFW3" << endl;
     356      get_log() << "ERROR: could not start GLFW3" << endl;
    351357      return 1;
    352358   }
     
    380386   if (!window) {
    381387      gl_log_err("ERROR: could not open window with GLFW3");
     388      cerr << "ERROR: could not open window with GLFW3" << endl;
     389      get_log() << "ERROR: could not open window with GLFW3" << endl;
    382390      glfwTerminate();
    383391      return 1;
     
    449457   gl_log("Renderer: %s", renderer);
    450458   gl_log("Supported OpenGL version: %s", version);
     459
     460   get_log() << "Renderer: " << renderer << endl;
     461   get_log() << "Supported OpenGL version: " << version << endl;
    451462
    452463   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    10111022   glfwTerminate();
    10121023
     1024   close_log();
     1025
    10131026   // free memory
    10141027
     
    10341047void glfw_error_callback(int error, const char* description) {
    10351048   gl_log_err("GLFW ERROR: code %i msg: %s", error, description);
     1049   cerr << "GLFW ERROR: code " << error << " msg: " << description << endl;
     1050   get_log() << "GLFW ERROR: code " << error << " msg: " << description << endl;
    10361051}
    10371052
     
    12751290  if (!image_data) {
    12761291    gl_log_err("ERROR: could not load %s", file_name.c_str());
     1292    cerr << "ERROR: could not load " << file_name << endl;
     1293    get_log() << "ERROR: could not load " << file_name << endl;
    12771294  }
    12781295
     
    12801297  if ((*x & (*x - 1)) != 0 || (*y & (*y - 1)) != 0) {
    12811298     gl_log_err("WARNING: texture %s is not power-of-2 dimensions", file_name.c_str());
     1299     cerr << "WARNING: texture " << file_name << " is not power-of-2 dimensions" << endl;
     1300     get_log() << "WARNING: texture " << file_name << " is not power-of-2 dimensions" << endl;
    12821301  }
    12831302
Note: See TracChangeset for help on using the changeset viewer.