intravenous

view src/main.cc @ 9:90af225f469a

- merged collision detection code - reduced inertia
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 28 Apr 2012 17:10:29 +0300
parents 94d4c60af435
children
line source
1 #include <stdio.h>
2 #include <assert.h>
3 #include "opengl.h"
4 #include "game.h"
6 #define FOV_DEG 50.0
8 void disp();
9 void idle();
10 void reshape(int x, int y);
11 void key_press(unsigned char key, int x, int y);
12 void key_release(unsigned char key, int x, int y);
13 void mouse(int bn, int state, int x, int y);
14 void motion(int x, int y);
16 int win_xsz, win_ysz;
18 int main(int argc, char **argv)
19 {
20 glutInitWindowSize(800, 450);
21 glutInit(&argc, argv);
22 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
23 glutCreateWindow("intravenous interventor");
25 glutDisplayFunc(disp);
26 glutIdleFunc(idle);
27 glutReshapeFunc(reshape);
28 glutKeyboardFunc(key_press);
29 glutKeyboardUpFunc(key_release);
30 glutMouseFunc(mouse);
31 glutMotionFunc(motion);
33 glewInit();
35 if(!game_init()) {
36 return 1;
37 }
39 glutMainLoop();
40 return 0;
41 }
43 void idle()
44 {
45 glutPostRedisplay();
46 }
48 void disp()
49 {
50 unsigned long msec = glutGet(GLUT_ELAPSED_TIME);
51 // update any game logic
52 game_update(msec);
54 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
56 // render stuff
57 game_draw();
59 glutSwapBuffers();
60 assert(glGetError() == GL_NO_ERROR);
61 }
63 void reshape(int x, int y)
64 {
65 glViewport(0, 0, x, y);
67 glMatrixMode(GL_PROJECTION);
68 glLoadIdentity();
69 gluPerspective(FOV_DEG, (float)x / (float)y, 0.1, 200.0);
71 win_xsz = x;
72 win_ysz = y;
73 }
75 void key_press(unsigned char key, int x, int y)
76 {
77 game_input_keyb(key, 1);
78 }
80 void key_release(unsigned char key, int x, int y)
81 {
82 game_input_keyb(key, 0);
83 }
85 void mouse(int bn, int state, int x, int y)
86 {
87 game_input_mbutton(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN, x, y);
88 }
90 void motion(int x, int y)
91 {
92 game_input_mmotion(x, y);
93 }