debug: Use a real logging library

This commit is contained in:
Archie Hilton 2024-05-26 19:53:26 +01:00
parent 3584b4c861
commit c904055632
4 changed files with 19 additions and 13 deletions

View File

@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD 20)
#set(CMAKE_BUILD_TYPE Debug) #set(CMAKE_BUILD_TYPE Debug)
find_package(PNG REQUIRED) find_package(PNG REQUIRED)
find_package(spdlog REQUIRED)
add_subdirectory(glfw) add_subdirectory(glfw)
add_subdirectory(src) add_subdirectory(src)

View File

@ -6,6 +6,7 @@ add_executable(Exponent
) )
target_link_libraries(Exponent PUBLIC glfw glm::glm ${PNG_LIBRARY}) 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 target_include_directories(Exponent PUBLIC ${CMAKE_SOURCE_DIR}/include
${PNG_INCLUDE_DIR}) ${PNG_INCLUDE_DIR})

View File

@ -15,7 +15,7 @@
#include <pngconf.h> #include <pngconf.h>
#include <string.h> #include <string.h>
#include <iostream> #include <spdlog/spdlog.h>
Quad::Quad(std::span<float> verts, const Uniform &uniform_data) Quad::Quad(std::span<float> verts, const Uniform &uniform_data)
: m_mesh(verts) { : m_mesh(verts) {
@ -30,7 +30,7 @@ Quad::Quad(std::span<float> verts, const Uniform &uniform_data)
png_const_bytep header[8] = {0}; png_const_bytep header[8] = {0};
if (fp == NULL) { if (fp == NULL) {
std::cerr << "Couldn't find file!" << std::endl; spdlog::error("Can't find texture file!");
throw std::exception(); throw std::exception();
} }
@ -70,8 +70,6 @@ Quad::Quad(std::span<float> verts, const Uniform &uniform_data)
png_destroy_read_struct(&png_ptr, &info_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp); fclose(fp);
std::cout << color_type << std::endl;
glGenTextures(1, &tex_id); glGenTextures(1, &tex_id);
glBindTexture(GL_TEXTURE_2D, tex_id); glBindTexture(GL_TEXTURE_2D, tex_id);

View File

@ -6,6 +6,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <spdlog/common.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -14,6 +15,9 @@
#include <array> #include <array>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
// This has to come last. // This has to come last.
#define GLAD_GL_IMPLEMENTATION #define GLAD_GL_IMPLEMENTATION
#include <glad/gl.h> #include <glad/gl.h>
@ -24,15 +28,15 @@
static std::vector<Quad *> quads = {}; static std::vector<Quad *> quads = {};
static void dbg_log(const char *str) { std::cout << str << std::endl; }
void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length, GLenum severity, GLsizei length,
const GLchar *message, const void *userParam) { const GLchar *message, const void *userParam) {
fprintf(stderr, // TODO: Dedupe
"GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = \n\t%s\n", if (type == GL_DEBUG_TYPE_ERROR) {
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, spdlog::error("GL TYPE {:x} SEV {:x}: {}", type, severity, message);
message); } else {
spdlog::trace("GL TYPE {:x} SEV {:x}: {}", type, severity, message);
}
} }
static void key_callback(GLFWwindow *w, int key, int scancode, int action, 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() { static void init_shaders() {
dbg_log("Initialising shaders"); spdlog::trace("Enter shader init");
const std::vector<std::pair<GLuint, std::string>> shaders = { const std::vector<std::pair<GLuint, std::string>> shaders = {
{GL_VERTEX_SHADER, VERTEX_SHADER_LOCATION}, {GL_VERTEX_SHADER, VERTEX_SHADER_LOCATION},
@ -102,7 +106,7 @@ static std::array<float, 7 * 6> verts({
// Do the work of initialising opengl so we can draw stuff // Do the work of initialising opengl so we can draw stuff
static void init_opengl() { static void init_opengl() {
dbg_log("Initialising opengl"); spdlog::trace("Initialising opengl");
// During init, enable debug output // During init, enable debug output
glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT);
@ -120,7 +124,9 @@ static void init_opengl() {
} }
int main() { int main() {
dbg_log("Initialising glfw"); spdlog::default_logger()->set_level(spdlog::level::info);
spdlog::trace("Initialising glfw");
// Initialise GLFW // Initialise GLFW
if (!glfwInit()) { if (!glfwInit()) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);