]> git.lizzy.rs Git - shadowclad.git/blob - main.c
Add the concept of a player character and load its 3D model
[shadowclad.git] / 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 "render.h"
8 #include "ui.h"
9
10 int main(int argc, char** argv) {
11         glutInit(&argc, argv);
12         // glutInitContextVersion(4,5); TODO establish correct context
13         
14         glutInitWindowSize(1280, 720);
15         
16         glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
17         glutCreateWindow(NULL);
18         
19         glutSetWindowTitle("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(renderScene);
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         
61         glutMainLoop();
62         return 0;
63 }