intravenous

view src/main.cc @ 3:94d4c60af435

some progress
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Apr 2012 03:35:18 +0300
parents 472c28b8b875
children aab0d8ea21cd
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 glClearColor(0.05, 0.05, 0.05, 1.0);
55 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
57 // render stuff
58 game_draw();
60 glutSwapBuffers();
61 assert(glGetError() == GL_NO_ERROR);
62 }
64 void reshape(int x, int y)
65 {
66 glViewport(0, 0, x, y);
68 glMatrixMode(GL_PROJECTION);
69 glLoadIdentity();
70 gluPerspective(FOV_DEG, (float)x / (float)y, 0.1, 200.0);
72 win_xsz = x;
73 win_ysz = y;
74 }
76 void key_press(unsigned char key, int x, int y)
77 {
78 game_input_keyb(key, 1);
79 }
81 void key_release(unsigned char key, int x, int y)
82 {
83 game_input_keyb(key, 0);
84 }
86 void mouse(int bn, int state, int x, int y)
87 {
88 game_input_mbutton(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN, x, y);
89 }
91 void motion(int x, int y)
92 {
93 game_input_mmotion(x, y);
94 }