#include <GL/glxew.h>
#include <GLFW/glfw3.h>
+#include "_prelude.h"
+#include "input.h"
#include "logger.h"
#include "performance.h"
#include "render.h"
-void init() {
+void init(EngineConfig config) {
if (window) {
logError("init called more than once");
return;
// 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();
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) {
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();
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);
}