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:
+2
-2
@@ -23,14 +23,14 @@ auto cube::init() -> bool {
|
||||
|
||||
auto cube::update(float) -> void {}
|
||||
|
||||
auto cube::render() -> void {
|
||||
auto cube::render(int width, int height) -> void {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto elapsed = std::chrono::duration<float>(now - m_start).count();
|
||||
|
||||
glClearColor(0.15f, 0.15f, 0.2f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
auto aspect = 1280.0f / 720.0f;
|
||||
auto aspect = float(width) / float(height);
|
||||
auto proj = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 100.0f);
|
||||
auto view = glm::translate(glm::mat4{1.0f}, glm::vec3{0.0f, 0.0f, -3.0f});
|
||||
auto model = glm::rotate(glm::mat4{1.0f}, elapsed, glm::vec3{1.0f, 0.5f, 0.3f});
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ public:
|
||||
cube();
|
||||
auto init() -> bool override;
|
||||
auto update(float delta_time) -> void override;
|
||||
auto render() -> void override;
|
||||
auto render(int width, int height) -> void override;
|
||||
|
||||
private:
|
||||
opengl::shader m_prog;
|
||||
|
||||
+2
-2
@@ -25,14 +25,14 @@ auto sphere::init() -> bool {
|
||||
|
||||
auto sphere::update(float) -> void {}
|
||||
|
||||
auto sphere::render() -> void {
|
||||
auto sphere::render(int width, int height) -> void {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto elapsed = std::chrono::duration<float>(now - m_start).count();
|
||||
|
||||
glClearColor(0.15f, 0.15f, 0.2f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
auto aspect = 1280.0f / 720.0f;
|
||||
auto aspect = float(width) / float(height);
|
||||
auto proj = glm::perspective(glm::radians(45.0f), aspect, 0.1f, 100.0f);
|
||||
auto view = glm::translate(glm::mat4{1.0f}, glm::vec3{0.0f, 0.0f, -4.0f});
|
||||
auto model = glm::rotate(glm::mat4{1.0f}, elapsed, glm::vec3{1.0f, 0.3f, 0.2f});
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ public:
|
||||
sphere();
|
||||
auto init() -> bool override;
|
||||
auto update(float delta_time) -> void override;
|
||||
auto render() -> void override;
|
||||
auto render(int width, int height) -> void override;
|
||||
|
||||
private:
|
||||
opengl::shader m_prog;
|
||||
|
||||
Reference in New Issue
Block a user