diff options
author | Adrian Kummerlaender | 2018-12-17 19:31:38 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2018-12-17 19:31:38 +0100 |
commit | f465b26a8aeac95cf7e0186a86ab1262dc771fb4 (patch) | |
tree | 8eb6e88a57b48fa1a6b3b0a3fca0e4e35f6b47e5 /src/glfw | |
parent | ede5386d53a453cb56c9b1c80de0a80322ddc6f1 (diff) | |
download | compustream-f465b26a8aeac95cf7e0186a86ab1262dc771fb4.tar compustream-f465b26a8aeac95cf7e0186a86ab1262dc771fb4.tar.gz compustream-f465b26a8aeac95cf7e0186a86ab1262dc771fb4.tar.bz2 compustream-f465b26a8aeac95cf7e0186a86ab1262dc771fb4.tar.lz compustream-f465b26a8aeac95cf7e0186a86ab1262dc771fb4.tar.xz compustream-f465b26a8aeac95cf7e0186a86ab1262dc771fb4.tar.zst compustream-f465b26a8aeac95cf7e0186a86ab1262dc771fb4.zip |
Keep track of window size in its wrapper class
Diffstat (limited to 'src/glfw')
-rw-r--r-- | src/glfw/window.cc | 10 | ||||
-rw-r--r-- | src/glfw/window.h | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/glfw/window.cc b/src/glfw/window.cc index 0e57a65..9e76b57 100644 --- a/src/glfw/window.cc +++ b/src/glfw/window.cc @@ -1,5 +1,15 @@ #include "window.h" +bool Window::updateSize() { + const int old_width = _width; + const int old_height = _height; + + glfwGetWindowSize(_handle, &_width, &_height); + + return old_width != _width + || old_height != _height; +} + Window::Window(const std::string& title): _handle(glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL)) { if ( _handle != nullptr ) { diff --git a/src/glfw/window.h b/src/glfw/window.h index 92a1b56..ea6075b 100644 --- a/src/glfw/window.h +++ b/src/glfw/window.h @@ -15,6 +15,8 @@ private: GLFWwindow* const _handle; + bool updateSize(); + public: Window(const std::string& title); ~Window(); @@ -46,9 +48,13 @@ void Window::render(F loop) { while ( glfwGetKey(_handle, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(_handle) == 0 ) { - glfwGetWindowSize(_handle, &_width, &_height); + const bool window_size_changed = updateSize(); + + if ( window_size_changed ) { + glViewport(0, 0, getWidth(), getHeight()); + } - loop(); + loop(window_size_changed); glfwSwapBuffers(_handle); glfwPollEvents(); |