From 4373c6aeb823853b1dad98fec92070234711438a Mon Sep 17 00:00:00 2001 From: OLEGSHA Date: Fri, 26 Mar 2021 02:29:25 +0300 Subject: [PATCH] Added texture reload feature --- main.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/main.cpp b/main.cpp index a5aaf98..9d3ae71 100644 --- a/main.cpp +++ b/main.cpp @@ -71,6 +71,9 @@ public: return gl_id; } + const std::string& getName() { + return name; + } void load_stb() { int channels; @@ -221,6 +224,7 @@ void switch_camera(); void switch_theme(); void change_texture(int direction); void close_texture(); +void reload_texture(); void on_key(GLFWwindow*, int key, int, int action, int mods) { if (action != GLFW_PRESS) return; @@ -242,6 +246,9 @@ void on_key(GLFWwindow*, int key, int, int action, int mods) { case GLFW_KEY_DELETE: close_texture(); return; + case GLFW_KEY_F5: + reload_texture(); + return; case GLFW_KEY_TAB: switch_camera(); return; @@ -297,6 +304,24 @@ void close_texture() { selection -= 1; } +void reload_texture() { + if (LOADED_TEXTURES.empty()) return; + + auto it = LOADED_TEXTURES.begin() + selection; + std::string name = (*it)->getName(); + + LOADED_TEXTURES.erase(it); + + load_texture(name); + + for (size_t i = 0; i < LOADED_TEXTURES.size(); ++i) { + if (LOADED_TEXTURES[i]->getName() == name) { + selection = i; + break; + } + } +} +