4 #include <assimp/version.h>
6 #include <GLFW/glfw3.h>
11 #include "performance.h"
15 // static const int EXIT_OK = 0;
16 static const int EXIT_LIB_FAIL = 1;
17 static const int EXIT_CTX_FAIL = 2;
19 static GLFWwindow* window;
21 static void onGlfwError(int error, const char* description);
25 void init(EngineConfig config) {
27 logError("init called more than once");
31 logInfo("Assimp %u.%u", aiGetVersionMajor(), aiGetVersionMinor());
32 logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
33 logInfo("GLFW %s", glfwGetVersionString());
35 glfwSetErrorCallback(onGlfwError);
38 logError("GLFW init failed");
41 // glutInitContextVersion(4,5); TODO establish correct context
42 // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
43 // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
45 window = glfwCreateWindow(config.windowWidth,
47 config.windowTitle.cstr,
52 logError("Window or context creation failed");
57 glfwMakeContextCurrent(window);
59 logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
60 logInfo("GLSL %s", (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
61 logInfo("Renderer: %s", (const char*) glGetString(GL_RENDERER));
63 GLenum glewInitStatus = glewInit();
64 if (glewInitStatus != GLEW_OK) {
65 logError("GLEW init failed: %s", (const char*) glewGetErrorString(glewInitStatus));
69 logInfo("Setting swap interval: %d", config.swapInterval);
70 glfwSwapInterval(config.swapInterval);
73 glfwGetFramebufferSize(window, &width, &height);
74 resizeStage(window, width, height);
76 glfwSetFramebufferSizeCallback(window, resizeStage);
77 glfwSetKeyCallback(window, onKeyboardEvent);
80 //initPerformanceMetering();
83 void run(void (*updateFn) (float)) {
85 logError("No update function provided");
89 float lastTime = glfwGetTime();
92 while (!glfwWindowShouldClose(window)) {
93 float time = glfwGetTime();
94 delta = time - lastTime;
108 EngineConfig defaultConfig() {
109 return (EngineConfig) { .windowWidth = 800,
111 .windowTitle = newString(NULL),
115 static void onGlfwError(int error UNUSED, const char* description) {
116 logError("GLFW error: %s", description);