diff --git a/src/lib/cimbar_js/cimbar_js.cpp b/src/lib/cimbar_js/cimbar_js.cpp index 4a78583..a303b11 100644 --- a/src/lib/cimbar_js/cimbar_js.cpp +++ b/src/lib/cimbar_js/cimbar_js.cpp @@ -29,9 +29,6 @@ extern "C" { int initialize_GL(int width, int height) { - if (_window) - return 1; - // must be divisible by 4??? if (width % 4 != 0) width += (4 - width % 4); @@ -39,7 +36,10 @@ int initialize_GL(int width, int height) height += (4 - height % 4); std::cerr << "initializing " << width << " by " << height << " window"; - _window = std::make_shared(width, height, "Cimbar Encoder"); + if (_window and _window->is_good()) + _window->resize(width, height); + else + _window = std::make_shared(width, height, "Cimbar Encoder"); if (!_window or !_window->is_good()) return 0; diff --git a/src/lib/gui/gl_2d_display.h b/src/lib/gui/gl_2d_display.h index becd9fc..56ba534 100644 --- a/src/lib/gui/gl_2d_display.h +++ b/src/lib/gui/gl_2d_display.h @@ -44,9 +44,9 @@ class gl_2d_display } public: - gl_2d_display(unsigned width, unsigned height) + gl_2d_display(float dim) : _p(create()) - , _shakePos(computeShakePos(std::min(width, height))) + , _shakePos(computeShakePos(dim)) , _shake(_shakePos) , _rotation(ROTATIONS) { diff --git a/src/lib/gui/window_glfw.h b/src/lib/gui/window_glfw.h index 011b044..184efe3 100644 --- a/src/lib/gui/window_glfw.h +++ b/src/lib/gui/window_glfw.h @@ -33,7 +33,7 @@ class window_glfw glfwMakeContextCurrent(_w); glfwSwapInterval(1); - _display = std::make_shared(width, height); + _display = std::make_shared(std::min(width, height)); glGenTextures(1, &_texid); init_opengl(width, height); } @@ -41,7 +41,10 @@ class window_glfw ~window_glfw() { if (_w) + { glfwDestroyWindow(_w); + _w = nullptr; + } if (_texid) glDeleteTextures(1, &_texid); glfwTerminate(); @@ -65,6 +68,12 @@ class window_glfw glfwSetWindowSizeCallback(_w, fun); } + void resize(unsigned width, unsigned height) + { + if (_w) + glfwSetWindowSize(_w, width, height); + } + void rotate(unsigned i=1) { if (_display) @@ -133,7 +142,7 @@ class window_glfw } protected: - GLFWwindow* _w; + GLFWwindow* _w = nullptr; GLuint _texid; std::shared_ptr _display; unsigned _width;