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)
find_package(PNG REQUIRED)
find_package(spdlog REQUIRED)
add_subdirectory(glfw)
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 PRIVATE spdlog::spdlog)
target_include_directories(Exponent PUBLIC ${CMAKE_SOURCE_DIR}/include
${PNG_INCLUDE_DIR})

View File

@ -15,7 +15,7 @@
#include <pngconf.h>
#include <string.h>
#include <iostream>
#include <spdlog/spdlog.h>
Quad::Quad(std::span<float> verts, const Uniform &uniform_data)
: m_mesh(verts) {
@ -30,7 +30,7 @@ Quad::Quad(std::span<float> 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<float> 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);

View File

@ -6,6 +6,7 @@
#include <fstream>
#include <iostream>
#include <spdlog/common.h>
#include <sstream>
#include <string>
#include <vector>
@ -14,6 +15,9 @@
#include <array>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
// This has to come last.
#define GLAD_GL_IMPLEMENTATION
#include <glad/gl.h>
@ -24,15 +28,15 @@
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,
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<std::pair<GLuint, std::string>> shaders = {
{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
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);