]> git.lizzy.rs Git - shadowclad.git/blob - src/main.c
Implement continuous player movement
[shadowclad.git] / src / main.c
1 #include <assimp/version.h>
2 #include <GL/glxew.h>
3 #include <GLFW/glfw3.h>
4
5 #include "engine/logger.h"
6 #include "engine/performance.h"
7 #include "engine/render.h"
8 #include "engine/ui.h"
9
10 #include "game/input.h"
11 #include "game/level.h"
12 #include "game/player.h"
13
14 void onGlfwError(int error, const char* description);
15
16 int main(/*int argc, char** argv*/) {
17         logInfo("Assimp %u.%u", aiGetVersionMajor(), aiGetVersionMinor());
18         logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
19         logInfo("GLFW %s", glfwGetVersionString());
20
21         glfwSetErrorCallback(onGlfwError);
22
23         if (!glfwInit()) {
24                 logError("GLFW init failed");
25                 return 1;
26         }
27         // glutInitContextVersion(4,5); TODO establish correct context
28         // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
29         // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
30
31         GLFWwindow* window = glfwCreateWindow(1280, 720, "shadowclad", NULL, NULL);
32         if (!window) {
33                 logError("Window or context creation failed");
34                 glfwTerminate();
35                 return 2;
36         }
37
38         glfwMakeContextCurrent(window);
39
40         logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
41         logInfo("GLSL %s", (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
42         logInfo("%s", (const char*) glGetString(GL_RENDERER));
43
44         GLenum glewInitStatus = glewInit();
45         if (glewInitStatus != GLEW_OK) {
46                 logError("GLEW init failed: %s", (const char*) glewGetErrorString(glewInitStatus));
47                 return 1;
48         }
49
50         logInfo("Setting swap interval to 1");
51         glfwSwapInterval(1);
52
53         int width, height;
54         glfwGetFramebufferSize(window, &width, &height);
55         resizeStage(window, width, height);
56
57         glfwSetFramebufferSizeCallback(window, resizeStage);
58         glfwSetKeyCallback(window, onKeyboardEvent);
59
60         initRender();
61         //initPerformanceMetering();
62         initLevel();
63         initPlayer();
64         startLevel();
65
66         float lastTime = glfwGetTime();
67         float delta = 0.0f;
68
69         while (!glfwWindowShouldClose(window)) {
70                 float time = glfwGetTime();
71                 delta = time - lastTime;
72                 lastTime = time;
73
74                 updatePlayer(delta);
75                 renderFrame(window);
76                 glfwPollEvents();
77         }
78
79         glfwTerminate();
80         return 0;
81 }
82
83 void onGlfwError(int error, const char* description) {
84         logError("GLFW error: %s", description);
85 }