Skip to content

Commit

Permalink
Allow resize of gl window?
Browse files Browse the repository at this point in the history
All current cimbar configs share the same dimensions, but that might be
changing
  • Loading branch information
sz3 committed Jan 14, 2025
1 parent 163a63b commit 81e3987
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/lib/cimbar_js/cimbar_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ 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);
if (height % 4 != 0)
height += (4 - height % 4);
std::cerr << "initializing " << width << " by " << height << " window";

_window = std::make_shared<cimbar::window_glfw>(width, height, "Cimbar Encoder");
if (_window and _window->is_good())
_window->resize(width, height);
else
_window = std::make_shared<cimbar::window_glfw>(width, height, "Cimbar Encoder");
if (!_window or !_window->is_good())
return 0;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/gui/gl_2d_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 11 additions & 2 deletions src/lib/gui/window_glfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ class window_glfw
glfwMakeContextCurrent(_w);
glfwSwapInterval(1);

_display = std::make_shared<cimbar::gl_2d_display>(width, height);
_display = std::make_shared<cimbar::gl_2d_display>(std::min(width, height));
glGenTextures(1, &_texid);
init_opengl(width, height);
}

~window_glfw()
{
if (_w)
{
glfwDestroyWindow(_w);
_w = nullptr;
}
if (_texid)
glDeleteTextures(1, &_texid);
glfwTerminate();
Expand All @@ -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)
Expand Down Expand Up @@ -133,7 +142,7 @@ class window_glfw
}

protected:
GLFWwindow* _w;
GLFWwindow* _w = nullptr;
GLuint _texid;
std::shared_ptr<cimbar::gl_2d_display> _display;
unsigned _width;
Expand Down

0 comments on commit 81e3987

Please sign in to comment.