You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.6 KiB
116 lines
2.6 KiB
#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"
|
|
#include "bezos.hpp"
|
|
|
|
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) {
|
|
Engine* engine = static_cast<Engine*>(glfwGetWindowUserPointer(window));
|
|
engine->mouse(xpos, ypos);
|
|
}
|
|
|
|
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
|
{
|
|
Engine* engine = static_cast<Engine*>(glfwGetWindowUserPointer(window));
|
|
|
|
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
|
glfwSetWindowShouldClose(window, true);
|
|
}
|
|
|
|
if (key == GLFW_KEY_W && action == GLFW_PRESS) {
|
|
engine->change_slide(-1);
|
|
}
|
|
|
|
if (key == GLFW_KEY_S && action == GLFW_PRESS) {
|
|
engine->change_slide(1);
|
|
}
|
|
}
|
|
|
|
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);
|
|
glfwSetKeyCallback(window, key_callback);
|
|
|
|
return window;
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
void render(GLFWwindow* window, Engine &state) {
|
|
state.render();
|
|
|
|
glfwSwapBuffers(window);
|
|
}
|
|
|
|
void quit(GLFWwindow* window) {
|
|
glfwTerminate();
|
|
}
|
|
|
|
int main() {
|
|
init_glfw();
|
|
|
|
auto window = create_window();
|
|
setup();
|
|
Deck deck = Bezos::load("lua/builder_test.lua");
|
|
|
|
Engine state(deck);
|
|
|
|
glfwSetWindowUserPointer(window, &state);
|
|
|
|
while(!glfwWindowShouldClose(window)) {
|
|
update(window);
|
|
render(window, state);
|
|
}
|
|
|
|
quit(window);
|
|
|
|
return 0;
|
|
}
|
|
|