intravenous

view src/main.cc @ 0:2b30f261f641

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Apr 2012 06:56:33 +0300
parents
children 3ea290d35984
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);
14 int win_xsz, win_ysz;
16 int main(int argc, char **argv)
17 {
18 glutInitWindowSize(800, 450);
19 glutInit(&argc, argv);
20 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
21 glutCreateWindow("intravenous interventor");
23 glutDisplayFunc(disp);
24 glutIdleFunc(idle);
25 glutReshapeFunc(reshape);
26 glutKeyboardFunc(key_press);
27 glutKeyboardUpFunc(key_release);
29 if(!game_init()) {
30 return 1;
31 }
33 glutMainLoop();
34 return 0;
35 }
37 void idle()
38 {
39 glutPostRedisplay();
40 }
42 void disp()
43 {
44 unsigned long msec = glutGet(GLUT_ELAPSED_TIME);
45 // update any game logic
46 game_update(msec);
48 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
50 // render stuff
51 game_draw();
53 glutSwapBuffers();
54 assert(glGetError() == GL_NO_ERROR);
55 }
57 void reshape(int x, int y)
58 {
59 glViewport(0, 0, x, y);
61 glMatrixMode(GL_PROJECTION);
62 glLoadIdentity();
63 gluPerspective(FOV_DEG, (float)x / (float)y, 1.0, 1000.0);
65 win_xsz = x;
66 win_ysz = y;
67 }
69 void key_press(unsigned char key, int x, int y)
70 {
71 game_input_keyb(key, 1);
72 }
74 void key_release(unsigned char key, int x, int y)
75 {
76 game_input_keyb(key, 0);
77 }