cf3f62ad448447362b6581905983c98f83310390
[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 'q':
54                 case 'Q':
55                         if(game_modkeys() & MODKEY_CTRL) {
56                                 game_quit();
57                                 return;
58                         }
59                         break;
60
61                 default:
62                         break;
63                 }
64         }
65
66         active_screen->keyboard(key, pressed);
67 }
68
69 void game_mbutton(int bn, bool pressed, int x, int y)
70 {
71         active_screen->mbutton(bn, pressed, x, y);
72 }
73
74 void game_mmotion(int x, int y)
75 {
76         active_screen->mmotion(x, y);
77 }
78
79 void game_mwheel(int dir, int x, int y)
80 {
81         active_screen->mwheel(dir, x, y);
82 }