|
@@ -1,6 +1,3 @@
|
|
-#define GLFW_INCLUDE_NONE
|
|
|
|
-#include <GLFW/glfw3.h>
|
|
|
|
-#include <glad/glad.h>
|
|
|
|
|
|
|
|
#include <spdlog/spdlog.h>
|
|
#include <spdlog/spdlog.h>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
@@ -8,6 +5,7 @@
|
|
#include "callbacks.h"
|
|
#include "callbacks.h"
|
|
#include "shader.h"
|
|
#include "shader.h"
|
|
#include "renderer.h"
|
|
#include "renderer.h"
|
|
|
|
+#include "game.h"
|
|
|
|
|
|
#define WINDOW_WIDTH 800
|
|
#define WINDOW_WIDTH 800
|
|
#define WINDOW_HEIGHT 600
|
|
#define WINDOW_HEIGHT 600
|
|
@@ -16,36 +14,8 @@ void process_input(GLFWwindow* window);
|
|
|
|
|
|
int main() {
|
|
int main() {
|
|
|
|
|
|
- if (!glfwInit()) {
|
|
|
|
- spdlog::error("Could not intialize GLFW.");
|
|
|
|
- return EXIT_FAILURE;
|
|
|
|
- }
|
|
|
|
- glfwSetErrorCallback(error_callback);
|
|
|
|
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
|
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
|
|
|
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- GLFWwindow *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "My New Window", NULL, NULL);
|
|
|
|
- if (!window) {
|
|
|
|
- spdlog::error("Could not create GLFW Window.");
|
|
|
|
- glfwTerminate();
|
|
|
|
- return EXIT_FAILURE;
|
|
|
|
- }
|
|
|
|
- glfwMakeContextCurrent(window);
|
|
|
|
-
|
|
|
|
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
|
|
- spdlog::error("Failed to initialize GLAD");
|
|
|
|
- return EXIT_FAILURE;
|
|
|
|
- }
|
|
|
|
- glfwSetKeyCallback(window, key_callback);
|
|
|
|
- glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
|
|
|
- glEnable(GL_BLEND);
|
|
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
-
|
|
|
|
|
|
+ Game game;
|
|
|
|
+ game.init();
|
|
|
|
|
|
Shader basic = Shader("shaders/vert.glsl", "shaders/frag.glsl");
|
|
Shader basic = Shader("shaders/vert.glsl", "shaders/frag.glsl");
|
|
basic.use();
|
|
basic.use();
|
|
@@ -54,41 +24,14 @@ int main() {
|
|
static_cast<float>(WINDOW_HEIGHT), 0.0f, -1.0f, 1.0f);
|
|
static_cast<float>(WINDOW_HEIGHT), 0.0f, -1.0f, 1.0f);
|
|
basic.setMatrix4("projection", projection);
|
|
basic.setMatrix4("projection", projection);
|
|
|
|
|
|
- Renderer r = Renderer(basic);
|
|
|
|
- float deltaTime = 0.0f;
|
|
|
|
- float lastFrame = 0.0f;
|
|
|
|
-
|
|
|
|
- while (!glfwWindowShouldClose(window)) {
|
|
|
|
-
|
|
|
|
|
|
|
|
- float currentFrame = glfwGetTime();
|
|
|
|
- deltaTime = currentFrame - lastFrame;
|
|
|
|
- lastFrame = currentFrame;
|
|
|
|
- glfwPollEvents();
|
|
|
|
|
|
+ glm::vec2 pos = glm::vec2(0,0);
|
|
|
|
+ glm::vec2 size(400.0f, 300.0f);
|
|
|
|
+ glm::vec3 color(0.5f, 0.5f, 0.5f);
|
|
|
|
+ Renderer r = Renderer(basic, pos, size, 0.0f, color);
|
|
|
|
|
|
- process_input(window);
|
|
|
|
-
|
|
|
|
- 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);
|
|
|
|
-
|
|
|
|
- r.draw(pos, size, 0.0f, color);
|
|
|
|
-
|
|
|
|
- spdlog::warn("deltaTime {}", 1.0f/deltaTime);
|
|
|
|
-
|
|
|
|
- glfwSwapBuffers(window);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- glfwDestroyWindow(window);
|
|
|
|
- glfwTerminate();
|
|
|
|
|
|
+ game.add_renderer_object(r);
|
|
|
|
|
|
|
|
+ game.run();
|
|
return EXIT_SUCCESS;
|
|
return EXIT_SUCCESS;
|
|
}
|
|
}
|
|
-
|
|
|
|
-void process_input(GLFWwindow* window) {
|
|
|
|
- if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
|
|
|
- glfwSetWindowShouldClose(window, true);
|
|
|
|
-}
|
|
|