9d69c69782bf356c9a436abfa9892eacafa6919c
[ld42_outofspace] / game.cc
1 #include <assert.h>
2 #include "opengl.h"
3 #include "game.h"
4 #include "screen.h"
5
6 int win_width, win_height;
7 float win_aspect;
8 long frame_time;
9 float frame_dt;
10
11 bool game_init()
12 {
13         if(init_opengl() == -1) {
14                 return false;
15         }
16
17         if(!init_screens()) {
18                 return false;
19         }
20
21         glEnable(GL_MULTISAMPLE);
22         glEnable(GL_FRAMEBUFFER_SRGB);
23         glEnable(GL_DEPTH_TEST);
24         glEnable(GL_CULL_FACE);
25
26         active_screen->start();
27         return true;
28 }
29
30 void game_cleanup()
31 {
32         cleanup_screens();
33 }
34
35 void game_draw()
36 {
37         active_screen->draw();
38
39         assert(glGetError() == GL_NO_ERROR);
40 }
41
42 void game_reshape(int x, int y)
43 {
44         active_screen->reshape(x, y);
45 }
46
47 void game_keyboard(int key, bool pressed)
48 {
49         if(pressed) {
50                 switch(key) {
51                 case 17:
52                         /* for some inexplicable reason freeglut seems to produce key
53                          * 17 for ctrl-q on both X and windows.
54                          */
55                         game_quit();
56                         return;
57
58                 default:
59                         break;
60                 }
61         }
62
63         active_screen->keyboard(key, pressed);
64 }
65
66 void game_mbutton(int bn, bool pressed, int x, int y)
67 {
68         active_screen->mbutton(bn, pressed, x, y);
69 }
70
71 void game_mmotion(int x, int y)
72 {
73         active_screen->mmotion(x, y);
74 }
75
76 void game_mwheel(int dir, int x, int y)
77 {
78         active_screen->mwheel(dir, x, y);
79 }