stratgame

view src/main.cc @ 1:55a43e27339a

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 22 May 2012 05:02:00 +0300
parents 86b53f76899f
children 369b51c9e4a8
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include "opengl.h"
5 #include "part.h"
6 #include "menu_part.h"
7 #include "game_part.h"
9 static bool init();
10 static void cleanup();
11 static void disp();
12 static void idle();
13 static void reshape(int x, int y);
14 static void key_press(unsigned char key, int x, int y);
15 static void key_release(unsigned char key, int x, int y);
16 static void mouse(int bn, int state, int x, int y);
17 static void motion(int x, int y);
18 static void sball_motion(int x, int y, int z);
19 static void sball_rotate(int x, int y, int z);
20 static void sball_button(int bn, int state);
22 int main(int argc, char **argv)
23 {
24 glutInit(&argc, argv);
25 glutInitWindowSize(800, 450);
26 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL);
27 glutCreateWindow("Foo");
29 glutDisplayFunc(disp);
30 glutIdleFunc(idle);
31 glutReshapeFunc(reshape);
32 glutKeyboardFunc(key_press);
33 glutKeyboardUpFunc(key_release);
34 glutMouseFunc(mouse);
35 glutMotionFunc(motion);
36 glutPassiveMotionFunc(motion);
37 glutSpaceballMotionFunc(sball_motion);
38 glutSpaceballRotateFunc(sball_rotate);
39 glutSpaceballButtonFunc(sball_button);
41 if(!init()) {
42 return 1;
43 }
44 atexit(cleanup);
46 glutMainLoop();
47 return 0;
48 }
51 static bool init()
52 {
53 glewInit();
55 menu_part = new MainMenu;
56 game_part = new Game;
57 cur_part = menu_part;
59 return true;
60 }
62 static void cleanup()
63 {
64 delete menu_part;
65 delete game_part;
66 }
68 static void disp()
69 {
70 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
71 cur_part->update(msec);
72 cur_part->draw();
74 glutSwapBuffers();
75 usleep(1000);
76 }
78 static void idle()
79 {
80 glutPostRedisplay();
81 }
83 static void reshape(int x, int y)
84 {
85 glViewport(0, 0, x, y);
87 cur_part->reshape(x, y);
88 }
90 static void key_press(unsigned char key, int x, int y)
91 {
92 cur_part->key(key, true);
93 }
95 static void key_release(unsigned char key, int x, int y)
96 {
97 cur_part->key(key, false);
98 }
100 static void mouse(int bn, int state, int x, int y)
101 {
102 cur_part->mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN);
103 }
105 static void motion(int x, int y)
106 {
107 cur_part->mouse_motion(x, y);
108 }
110 static int sbmotion[6];
112 static void sball_motion(int x, int y, int z)
113 {
114 sbmotion[0] = x;
115 sbmotion[1] = y;
116 sbmotion[2] = z;
117 cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2],
118 sbmotion[3], sbmotion[4], sbmotion[5]);
119 }
121 static void sball_rotate(int x, int y, int z)
122 {
123 sbmotion[3] = x;
124 sbmotion[4] = y;
125 sbmotion[5] = z;
126 cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2],
127 sbmotion[3], sbmotion[4], sbmotion[5]);
128 }
130 static void sball_button(int bn, int state)
131 {
132 cur_part->spaceball_button(bn, state == GLUT_DOWN);
133 }