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