From c90405563297024bd4dd569423e3b8a40bd3afbc Mon Sep 17 00:00:00 2001 From: Archie Hilton Date: Sun, 26 May 2024 19:53:26 +0100 Subject: [PATCH] debug: Use a real logging library --- CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + src/Quad.cc | 6 ++---- src/main.cc | 24 +++++++++++++++--------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9646bb8..7d3366c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD 20) #set(CMAKE_BUILD_TYPE Debug) find_package(PNG REQUIRED) +find_package(spdlog REQUIRED) add_subdirectory(glfw) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index afe8f23..30a6531 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ add_executable(Exponent ) target_link_libraries(Exponent PUBLIC glfw glm::glm ${PNG_LIBRARY}) +target_link_libraries(Exponent PRIVATE spdlog::spdlog) target_include_directories(Exponent PUBLIC ${CMAKE_SOURCE_DIR}/include ${PNG_INCLUDE_DIR}) diff --git a/src/Quad.cc b/src/Quad.cc index 2cd9a37..c979db4 100644 --- a/src/Quad.cc +++ b/src/Quad.cc @@ -15,7 +15,7 @@ #include #include -#include +#include Quad::Quad(std::span verts, const Uniform &uniform_data) : m_mesh(verts) { @@ -30,7 +30,7 @@ Quad::Quad(std::span verts, const Uniform &uniform_data) png_const_bytep header[8] = {0}; if (fp == NULL) { - std::cerr << "Couldn't find file!" << std::endl; + spdlog::error("Can't find texture file!"); throw std::exception(); } @@ -70,8 +70,6 @@ Quad::Quad(std::span verts, const Uniform &uniform_data) png_destroy_read_struct(&png_ptr, &info_ptr, NULL); fclose(fp); - std::cout << color_type << std::endl; - glGenTextures(1, &tex_id); glBindTexture(GL_TEXTURE_2D, tex_id); diff --git a/src/main.cc b/src/main.cc index 042086d..53d15a6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -14,6 +15,9 @@ #include +#include +#include + // This has to come last. #define GLAD_GL_IMPLEMENTATION #include @@ -24,15 +28,15 @@ static std::vector quads = {}; -static void dbg_log(const char *str) { std::cout << str << std::endl; } - void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { - fprintf(stderr, - "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = \n\t%s\n", - (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, - message); + // TODO: Dedupe + if (type == GL_DEBUG_TYPE_ERROR) { + spdlog::error("GL TYPE {:x} SEV {:x}: {}", type, severity, message); + } else { + spdlog::trace("GL TYPE {:x} SEV {:x}: {}", type, severity, message); + } } static void key_callback(GLFWwindow *w, int key, int scancode, int action, @@ -63,7 +67,7 @@ void framebuffer_size_callback(GLFWwindow *window, int width, int height) { } static void init_shaders() { - dbg_log("Initialising shaders"); + spdlog::trace("Enter shader init"); const std::vector> shaders = { {GL_VERTEX_SHADER, VERTEX_SHADER_LOCATION}, @@ -102,7 +106,7 @@ static std::array verts({ // Do the work of initialising opengl so we can draw stuff static void init_opengl() { - dbg_log("Initialising opengl"); + spdlog::trace("Initialising opengl"); // During init, enable debug output glEnable(GL_DEBUG_OUTPUT); @@ -120,7 +124,9 @@ static void init_opengl() { } int main() { - dbg_log("Initialising glfw"); + spdlog::default_logger()->set_level(spdlog::level::info); + + spdlog::trace("Initialising glfw"); // Initialise GLFW if (!glfwInit()) { exit(EXIT_FAILURE);