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