bloboland
diff src/main.cc @ 0:e4818a3300b9
bloboland initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 15 Dec 2012 07:52:13 +0200 |
parents | |
children | cfe68befb7cc |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main.cc Sat Dec 15 07:52:13 2012 +0200 1.3 @@ -0,0 +1,121 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include "opengl.h" 1.7 +#include "game.h" 1.8 +#include "opt.h" 1.9 + 1.10 +static void disp(); 1.11 +static void reshape(int x, int y); 1.12 +static void keydown(unsigned char key, int x, int y); 1.13 +static void keyup(unsigned char key, int x, int y); 1.14 +static void skeydown(int key, int x, int y); 1.15 +static void skeyup(int key, int x, int y); 1.16 +static void mouse(int bn, int state, int x, int y); 1.17 +static void motion(int x, int y); 1.18 +static void spacemove(int x, int y, int z); 1.19 +static void spacerot(int x, int y, int z); 1.20 +static void spacebut(int bn, int state); 1.21 + 1.22 +int main(int argc, char **argv) 1.23 +{ 1.24 + glutInit(&argc, argv); 1.25 + 1.26 + if(!parse_opt(argc, argv)) { 1.27 + return 1; 1.28 + } 1.29 + 1.30 + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0)); 1.31 + glutInitWindowSize(800, 450); 1.32 + glutCreateWindow("bloboland"); 1.33 + 1.34 + glutDisplayFunc(disp); 1.35 + glutReshapeFunc(reshape); 1.36 + glutKeyboardFunc(keydown); 1.37 + glutKeyboardUpFunc(keyup); 1.38 + glutSpecialFunc(skeydown); 1.39 + glutSpecialUpFunc(skeyup); 1.40 + glutMouseFunc(mouse); 1.41 + glutMotionFunc(motion); 1.42 + glutSpaceballMotionFunc(spacemove); 1.43 + glutSpaceballRotateFunc(spacerot); 1.44 + glutSpaceballButtonFunc(spacebut); 1.45 + 1.46 + glewInit(); 1.47 + 1.48 + if(!game_init()) { 1.49 + return 1; 1.50 + } 1.51 + 1.52 + glutMainLoop(); 1.53 +} 1.54 + 1.55 +static void disp() 1.56 +{ 1.57 + unsigned int msec = glutGet(GLUT_ELAPSED_TIME); 1.58 + game_iter((msec - prev_msec) / 1000.0); 1.59 + 1.60 + 1.61 + glClear(GL_COLOR_BUFFER_BIT); 1.62 + 1.63 + game_render(); 1.64 + 1.65 + glutSwapBuffers(); 1.66 +} 1.67 + 1.68 +static void reshape(int x, int y) 1.69 +{ 1.70 + glViewport(0, 0, x, y); 1.71 + 1.72 + glMatrixMode(GL_PROJECTION); 1.73 + glLoadIdentity(); 1.74 + gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0); 1.75 +} 1.76 + 1.77 +static void keydown(unsigned char key, int x, int y) 1.78 +{ 1.79 + skeydown(key, x, y); 1.80 +} 1.81 + 1.82 +static void keyup(unsigned char key, int x, int y) 1.83 +{ 1.84 + skeyup(key, x, y); 1.85 +} 1.86 + 1.87 +static void skeydown(int key, int x, int y) 1.88 +{ 1.89 + if(key == 27) { 1.90 + exit(0); 1.91 + } 1.92 + 1.93 + if(key < sizeof keystate / sizeof *keystate) { 1.94 + keystate[key] = true; 1.95 + } 1.96 +} 1.97 + 1.98 +static void skeyup(int key, int x, int y) 1.99 +{ 1.100 + if(key < sizeof keystate / sizeof *keystate) { 1.101 + keystate[key] = false; 1.102 + } 1.103 +} 1.104 + 1.105 +static void mouse(int bn, int state, int x, int y) 1.106 +{ 1.107 +} 1.108 + 1.109 +static void motion(int x, int y) 1.110 +{ 1.111 +} 1.112 + 1.113 +static void spacemove(int x, int y, int z) 1.114 +{ 1.115 +} 1.116 + 1.117 +static void spacerot(int x, int y, int z) 1.118 +{ 1.119 +} 1.120 + 1.121 +static void spacebut(int bn, int state) 1.122 +{ 1.123 +} 1.124 +