From b2164b76cf07743dd6b2207d23e041921c796b6b Mon Sep 17 00:00:00 2001 From: Shylie Date: Thu, 23 May 2024 21:33:15 -0400 Subject: [PATCH] Add some options for configuration --- CMakeLists.txt | 10 ++++++++++ include/glerminal.h | 9 ++------- source/glerminal-config.h.in | 26 ++++++++++++++++++++++++++ source/glerminal-private.h | 7 ++++--- source/glerminal.cpp | 6 +++--- 5 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 source/glerminal-config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 295149c..f1e28ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,18 @@ project(glerminal LANGUAGES C CXX ) +option(GLERMINAL_OPENGL_DEBUG_CONTEXT "" OFF) +set(GLERMINAL_GRID_WIDTH 40 CACHE STRING "") +set(GLERMINAL_GRID_HEIGHT 25 CACHE STRING "") +set(GLERMINAL_LAYER_COUNT 64 CACHE STRING "") +set(GLERMINAL_CELL_SCALE 4 CACHE STRING "") + +configure_file(source/glerminal-config.h.in glerminal-config.h @ONLY) + add_subdirectory(glfw) add_library(glerminal STATIC + ${CMAKE_CURRENT_BINARY_DIR}/glerminal-config.h include/glerminal.h source/glerminal-private.h @@ -26,6 +35,7 @@ set_target_properties(glerminal target_include_directories(glerminal PUBLIC include + ${CMAKE_CURRENT_BINARY_DIR} PRIVATE source ) diff --git a/include/glerminal.h b/include/glerminal.h index e3a9bc9..a2dd208 100644 --- a/include/glerminal.h +++ b/include/glerminal.h @@ -1,18 +1,13 @@ #ifndef GLERMINAL_H #define GLERMINAL_H +#include + #ifdef __cplusplus extern "C" { #endif -enum -{ - GRID_WIDTH = 40, - GRID_HEIGHT = 25, - LAYER_COUNT = 64 -}; - typedef void (*glerminal_init_cb)(); typedef void (*glerminal_main_cb)(float dt); diff --git a/source/glerminal-config.h.in b/source/glerminal-config.h.in new file mode 100644 index 0000000..a9d58b9 --- /dev/null +++ b/source/glerminal-config.h.in @@ -0,0 +1,26 @@ +#ifndef GLERMINAL_CONFIG_H +#define GLERMINAL_CONFIG_H + +// THIS FILE IS CONFIGURED BY CMAKE +// MODIFY glerminal-config.h.in INSTEAD! + +#ifdef __cplusplus +extern "C" +{ +#endif + +#cmakedefine GLERMINAL_OPENGL_DEBUG_CONTEXT + +enum +{ + GRID_WIDTH = @GLERMINAL_GRID_WIDTH@, + GRID_HEIGHT = @GLERMINAL_GRID_HEIGHT@, + LAYER_COUNT = @GLERMINAL_LAYER_COUNT@, + CELL_SCALE = @GLERMINAL_CELL_SCALE@ +}; + +#ifdef __cplusplus +} +#endif + +#endif//GLERMINAL_CONFIG_H \ No newline at end of file diff --git a/source/glerminal-private.h b/source/glerminal-private.h index 24947de..fbda5f2 100644 --- a/source/glerminal-private.h +++ b/source/glerminal-private.h @@ -12,13 +12,14 @@ namespace glerminal { - constexpr unsigned int SCREEN_WIDTH = 1280; - constexpr unsigned int SCREEN_HEIGHT = 800; constexpr unsigned int CELL_SIZE = 8; - constexpr unsigned int LAYER_COUNT = ::LAYER_COUNT; constexpr unsigned int GRID_WIDTH = ::GRID_WIDTH; constexpr unsigned int GRID_HEIGHT = ::GRID_HEIGHT; + constexpr unsigned int LAYER_COUNT = ::LAYER_COUNT; + constexpr unsigned int CELL_SCALE = ::CELL_SCALE; constexpr unsigned int GRID_AREA = GRID_WIDTH * GRID_HEIGHT; + constexpr unsigned int SCREEN_WIDTH = GRID_WIDTH * CELL_SIZE * CELL_SCALE; + constexpr unsigned int SCREEN_HEIGHT = GRID_HEIGHT * CELL_SIZE * CELL_SCALE; class glerminal { diff --git a/source/glerminal.cpp b/source/glerminal.cpp index f1e07bd..b34bfc9 100644 --- a/source/glerminal.cpp +++ b/source/glerminal.cpp @@ -295,7 +295,7 @@ namespace glerminal // need to think about how to handle resizing to ensure // that the window stays an integer number of "tiles" large glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); -#ifdef _DEBUG +#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT glfwWindowHint(GLFW_CONTEXT_DEBUG, GLFW_TRUE); #endif @@ -308,7 +308,7 @@ namespace glerminal } } -#ifdef _DEBUG +#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT void glerminal::log(GLenum type, GLuint id, GLenum severity, const char* message) const { glDebugMessageInsert(GL_DEBUG_SOURCE_THIRD_PARTY, type, id, severity, -1, message); @@ -325,7 +325,7 @@ namespace glerminal throw std::runtime_error("Failed to initialize GLAD."); } -#ifdef _DEBUG +#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback([](GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)