feat: add window resize support
Added width/height tracking to the window class via a GLFW resize callback. The callback stores the current size and forwards it to a user-provided std::function. Added context::set_size() to update the GL viewport when the window is resized. Changed scene::render() to accept (int width, int height) parameters so scenes can compute the correct aspect ratio for their projection matrix instead of hardcoding 1280/720. Fixed parameter shadowing in resize_callback_impl (glfw_window instead of window).
This commit is contained in:
@@ -52,6 +52,12 @@ window::window(std::string title, int width, int height) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
glfwSetWindowUserPointer(m_window, this);
|
||||
glfwSetWindowSizeCallback(m_window, resize_callback_impl);
|
||||
|
||||
#ifdef _WIN32
|
||||
auto hwnd = glfwGetWin32Window(m_window);
|
||||
BOOL use_dark_mode = TRUE;
|
||||
@@ -94,6 +100,29 @@ auto window::stop() -> void {
|
||||
}
|
||||
}
|
||||
|
||||
auto window::width() const -> int {
|
||||
return m_width;
|
||||
}
|
||||
|
||||
auto window::height() const -> int {
|
||||
return m_height;
|
||||
}
|
||||
|
||||
auto window::on_resize(resize_callback cb) -> void {
|
||||
m_resize_cb = cb;
|
||||
}
|
||||
|
||||
auto window::resize_callback_impl(GLFWwindow* glfw_window, int width, int height) -> void {
|
||||
auto* self = static_cast<window*>(glfwGetWindowUserPointer(glfw_window));
|
||||
if (self) {
|
||||
self->m_width = width;
|
||||
self->m_height = height;
|
||||
if (self->m_resize_cb) {
|
||||
self->m_resize_cb(width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto window::screenshot(std::string filepath) const -> bool {
|
||||
if (!m_window || !valid()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user