|
@@ -1,8 +1,11 @@
|
|
|
#include "game.h"
|
|
|
-#include "callbacks.h"
|
|
|
+
|
|
|
#include <spdlog/spdlog.h>
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
|
+#include "window.h"
|
|
|
+#include "callbacks.h"
|
|
|
+
|
|
|
Game::Game() {
|
|
|
m_window_height = 600;
|
|
|
m_window_width = 800;
|
|
@@ -12,6 +15,8 @@ Game::Game() {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ m_window = std::make_unique<Window>(m_window_height, m_window_height);
|
|
|
+
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
|
@@ -24,34 +29,10 @@ Game::Game(int width, int height): m_window_width(width), m_window_height(height
|
|
|
}
|
|
|
|
|
|
Game::~Game() {
|
|
|
- glfwDestroyWindow(*m_window);
|
|
|
- glfwTerminate();
|
|
|
+ glfwTerminate();
|
|
|
}
|
|
|
|
|
|
void Game::init() {
|
|
|
- m_window = std::make_unique<GLFWwindow *>(glfwCreateWindow(
|
|
|
- m_window_width
|
|
|
- , m_window_height
|
|
|
- , "My New Window"
|
|
|
- , NULL
|
|
|
- , NULL)
|
|
|
- );
|
|
|
-
|
|
|
- if (!m_window) {
|
|
|
- spdlog::error("Could not create GLFW Window.");
|
|
|
- glfwTerminate();
|
|
|
- return;
|
|
|
- }
|
|
|
- glfwMakeContextCurrent(*m_window);
|
|
|
-
|
|
|
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
|
- spdlog::error("Failed to initialize GLAD");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- glfwSetKeyCallback(*m_window, key_callback);
|
|
|
- glfwSetFramebufferSizeCallback(*m_window, framebuffer_size_callback);
|
|
|
-
|
|
|
|
|
|
glViewport(0, 0, m_window_width, m_window_height);
|
|
|
glEnable(GL_BLEND);
|
|
@@ -71,29 +52,24 @@ void Game::run() {
|
|
|
double deltaTime = 0.0f;
|
|
|
double lastFrame = 0.0f;
|
|
|
|
|
|
- while (!glfwWindowShouldClose(*m_window.get())) {
|
|
|
-
|
|
|
+ while (m_window->run()) {
|
|
|
|
|
|
double currentFrame = glfwGetTime();
|
|
|
deltaTime = currentFrame - lastFrame;
|
|
|
lastFrame = currentFrame;
|
|
|
- glfwPollEvents();
|
|
|
-
|
|
|
- process_input();
|
|
|
|
|
|
- glm::vec2 pos = glm::vec2(0,0);
|
|
|
- glm::vec2 size(400.0f, 300.0f);
|
|
|
- glm::vec3 color(0.5f, 0.5f, 0.5f);
|
|
|
+ glm::vec2 pos = glm::vec2(0,0);
|
|
|
+ glm::vec2 size(400.0f, 300.0f);
|
|
|
+ glm::vec3 color(0.5f, 0.5f, 0.5f);
|
|
|
|
|
|
- glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
|
|
- glClear(GL_COLOR_BUFFER_BIT);
|
|
|
+ glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
|
|
+ glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
- for(Renderer &r: m_renderer_objects) {
|
|
|
+ for(Renderer &r: m_renderer_objects) {
|
|
|
r.draw();
|
|
|
- }
|
|
|
- spdlog::warn("deltaTime {}", 1.0f/deltaTime);
|
|
|
+ }
|
|
|
|
|
|
- glfwSwapBuffers(*m_window.get());
|
|
|
+ spdlog::warn("deltaTime {}", 1.0f/deltaTime);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -101,8 +77,3 @@ void Game::run() {
|
|
|
void Game::add_renderer_object(Renderer obj) {
|
|
|
m_renderer_objects.push_back(obj);
|
|
|
}
|
|
|
-
|
|
|
-void Game::process_input() {
|
|
|
- if (glfwGetKey(*m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
|
|
- glfwSetWindowShouldClose(*m_window, true);
|
|
|
-}
|