rev |
line source |
nuclear@0
|
1 #ifdef USE_GLUT
|
nuclear@0
|
2
|
nuclear@0
|
3 #include <stdlib.h>
|
nuclear@0
|
4
|
nuclear@0
|
5 #ifdef __APPLE__
|
nuclear@0
|
6 #include <GLUT/glut.h>
|
nuclear@0
|
7 #else
|
nuclear@0
|
8 #include <GL/glut.h>
|
nuclear@0
|
9 #endif
|
nuclear@0
|
10
|
nuclear@0
|
11 #include "game.h"
|
nuclear@0
|
12
|
nuclear@0
|
13 static void display();
|
nuclear@0
|
14 static void idle();
|
nuclear@0
|
15 static void reshape(int x, int y);
|
nuclear@0
|
16 static void key_press(unsigned char key, int x, int y);
|
nuclear@0
|
17 static void key_release(unsigned char key, int x, int y);
|
nuclear@0
|
18 static void mouse(int bn, int st, int x, int y);
|
nuclear@0
|
19 static void motion(int x, int y);
|
nuclear@0
|
20
|
nuclear@0
|
21 static bool state_fullscreen;
|
nuclear@0
|
22 static int prev_width, prev_height;
|
nuclear@0
|
23 static int win_width, win_height;
|
nuclear@0
|
24
|
nuclear@0
|
25 int main(int argc, char **argv)
|
nuclear@0
|
26 {
|
nuclear@0
|
27 glutInit(&argc, argv);
|
nuclear@0
|
28 glutInitWindowSize(800, 600);
|
nuclear@0
|
29 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
|
nuclear@0
|
30 glutCreateWindow("GLUT");
|
nuclear@0
|
31
|
nuclear@0
|
32 glutDisplayFunc(display);
|
nuclear@0
|
33 glutIdleFunc(idle);
|
nuclear@0
|
34 glutReshapeFunc(reshape);
|
nuclear@0
|
35 glutKeyboardFunc(key_press);
|
nuclear@0
|
36 glutKeyboardUpFunc(key_release);
|
nuclear@0
|
37 glutMouseFunc(mouse);
|
nuclear@0
|
38 glutMotionFunc(motion);
|
nuclear@0
|
39
|
nuclear@0
|
40 if(!game_init(argc, argv)) {
|
nuclear@0
|
41 return 1;
|
nuclear@0
|
42 }
|
nuclear@0
|
43 atexit(game_shutdown);
|
nuclear@0
|
44
|
nuclear@0
|
45 glutMainLoop();
|
nuclear@0
|
46 return 0;
|
nuclear@0
|
47 }
|
nuclear@0
|
48
|
nuclear@0
|
49 void quit()
|
nuclear@0
|
50 {
|
nuclear@0
|
51 exit(0);
|
nuclear@0
|
52 }
|
nuclear@0
|
53
|
nuclear@0
|
54 void swap_buffers()
|
nuclear@0
|
55 {
|
nuclear@0
|
56 glutSwapBuffers();
|
nuclear@0
|
57 }
|
nuclear@0
|
58
|
nuclear@0
|
59 void redisplay()
|
nuclear@0
|
60 {
|
nuclear@0
|
61 glutPostRedisplay();
|
nuclear@0
|
62 }
|
nuclear@0
|
63
|
nuclear@0
|
64 void idle()
|
nuclear@0
|
65 {
|
nuclear@0
|
66 glutPostRedisplay();
|
nuclear@0
|
67 }
|
nuclear@0
|
68
|
nuclear@0
|
69 void fullscreen()
|
nuclear@0
|
70 {
|
nuclear@0
|
71 if(!state_fullscreen) {
|
nuclear@0
|
72 prev_width = win_width;
|
nuclear@0
|
73 prev_height = win_height;
|
nuclear@0
|
74
|
nuclear@0
|
75 glutFullScreen();
|
nuclear@0
|
76 state_fullscreen = true;
|
nuclear@0
|
77 }
|
nuclear@0
|
78 }
|
nuclear@0
|
79
|
nuclear@0
|
80 void windowed()
|
nuclear@0
|
81 {
|
nuclear@0
|
82 if(state_fullscreen) {
|
nuclear@0
|
83 glutReshapeWindow(prev_width, prev_height);
|
nuclear@0
|
84 state_fullscreen = false;
|
nuclear@0
|
85 }
|
nuclear@0
|
86 }
|
nuclear@0
|
87
|
nuclear@0
|
88 void move_window(int x, int y)
|
nuclear@0
|
89 {
|
nuclear@0
|
90 if(!state_fullscreen) {
|
nuclear@0
|
91 glutPositionWindow(x, y);
|
nuclear@0
|
92 }
|
nuclear@0
|
93 }
|
nuclear@0
|
94
|
nuclear@0
|
95 void window_position(int *xout, int *yout)
|
nuclear@0
|
96 {
|
nuclear@0
|
97 *xout = glutGet(GLUT_WINDOW_X);
|
nuclear@0
|
98 *yout = glutGet(GLUT_WINDOW_Y);
|
nuclear@0
|
99 }
|
nuclear@0
|
100
|
nuclear@0
|
101 void resize_window(int x, int y)
|
nuclear@0
|
102 {
|
nuclear@0
|
103 if(!state_fullscreen) {
|
nuclear@0
|
104 glutReshapeWindow(x, y);
|
nuclear@0
|
105 }
|
nuclear@0
|
106 }
|
nuclear@0
|
107
|
nuclear@0
|
108 void window_size(int *xout, int *yout)
|
nuclear@0
|
109 {
|
nuclear@0
|
110 *xout = win_width;
|
nuclear@0
|
111 *yout = win_height;
|
nuclear@0
|
112 }
|
nuclear@0
|
113
|
nuclear@0
|
114
|
nuclear@0
|
115 static void display()
|
nuclear@0
|
116 {
|
nuclear@0
|
117 game_draw();
|
nuclear@0
|
118 }
|
nuclear@0
|
119
|
nuclear@0
|
120 static void reshape(int x, int y)
|
nuclear@0
|
121 {
|
nuclear@0
|
122 win_width = x;
|
nuclear@0
|
123 win_height = y;
|
nuclear@0
|
124 game_reshape(x, y);
|
nuclear@0
|
125 }
|
nuclear@0
|
126
|
nuclear@0
|
127 static void key_press(unsigned char key, int x, int y)
|
nuclear@0
|
128 {
|
nuclear@0
|
129 game_keyboard(key, true);
|
nuclear@0
|
130 }
|
nuclear@0
|
131
|
nuclear@0
|
132 static void key_release(unsigned char key, int x, int y)
|
nuclear@0
|
133 {
|
nuclear@0
|
134 game_keyboard(key, false);
|
nuclear@0
|
135 }
|
nuclear@0
|
136
|
nuclear@0
|
137 static void mouse(int bn, int st, int x, int y)
|
nuclear@0
|
138 {
|
nuclear@0
|
139 game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
|
nuclear@0
|
140 }
|
nuclear@0
|
141
|
nuclear@0
|
142 static void motion(int x, int y)
|
nuclear@0
|
143 {
|
nuclear@0
|
144 game_mmotion(x, y);
|
nuclear@0
|
145 }
|
nuclear@0
|
146
|
nuclear@0
|
147 int using_glut;
|
nuclear@0
|
148 #else
|
nuclear@0
|
149 int not_using_glut;
|
nuclear@0
|
150 #endif
|