diff --git a/common/map_view.cpp b/common/map_view.cpp index 5119b3134..e151964e3 100644 --- a/common/map_view.cpp +++ b/common/map_view.cpp @@ -68,12 +68,10 @@ public: glfwSetKeyCallback(window, key); } - static void character(GLFWwindow *window, unsigned int codepoint) { } - static void key(GLFWwindow *window, int key, int scancode, int action, int mods) { MapView *mapView = (MapView *)glfwGetWindowUserPointer(window); @@ -95,7 +93,6 @@ public: } } - static void scroll(GLFWwindow *window, double xoffset, double yoffset) { MapView *mapView = (MapView *)glfwGetWindowUserPointer(window); double delta = yoffset * 40; @@ -234,3 +231,38 @@ public: llmr::Settings& settings; llmr::Map map; }; + +namespace llmr { +namespace platform { + +double time() { + return glfwGetTime(); +} + + +void show_debug_image(std::string name, const char *data, size_t width, size_t height) { + static GLFWwindow *debug_window = nullptr; + if (!debug_window) { + debug_window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr); + if (!debug_window) { + glfwTerminate(); + fprintf(stderr, "Failed to initialize window\n"); + exit(1); + } + } + + GLFWwindow *current_window = glfwGetCurrentContext(); + + glfwSetWindowSize(debug_window, width, height); + glfwMakeContextCurrent(debug_window); + + glPixelZoom(1.0, -1.0); + glRasterPos2f(-1.0f, 1.0f); + glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); + glfwSwapBuffers(debug_window); + + glfwMakeContextCurrent(current_window); +} + +} +} diff --git a/include/llmr/platform/platform.hpp b/include/llmr/platform/platform.hpp index 806c69f8d..bb9e619cb 100644 --- a/include/llmr/platform/platform.hpp +++ b/include/llmr/platform/platform.hpp @@ -34,6 +34,9 @@ double time(); // Performs routine cleanup operation and is called on every loop iteration. void cleanup(); +// Shows an RGBA image with the specified dimensions in a named window. +void show_debug_image(std::string name, const char *data, size_t width, size_t height); + } } diff --git a/linux/main.cpp b/linux/main.cpp index 9e2c24001..51d31bd0b 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -110,9 +110,5 @@ void cancel_request_http(Request *request) { } } -double time() { - return glfwGetTime(); -} - } } diff --git a/macosx/main.mm b/macosx/main.mm index 48d8aee63..705bff8ff 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -84,9 +84,5 @@ void cancel_request_http(Request *request) }]; } -double time() { - return glfwGetTime(); -} - } } diff --git a/src/geometry/glyph_atlas.cpp b/src/geometry/glyph_atlas.cpp index ef55d268e..05ede1476 100644 --- a/src/geometry/glyph_atlas.cpp +++ b/src/geometry/glyph_atlas.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -135,5 +136,7 @@ void GlyphAtlas::bind() { std::lock_guard lock(mtx); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); dirty = false; + + platform::show_debug_image("Glyph Atlas", data, width, height); } }; diff --git a/src/map/map.cpp b/src/map/map.cpp index 3d6236827..1a9e6c609 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -432,6 +432,8 @@ bool Map::render() { transform.updateAnimations(); } + glyphAtlas.bind(); + bool changed = updateTiles(); painter.clear();