-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp.save
More file actions
390 lines (327 loc) · 8.8 KB
/
Copy pathmain.cpp.save
File metadata and controls
390 lines (327 loc) · 8.8 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/**#include <stdio.h>
#include <stdlib.h>
#include <math.h>**/
#include "Main.h"
#define DEFINE_EXTERNALS
#include "include.h"
/**#include <gl_inc_hs.h>
// angle of rotation for the camera direction
float angle = 0.0f;
// actual vector representing the camera's direction
float lx=0.0f,lz=-1.0f;
// XZ position of the camera
float x=0.0f, z=5.0f;
// the key states. These variables will be zero
// when no key is being pressesed
float deltaAngle = 0.0f;
float deltaMove = 0;
int xOrigin = -1;
// color for the snowman's nose
float red = 1.0f, blue=0.5f, green=0.5f;
// scale of snowman
float scale = 1.0f;
// default font
void *font = GLUT_STROKE_ROMAN;
// width and height of the window
int h,w;
// variables to compute frames per second
int frame;
long fpstime, timebase;
char s[60];
char currentMode[80];
// this string keeps the last good setting
// for the game mode
char gameModeString[40] = "640x480";
void drawSnowMan() {
glScalef(scale, scale, scale);
glColor3f(1.0f, 1.0f, 1.0f);
// Draw Body
glTranslatef(0.0f ,0.75f, 0.0f);
glutSolidSphere(0.75f,20,20);
// Draw Head
glTranslatef(0.0f, 1.0f, 0.0f);
glutSolidSphere(0.25f,20,20);
// Draw Eyes
glPushMatrix();
glColor3f(0.0f,0.0f,0.0f);
glTranslatef(0.05f, 0.10f, 0.18f);
glutSolidSphere(0.05f,10,10);
glTranslatef(-0.1f, 0.0f, 0.0f);
glutSolidSphere(0.05f,10,10);
glPopMatrix();
// Draw Nose
glColor3f(red, green, blue);
glRotatef(0.0f,1.0f, 0.0f, 0.0f);
glutSolidCone(0.08f,0.5f,10,2);
glColor3f(1.0f, 1.0f, 1.0f);
}
void renderBitmapString(
float x,
float y,
float z,
void *font,
char *string) {
char *c;
glRasterPos3f(x, y,z);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font, *c);
}
}
void renderStrokeFontString(
float x,
float y,
float z,
void *font,
char *string) {
char *c;
glPushMatrix();
glTranslatef(x, y,z);
glScalef(0.002f, 0.002f, 0.002f);
for (c=string; *c != '\0'; c++) {
glutStrokeCharacter(font, *c);
}
glPopMatrix();
}
void restorePerspectiveProjection() {
glMatrixMode(GL_PROJECTION);
// restore previous projection matrix
glPopMatrix();
// get back to modelview mode
glMatrixMode(GL_MODELVIEW);
}
void setOrthographicProjection() {
// switch to projection mode
glMatrixMode(GL_PROJECTION);
// save previous matrix which contains the
//settings for the perspective projection
glPushMatrix();
// reset matrix
glLoadIdentity();
// set a 2D orthographic projection
gluOrtho2D(0, w, h, 0);
// switch back to modelview mode
glMatrixMode(GL_MODELVIEW);
}
void computePos(float deltaMove) {
x += deltaMove * lx * 0.1f;
z += deltaMove * lz * 0.1f;
}
void renderScene(void) {
if (deltaMove)
computePos(deltaMove);
// Clear Color and Depth Buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Set the camera
gluLookAt( x, 1.0f, z,
x+lx, 1.0f, z+lz,
0.0f, 1.0f, 0.0f);
// Draw ground
glColor3f(0.9f, 0.9f, 0.9f);
glBegin(GL_QUADS);
glVertex3f(-100.0f, 0.0f, -100.0f);
glVertex3f(-100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, 100.0f);
glVertex3f( 100.0f, 0.0f, -100.0f);
glEnd();
// Draw 36 SnowMen
char number[3];
for(int i = -3; i < 3; i++)
for(int j=-3; j < 3; j++) {
glPushMatrix();
glTranslatef(i*10.0f, 0.0f, j * 10.0f);
drawSnowMan();
sprintf(number,"%d",(i+3)*6+(j+3));
renderStrokeFontString(0.0f, 0.5f, 0.0f, (void *)font ,number);
glPopMatrix();
}
// Code to compute frames per second
frame++;
fpstime=glutGet(GLUT_ELAPSED_TIME);
if (fpstime - timebase > 1000) {
sprintf(s,"Lighthouse3D - FPS:%4.2f",
frame*1000.0/(fpstime-timebase));
timebase = fpstime;
frame = 0;
}
setOrthographicProjection();
void *font= GLUT_BITMAP_8_BY_13;
glPushMatrix();
glLoadIdentity();
renderBitmapString(30,15,0,font,(char *)"GLUT Tutorial @ Lighthouse3D");
renderBitmapString(30,30,0,font,s);
renderBitmapString(30,45,0,font,(char *)"F1 - Game Mode 640x480 32 bits");
renderBitmapString(30,60,0,font,(char *)"F2 - Game Mode 800x600 32 bits");
renderBitmapString(30,75,0,font,(char *)"F3 - Game Mode 1024x768 32 bits");
renderBitmapString(30,90,0,font,(char *)"F4 - Game Mode 1280x1024 32 bits");
renderBitmapString(30,105,0,font,(char *)"F5 - Game Mode 1920x1200 32 bits");
renderBitmapString(30,120,0,font,(char *)"F6 - Window Mode");
renderBitmapString(30,135,0,font,(char *)"Esc - Quit");
renderBitmapString(30,150,0,font,currentMode);
glPopMatrix();
restorePerspectiveProjection();
glutSwapBuffers();
}
// -----------------------------------
// KEYBOARD
// -----------------------------------
void processNormalKeys(unsigned char key, int xx, int yy) {
switch (key) {
case 27:
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0)
glutLeaveGameMode();
exit(0);
break;
}
}
void pressKey(int key, int xx, int yy) {
switch (key) {
case GLUT_KEY_UP : deltaMove = 0.5f; break;
case GLUT_KEY_DOWN : deltaMove = -0.5f; break;
case GLUT_KEY_F1:
// define resolution, color depth
glutGameModeString("640x480:32");
// enter full screen
if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
glutEnterGameMode();
sprintf(gameModeString,"640x480:32");
// register callbacks again
// and init OpenGL context
init();
}
else
glutGameModeString(gameModeString);
break;
case GLUT_KEY_F2:
// define resolution, color depth
glutGameModeString("800x600:32");
// enter full screen
if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
glutEnterGameMode();
sprintf(gameModeString,"800x600:32");
// register callbacks again
// and init OpenGL context
init();
}
else
glutGameModeString(gameModeString);
break;
case GLUT_KEY_F3:
// define resolution, color depth
glutGameModeString("1024x768:32");
// enter full screen
if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
glutEnterGameMode();
sprintf(gameModeString,"1024x768:32");
// register callbacks again
// and init OpenGL context
init();
}
else
glutGameModeString(gameModeString);
break;
case GLUT_KEY_F4:
// define resolution, color depth
glutGameModeString("1280x1024:32");
// enter full screen
if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
glutEnterGameMode();
sprintf(gameModeString,"1280x1024:32");
// register callbacks again
// and init OpenGL context
init();
}
else
glutGameModeString(gameModeString);
break;
case GLUT_KEY_F5:
// define resolution, color depth
glutGameModeString("1920x1200");
// enter full screen
if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
glutEnterGameMode();
sprintf(gameModeString,"1920x1200");
// register callbacks again
// and init OpenGL context
init();
}
else
glutGameModeString(gameModeString);
break;
case GLUT_KEY_F6:
// return to default window
w = 800;h = 600;
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0) {
glutLeaveGameMode();
//init();
}
break;
}
if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) == 0)
sprintf(currentMode,"Current Mode: Window");
else
sprintf(currentMode,
"Current Mode: Game Mode %dx%d at %d hertz, %d bpp",
glutGameModeGet(GLUT_GAME_MODE_WIDTH),
glutGameModeGet(GLUT_GAME_MODE_HEIGHT),
glutGameModeGet(GLUT_GAME_MODE_REFRESH_RATE),
glutGameModeGet(GLUT_GAME_MODE_PIXEL_DEPTH));
}
void releaseKey(int key, int x, int y) {
switch (key) {
case GLUT_KEY_UP :
case GLUT_KEY_DOWN : deltaMove = 0;break;
}
}
// -----------------------------------
// MOUSE
// -----------------------------------
void mouseMove(int x, int y) {
// this will only be true when the left button is down
if (xOrigin >= 0) {
// update deltaAngle
deltaAngle = (x - xOrigin) * 0.001f;
// update camera's direction
lx = sin(angle + deltaAngle);
lz = -cos(angle + deltaAngle);
}
}
void mouseButton(int button, int state, int x, int y) {
// only start motion if the left button is pressed
if (button == GLUT_LEFT_BUTTON) {
// when the button is released
if (state == GLUT_UP) {
angle += deltaAngle;
xOrigin = -1;
}
else {// state = GLUT_DOWN
xOrigin = x;
}
}
}
// -----------------------------------
// MAIN
// -----------------------------------
**/
int main(int argc, char **argv) {
PRINT_TRANSLATION_FAILURES = false;
std::vector<std::string> v;
for(int i = 1; i < argc; i++)
{
v.push_back(argv[i]);
}
App.path = S(argv[0]);
std::string relPath = App.path.substr(0, App.path.size()-App.command.size()-1);
char absPath[PATH_MAX+1];
realpath(relPath.c_str(), absPath);
App.executionPath = S(absPath);
Config::init(App.config);
File::Folder f(App.basePath);
f.enter(Config::files[0].at(App.command).at(S("LanguageBaseLocation")).valueSTRING());
Language::init(&f, new Config);
PRINT_TRANSLATION_FAILURES = true;
Commands::init();
Main main(v);
return __return;
}