mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
refactor: introduce App class as program core
This commit is contained in:
52
src/window.cpp
Normal file
52
src/window.cpp
Normal 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();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user