]> git.lizzy.rs Git - shadowclad.git/blob - src/main.c
abfd8e9fe214ebf156f71d6e4577c5f16af96e0d
[shadowclad.git] / src / main.c
1 #include <GL/glxew.h>
2 #include <GL/glut.h>
3
4 #include "engine/logger.h"
5 #include "engine/performance.h"
6 #include "engine/render.h"
7 #include "engine/ui.h"
8
9 #include "game/input.h"
10 #include "game/level.h"
11 #include "game/player.h"
12
13 int main(int argc, char** argv) {
14         glutInit(&argc, argv);
15         // glutInitContextVersion(4,5); TODO establish correct context
16         
17         glutInitWindowSize(1280, 720);
18         
19         glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
20         glutCreateWindow("shadowclad");
21         
22         logInfo("OpenGL %s", (const char*) glGetString(GL_VERSION));
23         logInfo("GLSL %s", (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
24         logInfo("%s", (const char*) glGetString(GL_RENDERER));
25         
26         GLenum glewInitStatus = glewInit();
27         if (glewInitStatus != GLEW_OK) {
28                 logError("GLEW init failed: %s", (const char*) glewGetErrorString(glewInitStatus));
29                 return 1;
30         }
31         logInfo("GLEW %s", (const char*) glewGetString(GLEW_VERSION));
32         
33         if (GLXEW_EXT_swap_control) {
34                 Display* display = glXGetCurrentDisplay();
35                 GLXDrawable drawable = glXGetCurrentDrawable();
36                 if (drawable) {
37                         glXSwapIntervalEXT(display, drawable, 1);
38                 }
39                 else {
40                         logWarning("Drawable is not here ¯\\_(ツ)_/¯");
41                         logWarning("Could not enable vsync (GLX_EXT_swap_control)");
42                 }
43         }
44         else if (GLXEW_MESA_swap_control) {
45                 glXSwapIntervalMESA(1);
46                 logDebug("Vsync enabled with GLX_MESA_swap_control, swap interval %d", glXGetSwapIntervalMESA());
47         }
48         else {
49                 logWarning("Could not enable vsync (extensions not supported)");
50         }
51         
52         glutDisplayFunc(renderFrame);
53         glutReshapeFunc(resizeStage);
54         glutKeyboardFunc(onKeyPressed);
55         //glutMouseFunc(mouse_button_event);
56         //glutMotionFunc(mouse_motion_event);
57         
58         initRender();
59         //initPerformanceMetering();
60         initLevel();
61         initPlayer();
62         startLevel();
63         
64         glutMainLoop();
65         return 0;
66 }