intravenous
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main.cc Sat Apr 21 06:56:33 2012 +0300 1.3 @@ -0,0 +1,77 @@ 1.4 +#include <stdio.h> 1.5 +#include <assert.h> 1.6 +#include "opengl.h" 1.7 +#include "game.h" 1.8 + 1.9 +#define FOV_DEG 50.0 1.10 + 1.11 +void disp(); 1.12 +void idle(); 1.13 +void reshape(int x, int y); 1.14 +void key_press(unsigned char key, int x, int y); 1.15 +void key_release(unsigned char key, int x, int y); 1.16 + 1.17 +int win_xsz, win_ysz; 1.18 + 1.19 +int main(int argc, char **argv) 1.20 +{ 1.21 + glutInitWindowSize(800, 450); 1.22 + glutInit(&argc, argv); 1.23 + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 1.24 + glutCreateWindow("intravenous interventor"); 1.25 + 1.26 + glutDisplayFunc(disp); 1.27 + glutIdleFunc(idle); 1.28 + glutReshapeFunc(reshape); 1.29 + glutKeyboardFunc(key_press); 1.30 + glutKeyboardUpFunc(key_release); 1.31 + 1.32 + if(!game_init()) { 1.33 + return 1; 1.34 + } 1.35 + 1.36 + glutMainLoop(); 1.37 + return 0; 1.38 +} 1.39 + 1.40 +void idle() 1.41 +{ 1.42 + glutPostRedisplay(); 1.43 +} 1.44 + 1.45 +void disp() 1.46 +{ 1.47 + unsigned long msec = glutGet(GLUT_ELAPSED_TIME); 1.48 + // update any game logic 1.49 + game_update(msec); 1.50 + 1.51 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.52 + 1.53 + // render stuff 1.54 + game_draw(); 1.55 + 1.56 + glutSwapBuffers(); 1.57 + assert(glGetError() == GL_NO_ERROR); 1.58 +} 1.59 + 1.60 +void reshape(int x, int y) 1.61 +{ 1.62 + glViewport(0, 0, x, y); 1.63 + 1.64 + glMatrixMode(GL_PROJECTION); 1.65 + glLoadIdentity(); 1.66 + gluPerspective(FOV_DEG, (float)x / (float)y, 1.0, 1000.0); 1.67 + 1.68 + win_xsz = x; 1.69 + win_ysz = y; 1.70 +} 1.71 + 1.72 +void key_press(unsigned char key, int x, int y) 1.73 +{ 1.74 + game_input_keyb(key, 1); 1.75 +} 1.76 + 1.77 +void key_release(unsigned char key, int x, int y) 1.78 +{ 1.79 + game_input_keyb(key, 0); 1.80 +}