]> git.lizzy.rs Git - shadowclad.git/blobdiff - src/engine/engine.c
Add prelude with UNUSED macro
[shadowclad.git] / src / engine / engine.c
index 81abb235a9b95cdb78bf323b88860759f1f87af3..1e7849f7a33dc45cf85d5409406de78a005bd8d7 100644 (file)
@@ -5,6 +5,8 @@
 #include <GL/glxew.h>
 #include <GLFW/glfw3.h>
 
+#include "_prelude.h"
+#include "input.h"
 #include "logger.h"
 #include "performance.h"
 #include "render.h"
@@ -20,7 +22,7 @@ static void onGlfwError(int error, const char* description);
 
 
 
-void init() {
+void init(EngineConfig config) {
        if (window) {
                logError("init called more than once");
                return;
@@ -40,7 +42,12 @@ void init() {
        // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
        // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
 
-       window = glfwCreateWindow(1280, 720, "shadowclad", NULL, NULL);
+       window = glfwCreateWindow(config.windowWidth,
+                                 config.windowHeight,
+                                 config.windowTitle.cstr,
+                                 NULL,
+                                 NULL);
+
        if (!window) {
                logError("Window or context creation failed");
                glfwTerminate();
@@ -51,7 +58,7 @@ void init() {
 
        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));
+       logInfo("Renderer: %s", (const char*) glGetString(GL_RENDERER));
 
        GLenum glewInitStatus = glewInit();
        if (glewInitStatus != GLEW_OK) {
@@ -59,14 +66,15 @@ void init() {
                exit(EXIT_LIB_FAIL);
        }
 
-       logInfo("Setting swap interval to 1");
-       glfwSwapInterval(1);
+       logInfo("Setting swap interval: %d", config.swapInterval);
+       glfwSwapInterval(config.swapInterval);
 
        int width, height;
        glfwGetFramebufferSize(window, &width, &height);
        resizeStage(window, width, height);
 
        glfwSetFramebufferSizeCallback(window, resizeStage);
+       glfwSetKeyCallback(window, onKeyboardEvent);
 
        initRender();
        //initPerformanceMetering();
@@ -97,10 +105,13 @@ void terminate() {
        glfwTerminate();
 }
 
-void setKeyboardEventCallback(void (*keyboardEventCallback) (GLFWwindow*, int, int, int, int)) {
-       glfwSetKeyCallback(window, keyboardEventCallback);
+EngineConfig defaultConfig() {
+       return (EngineConfig) { .windowWidth = 800,
+                               .windowHeight = 600,
+                               .windowTitle = newString(NULL),
+                               .swapInterval = 1 };
 }
 
-static void onGlfwError(int error, const char* description) {
+static void onGlfwError(int error UNUSED, const char* description) {
        logError("GLFW error: %s", description);
 }