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