stratgame
diff src/main.cc @ 0:86b53f76899f
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 21 May 2012 19:07:40 +0300 |
parents | |
children | 55a43e27339a |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main.cc Mon May 21 19:07:40 2012 +0300 1.3 @@ -0,0 +1,133 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <unistd.h> 1.7 +#include "opengl.h" 1.8 +#include "part.h" 1.9 +#include "menu_part.h" 1.10 +#include "game_part.h" 1.11 + 1.12 +static bool init(); 1.13 +static void cleanup(); 1.14 +static void disp(); 1.15 +static void idle(); 1.16 +static void reshape(int x, int y); 1.17 +static void key_press(unsigned char key, int x, int y); 1.18 +static void key_release(unsigned char key, int x, int y); 1.19 +static void mouse(int bn, int state, int x, int y); 1.20 +static void motion(int x, int y); 1.21 +static void sball_motion(int x, int y, int z); 1.22 +static void sball_rotate(int x, int y, int z); 1.23 +static void sball_button(int bn, int state); 1.24 + 1.25 +int main(int argc, char **argv) 1.26 +{ 1.27 + glutInit(&argc, argv); 1.28 + glutInitWindowSize(1280, 800); 1.29 + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL); 1.30 + glutCreateWindow("Foo"); 1.31 + 1.32 + glutDisplayFunc(disp); 1.33 + glutIdleFunc(idle); 1.34 + glutReshapeFunc(reshape); 1.35 + glutKeyboardFunc(key_press); 1.36 + glutKeyboardUpFunc(key_release); 1.37 + glutMouseFunc(mouse); 1.38 + glutMotionFunc(motion); 1.39 + glutPassiveMotionFunc(motion); 1.40 + glutSpaceballMotionFunc(sball_motion); 1.41 + glutSpaceballRotateFunc(sball_rotate); 1.42 + glutSpaceballButtonFunc(sball_button); 1.43 + 1.44 + if(!init()) { 1.45 + return 1; 1.46 + } 1.47 + atexit(cleanup); 1.48 + 1.49 + glutMainLoop(); 1.50 + return 0; 1.51 +} 1.52 + 1.53 + 1.54 +static bool init() 1.55 +{ 1.56 + glewInit(); 1.57 + 1.58 + menu_part = new MainMenu; 1.59 + game_part = new Game; 1.60 + cur_part = menu_part; 1.61 + 1.62 + return true; 1.63 +} 1.64 + 1.65 +static void cleanup() 1.66 +{ 1.67 + delete menu_part; 1.68 + delete game_part; 1.69 +} 1.70 + 1.71 +static void disp() 1.72 +{ 1.73 + unsigned int msec = glutGet(GLUT_ELAPSED_TIME); 1.74 + cur_part->update(msec); 1.75 + cur_part->draw(); 1.76 + 1.77 + glutSwapBuffers(); 1.78 + usleep(1000); 1.79 +} 1.80 + 1.81 +static void idle() 1.82 +{ 1.83 + glutPostRedisplay(); 1.84 +} 1.85 + 1.86 +static void reshape(int x, int y) 1.87 +{ 1.88 + glViewport(0, 0, x, y); 1.89 + 1.90 + cur_part->reshape(x, y); 1.91 +} 1.92 + 1.93 +static void key_press(unsigned char key, int x, int y) 1.94 +{ 1.95 + cur_part->key(key, true); 1.96 +} 1.97 + 1.98 +static void key_release(unsigned char key, int x, int y) 1.99 +{ 1.100 + cur_part->key(key, false); 1.101 +} 1.102 + 1.103 +static void mouse(int bn, int state, int x, int y) 1.104 +{ 1.105 + cur_part->mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN); 1.106 +} 1.107 + 1.108 +static void motion(int x, int y) 1.109 +{ 1.110 + cur_part->mouse_motion(x, y); 1.111 +} 1.112 + 1.113 +static int sbmotion[6]; 1.114 + 1.115 +static void sball_motion(int x, int y, int z) 1.116 +{ 1.117 + sbmotion[0] = x; 1.118 + sbmotion[1] = y; 1.119 + sbmotion[2] = z; 1.120 + cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2], 1.121 + sbmotion[3], sbmotion[4], sbmotion[5]); 1.122 +} 1.123 + 1.124 +static void sball_rotate(int x, int y, int z) 1.125 +{ 1.126 + sbmotion[3] = x; 1.127 + sbmotion[4] = y; 1.128 + sbmotion[5] = z; 1.129 + cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2], 1.130 + sbmotion[3], sbmotion[4], sbmotion[5]); 1.131 +} 1.132 + 1.133 +static void sball_button(int bn, int state) 1.134 +{ 1.135 + cur_part->spaceball_button(bn, state == GLUT_DOWN); 1.136 +}