intravenous

annotate 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
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <assert.h>
nuclear@0 3 #include "opengl.h"
nuclear@0 4 #include "game.h"
nuclear@0 5
nuclear@0 6 #define FOV_DEG 50.0
nuclear@0 7
nuclear@0 8 void disp();
nuclear@0 9 void idle();
nuclear@0 10 void reshape(int x, int y);
nuclear@0 11 void key_press(unsigned char key, int x, int y);
nuclear@0 12 void key_release(unsigned char key, int x, int y);
nuclear@1 13 void mouse(int bn, int state, int x, int y);
nuclear@1 14 void motion(int x, int y);
nuclear@0 15
nuclear@0 16 int win_xsz, win_ysz;
nuclear@0 17
nuclear@0 18 int main(int argc, char **argv)
nuclear@0 19 {
nuclear@0 20 glutInitWindowSize(800, 450);
nuclear@0 21 glutInit(&argc, argv);
nuclear@0 22 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
nuclear@0 23 glutCreateWindow("intravenous interventor");
nuclear@0 24
nuclear@0 25 glutDisplayFunc(disp);
nuclear@0 26 glutIdleFunc(idle);
nuclear@0 27 glutReshapeFunc(reshape);
nuclear@0 28 glutKeyboardFunc(key_press);
nuclear@0 29 glutKeyboardUpFunc(key_release);
nuclear@1 30 glutMouseFunc(mouse);
nuclear@1 31 glutMotionFunc(motion);
nuclear@0 32
nuclear@3 33 glewInit();
nuclear@3 34
nuclear@0 35 if(!game_init()) {
nuclear@0 36 return 1;
nuclear@0 37 }
nuclear@0 38
nuclear@0 39 glutMainLoop();
nuclear@0 40 return 0;
nuclear@0 41 }
nuclear@0 42
nuclear@0 43 void idle()
nuclear@0 44 {
nuclear@0 45 glutPostRedisplay();
nuclear@0 46 }
nuclear@0 47
nuclear@0 48 void disp()
nuclear@0 49 {
nuclear@0 50 unsigned long msec = glutGet(GLUT_ELAPSED_TIME);
nuclear@0 51 // update any game logic
nuclear@0 52 game_update(msec);
nuclear@0 53
nuclear@0 54 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
nuclear@0 55
nuclear@0 56 // render stuff
nuclear@0 57 game_draw();
nuclear@0 58
nuclear@0 59 glutSwapBuffers();
nuclear@0 60 assert(glGetError() == GL_NO_ERROR);
nuclear@0 61 }
nuclear@0 62
nuclear@0 63 void reshape(int x, int y)
nuclear@0 64 {
nuclear@0 65 glViewport(0, 0, x, y);
nuclear@0 66
nuclear@0 67 glMatrixMode(GL_PROJECTION);
nuclear@0 68 glLoadIdentity();
nuclear@2 69 gluPerspective(FOV_DEG, (float)x / (float)y, 0.1, 200.0);
nuclear@0 70
nuclear@0 71 win_xsz = x;
nuclear@0 72 win_ysz = y;
nuclear@0 73 }
nuclear@0 74
nuclear@0 75 void key_press(unsigned char key, int x, int y)
nuclear@0 76 {
nuclear@0 77 game_input_keyb(key, 1);
nuclear@0 78 }
nuclear@0 79
nuclear@0 80 void key_release(unsigned char key, int x, int y)
nuclear@0 81 {
nuclear@0 82 game_input_keyb(key, 0);
nuclear@0 83 }
nuclear@1 84
nuclear@1 85 void mouse(int bn, int state, int x, int y)
nuclear@1 86 {
nuclear@1 87 game_input_mbutton(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN, x, y);
nuclear@1 88 }
nuclear@1 89
nuclear@1 90 void motion(int x, int y)
nuclear@1 91 {
nuclear@1 92 game_input_mmotion(x, y);
nuclear@1 93 }