refactor: introduce App class as program core

This commit is contained in:
2026-03-20 22:46:34 +08:00
parent bfc928d91a
commit 3916a72ca3
12 changed files with 492 additions and 288 deletions

52
src/window.cpp Normal file
View File

@@ -0,0 +1,52 @@
#include <Cubed/renderer.hpp>
#include <Cubed/input.hpp>
#include <Cubed/tools/cubed_assert.hpp>
#include <Cubed/tools/log.hpp>
#include <Cubed/window.hpp>
Window::Window(Renderer& renderer) :
m_renderer(renderer)
{
}
Window::~Window() {
glfwDestroyWindow(m_window);
glfwTerminate();
}
const GLFWwindow* Window::get_glfw_window() const {
return m_window;
}
GLFWwindow* Window::get_glfw_window() {
return m_window;
}
void Window::update_viewport() {
glfwGetFramebufferSize(m_window, &m_width, &m_height);
m_aspect = (float)m_width / (float)m_height;
glViewport(0, 0, m_width, m_height);
m_renderer.update_proj_matrix(m_aspect);
}
void Window::init() {
if (!glfwInit()) {
LOG::error("glfwinit fail");
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
m_window = glfwCreateWindow(800, 600, "Cubed", NULL, NULL);
glfwMakeContextCurrent(m_window);
glfwSwapInterval(1);
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
//update_viewport();
}