-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
109 lines (89 loc) · 2.09 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* GLUT main app for things.
*/
#include "tools.h"
#include "game.h"
// Global status things.
int key[256];
int specialKey[256];
// Key press handler, normal keys.
void handleKeypress( unsigned char k, int x, int y ) {
key[ k ] = 1;
// Some special cases.
switch( k ) {
case 27: // Escape
exit( 0 );
case 'p': // Neat for debugging
sleep( 1 );
break;
}
}
void handleKeyUp( unsigned char k, int x, int y ) {
key[ k ] = 0;
}
// Key press handler, special keys.
void handleSpecialKeypress( int k, int x, int y ) {
specialKey[ k ] = 1;
}
void handleSpecialUp( int k, int x, int y ) {
specialKey[ k ] = 0;
}
// Resize handler.
void handleResize(int w, int h) {
glViewport( 0, 0, w, h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0, (float)w / (float)h, 1.0, 200.0 );
}
// Scene drawing
void drawScene() {
gameDraw();
glutSwapBuffers();
}
// Called every 10 milliseconds to update things on screen
void update(int value) {
if( gameUpdate() ) {
gameCleanup();
exit( 1 );
}
glutPostRedisplay();
glutTimerFunc( 10, update, 0 );
}
// Initialization functions.
void initOGL(int argc, char** argv) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
// Build modestring.
char tmpString[255];
char modeString[255];
modeString[0] = 0;
itoa( (int)screenHeight, tmpString, 10 );
strcat( modeString, tmpString );
strcat( modeString, "x" );
itoa( (int)screenWidth, tmpString, 10 );
strcat( modeString, tmpString );
strcat( modeString, ":24" );
glutGameModeString( modeString );
glutEnterGameMode();
// Alternative: Windowed.
//glutCreateWindow("Fages");
glewInit();
}
void initFunctions() {
memset( key, 0, 256 );
memset( specialKey, 0, 256 );
glutDisplayFunc( drawScene );
glutKeyboardFunc( handleKeypress );
glutKeyboardUpFunc( handleKeyUp );
glutSpecialFunc( handleSpecialKeypress );
glutSpecialUpFunc( handleSpecialUp );
glutReshapeFunc( handleResize );
glutTimerFunc( 10, update, 0 );
}
int main(int argc, char** argv) {
initOGL( argc, argv );
initFunctions();
gameInit();
glutMainLoop();
return 0;
}