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:
2026-05-06 00:06:59 +02:00
parent 91fe3c6e8c
commit a4ef4adfc7
11 changed files with 61 additions and 9 deletions
+6 -1
View File
@@ -57,6 +57,11 @@ auto main(int argc, char const* argv[]) -> int {
return 1;
}
// Wire up resize callback
win.on_resize([&ctx](int width, int height) {
ctx.set_size(width, height);
});
auto cube_scn = cbt::scenes::cube();
auto sphere_scn = cbt::scenes::sphere();
@@ -118,7 +123,7 @@ auto main(int argc, char const* argv[]) -> int {
prev = now;
active_scene->update(dt);
active_scene->render();
active_scene->render(win.width(), win.height());
win.swap_buffers();
win.poll_events();