intravenous

view src/main.cc @ 1:3ea290d35984

it's never going to finish but wth :)
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Apr 2012 22:42:43 +0300
parents 2b30f261f641
children 472c28b8b875
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 if(!game_init()) {
34 return 1;
35 }
37 glutMainLoop();
38 return 0;
39 }
41 void idle()
42 {
43 glutPostRedisplay();
44 }
46 void disp()
47 {
48 unsigned long msec = glutGet(GLUT_ELAPSED_TIME);
49 // update any game logic
50 game_update(msec);
52 glClearColor(0.05, 0.05, 0.05, 1.0);
53 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
55 // render stuff
56 game_draw();
58 glutSwapBuffers();
59 assert(glGetError() == GL_NO_ERROR);
60 }
62 void reshape(int x, int y)
63 {
64 glViewport(0, 0, x, y);
66 glMatrixMode(GL_PROJECTION);
67 glLoadIdentity();
68 gluPerspective(FOV_DEG, (float)x / (float)y, 1.0, 1000.0);
70 win_xsz = x;
71 win_ysz = y;
72 }
74 void key_press(unsigned char key, int x, int y)
75 {
76 game_input_keyb(key, 1);
77 }
79 void key_release(unsigned char key, int x, int y)
80 {
81 game_input_keyb(key, 0);
82 }
84 void mouse(int bn, int state, int x, int y)
85 {
86 game_input_mbutton(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN, x, y);
87 }
89 void motion(int x, int y)
90 {
91 game_input_mmotion(x, y);
92 }