4 #include <assimp/version.h>
6 #include <GLFW/glfw3.h>
10 #include "performance.h"
14 // static const int EXIT_OK = 0;
15 static const int EXIT_LIB_FAIL = 1;
16 static const int EXIT_CTX_FAIL = 2;
18 static GLFWwindow* window;
20 static void onGlfwError(int error, const char* description);
24 void init(EngineConfig config) {
26 logError("init called more than once");
30 logInfo("Assimp %u.%u", aiGetVersionMajor(), aiGetVersionMinor());
31 logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
32 logInfo("GLFW %s", glfwGetVersionString());
34 glfwSetErrorCallback(onGlfwError);
37 logError("GLFW init failed");
40 // glutInitContextVersion(4,5); TODO establish correct context
41 // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
42 // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
44 window = glfwCreateWindow(config.windowWidth,
46 config.windowTitle.cstr,
51 logError("Window or context creation failed");
56 glfwMakeContextCurrent(window);
58 logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
59 logInfo("GLSL %s", (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
60 logInfo("Renderer: %s", (const char*) glGetString(GL_RENDERER));
62 GLenum glewInitStatus = glewInit();
63 if (glewInitStatus != GLEW_OK) {
64 logError("GLEW init failed: %s", (const char*) glewGetErrorString(glewInitStatus));
68 logInfo("Setting swap interval: %d", config.swapInterval);
69 glfwSwapInterval(config.swapInterval);
72 glfwGetFramebufferSize(window, &width, &height);
73 resizeStage(window, width, height);
75 glfwSetFramebufferSizeCallback(window, resizeStage);
76 glfwSetKeyCallback(window, onKeyboardEvent);
79 //initPerformanceMetering();
82 void run(void (*updateFn) (float)) {
84 logError("No update function provided");
88 float lastTime = glfwGetTime();
91 while (!glfwWindowShouldClose(window)) {
92 float time = glfwGetTime();
93 delta = time - lastTime;
107 EngineConfig defaultConfig() {
108 return (EngineConfig) { .windowWidth = 800,
110 .windowTitle = newString(NULL),
114 static void onGlfwError(int error, const char* description) {
115 logError("GLFW error: %s", description);