doing stuff
[ld42_outofspace] / src / 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         glEnable(GL_LIGHTING);
26         glEnable(GL_LIGHT0);
27
28         active_screen->start();
29         return true;
30 }
31
32 void game_cleanup()
33 {
34         cleanup_screens();
35 }
36
37 void game_draw()
38 {
39         active_screen->draw();
40
41         assert(glGetError() == GL_NO_ERROR);
42 }
43
44 void game_reshape(int x, int y)
45 {
46         active_screen->draw();
47 }
48
49 void game_keyboard(int key, bool pressed)
50 {
51         if(pressed) {
52                 switch(key) {
53                 case 17:
54                         /* for some inexplicable reason freeglut seems to produce key
55                          * 17 for ctrl-q on both X and windows.
56                          */
57                         game_quit();
58                         return;
59
60                 default:
61                         break;
62                 }
63         }
64
65         active_screen->keyboard(key, pressed);
66 }
67
68 void game_mbutton(int bn, bool pressed, int x, int y)
69 {
70         active_screen->mbutton(bn, pressed, x, y);
71 }
72
73 void game_mmotion(int x, int y)
74 {
75         active_screen->mmotion(x, y);
76 }
77
78 void game_mwheel(int dir, int x, int y)
79 {
80         active_screen->mwheel(dir, x, y);
81 }