4 #include <assimp/version.h>
6 #include <GLFW/glfw3.h>
9 #include "performance.h"
13 // static const int EXIT_OK = 0;
14 static const int EXIT_LIB_FAIL = 1;
15 static const int EXIT_CTX_FAIL = 2;
17 static GLFWwindow* window;
19 static void onGlfwError(int error, const char* description);
25 logError("init called more than once");
29 logInfo("Assimp %u.%u", aiGetVersionMajor(), aiGetVersionMinor());
30 logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
31 logInfo("GLFW %s", glfwGetVersionString());
33 glfwSetErrorCallback(onGlfwError);
36 logError("GLFW init failed");
39 // glutInitContextVersion(4,5); TODO establish correct context
40 // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
41 // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
43 window = glfwCreateWindow(1280, 720, "shadowclad", NULL, NULL);
45 logError("Window or context creation failed");
50 glfwMakeContextCurrent(window);
52 logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
53 logInfo("GLSL %s", (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
54 logInfo("%s", (const char*) glGetString(GL_RENDERER));
56 GLenum glewInitStatus = glewInit();
57 if (glewInitStatus != GLEW_OK) {
58 logError("GLEW init failed: %s", (const char*) glewGetErrorString(glewInitStatus));
62 logInfo("Setting swap interval to 1");
66 glfwGetFramebufferSize(window, &width, &height);
67 resizeStage(window, width, height);
69 glfwSetFramebufferSizeCallback(window, resizeStage);
72 //initPerformanceMetering();
75 void run(void (*updateFn) (float)) {
77 logError("No update function provided");
81 float lastTime = glfwGetTime();
84 while (!glfwWindowShouldClose(window)) {
85 float time = glfwGetTime();
86 delta = time - lastTime;
100 void setKeyboardEventCallback(void (*keyboardEventCallback) (GLFWwindow*, int, int, int, int)) {
101 glfwSetKeyCallback(window, keyboardEventCallback);
104 static void onGlfwError(int error, const char* description) {
105 logError("GLFW error: %s", description);