|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
|
#include <stb_image.h>
|
|
|
|
|
#include <fmt/core.h>
|
|
|
|
|
#include <glad/glad.h>
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
#include "config.hpp"
|
|
|
|
|
#include "render.hpp"
|
|
|
|
|
|
|
|
|
|
float mouse_x = 0;
|
|
|
|
|
float mouse_y = 0;
|
|
|
|
|
|
|
|
|
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void init_glfw() {
|
|
|
|
|
glfwInit();
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void framebuffer_size_callback(GLFWwindow *, int width, int height) {
|
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mouse_callback(GLFWwindow *window, double xpos, double ypos) {
|
|
|
|
|
fmt::println("mouse click: {},{}", xpos, ypos);
|
|
|
|
|
mouse_x = xpos;
|
|
|
|
|
mouse_y = ypos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLFWwindow* create_window() {
|
|
|
|
|
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
|
|
|
|
|
dbc::check(window != NULL, "failed to open window");
|
|
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
|
|
|
|
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
|
|
|
|
|
|
|
|
|
auto good = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
|
|
|
|
dbc::check(good, "failed to load GLAD");
|
|
|
|
|
|
|
|
|
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
|
|
|
|
glfwSetCursorPosCallback(window, mouse_callback);
|
|
|
|
|
glfwSetScrollCallback(window, scroll_callback);
|
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void process_input(GLFWwindow *window) {
|
|
|
|
|
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
|
|
|
|
glfwSetWindowShouldClose(window, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
|
|
|
|
fmt::println("move window left");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
|
|
|
|
fmt::println("move window left");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
|
glEnable(GL_MULTISAMPLE);
|
|
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update(GLFWwindow* window) {
|
|
|
|
|
glfwPollEvents();
|
|
|
|
|
process_input(window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void render(GLFWwindow* window, Engine &state) {
|
|
|
|
|
state.render();
|
|
|
|
|
|
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void quit(GLFWwindow* window) {
|
|
|
|
|
glfwTerminate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
init_glfw();
|
|
|
|
|
|
|
|
|
|
auto window = create_window();
|
|
|
|
|
setup();
|
|
|
|
|
Engine state;
|
|
|
|
|
|
|
|
|
|
// glfwSetWindowUserPointer(window, scene.get());
|
|
|
|
|
|
|
|
|
|
while(!glfwWindowShouldClose(window)) {
|
|
|
|
|
update(window);
|
|
|
|
|
render(window, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quit(window);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|