a4ef4adfc7
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).
42 lines
1022 B
C++
42 lines
1022 B
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
#define GLFW_INCLUDE_NONE
|
|
#include "GLFW/glfw3.h"
|
|
|
|
namespace cbt {
|
|
|
|
class window {
|
|
public:
|
|
explicit window(std::string title, int width, int height);
|
|
~window();
|
|
|
|
auto should_close() const -> bool;
|
|
auto valid() const -> bool;
|
|
auto swap_buffers() -> void;
|
|
auto poll_events() -> void;
|
|
auto raw() const -> GLFWwindow*;
|
|
auto stop() -> void;
|
|
auto screenshot(std::string filepath = "screenshot.png") const -> bool;
|
|
auto width() const -> int;
|
|
auto height() const -> int;
|
|
|
|
using resize_callback = std::function<void(int width, int height)>;
|
|
auto on_resize(resize_callback cb) -> void;
|
|
|
|
private:
|
|
GLFWwindow* m_window = nullptr;
|
|
int m_width = 0;
|
|
int m_height = 0;
|
|
resize_callback m_resize_cb;
|
|
bool m_glfw_initialized = false;
|
|
|
|
static auto init_glfw() -> bool;
|
|
static auto terminate_glfw() -> void;
|
|
static auto resize_callback_impl(GLFWwindow* glfw_window, int width, int height) -> void;
|
|
};
|
|
|
|
}
|