]> git.lizzy.rs Git - shadowclad.git/blobdiff - src/main.c
Add and move version logging, disable import debug
[shadowclad.git] / src / main.c
index a7f0c62375b9cb55527b435a83dc68087b42f1d7..bd2fe9d18b8642095bc1237cf6b3be2778471ab7 100644 (file)
@@ -1,33 +1,53 @@
+#include <assimp/version.h>
 #include <GL/glxew.h>
-#include <GL/glut.h>
+#include <GLFW/glfw3.h>
 
-#include "level.h"
-#include "logger.h"
-#include "performance.h"
-#include "player.h"
-#include "render.h"
-#include "ui.h"
+#include "engine/logger.h"
+#include "engine/performance.h"
+#include "engine/render.h"
+#include "engine/ui.h"
 
-int main(int argc, char** argv) {
-       glutInit(&argc, argv);
+#include "game/input.h"
+#include "game/level.h"
+#include "game/player.h"
+
+void onGlfwError(int error, const char* description);
+
+int main(/*int argc, char** argv*/) {
+       logInfo("Assimp %u.%u", aiGetVersionMajor(), aiGetVersionMinor());
+       logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
+       logInfo("GLFW %s", glfwGetVersionString());
+
+       glfwSetErrorCallback(onGlfwError);
+
+       if (!glfwInit()) {
+               logError("GLFW init failed");
+               return 1;
+       }
        // glutInitContextVersion(4,5); TODO establish correct context
-       
-       glutInitWindowSize(1280, 720);
-       
-       glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
-       glutCreateWindow("shadowclad");
-       
+       // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
+       // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
+
+       GLFWwindow* window = glfwCreateWindow(1280, 720, "shadowclad", NULL, NULL);
+       if (!window) {
+               logError("Window or context creation failed");
+               glfwTerminate();
+               return 2;
+       }
+
+       glfwMakeContextCurrent(window);
+       //glutInitDisplayMode(//glut_DOUBLE | //glut_RGBA | //glut_DEPTH);
+
        logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
        logInfo("GLSL %s", (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
        logInfo("%s", (const char*) glGetString(GL_RENDERER));
-       
+
        GLenum glewInitStatus = glewInit();
        if (glewInitStatus != GLEW_OK) {
                logError("GLEW init failed: %s", (const char*) glewGetErrorString(glewInitStatus));
                return 1;
        }
-       logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
-       
+/*
        if (GLXEW_EXT_swap_control) {
                Display* display = glXGetCurrentDisplay();
                GLXDrawable drawable = glXGetCurrentDrawable();
@@ -46,18 +66,32 @@ int main(int argc, char** argv) {
        else {
                logWarning("Could not enable vsync (extensions not supported)");
        }
-       
-       glutDisplayFunc(renderScene);
-       glutReshapeFunc(resizeStage);
-       //glutKeyboardFunc(key_pressed);
-       //glutMouseFunc(mouse_button_event);
-       //glutMotionFunc(mouse_motion_event);
-       
+*/
+       logInfo("Setting swap interval to 1");
+       glfwSwapInterval(1);
+
+       int width, height;
+       glfwGetFramebufferSize(window, &width, &height);
+       resizeStage(window, width, height);
+
+       glfwSetFramebufferSizeCallback(window, resizeStage);
+       glfwSetKeyCallback(window, onKeyboardEvent);
+
        initRender();
        //initPerformanceMetering();
        initLevel();
        initPlayer();
-       
-       glutMainLoop();
+       startLevel();
+
+       while (!glfwWindowShouldClose(window)) {
+               renderFrame(window);
+               glfwPollEvents();
+       }
+
+       glfwTerminate();
        return 0;
 }
+
+void onGlfwError(int error, const char* description) {
+       logError("GLFW error: %s", description);
+}