public
Description: sole's demoscene projects
Homepage: http://soledadpenades.com/tag/demoscene/
Clone URL: git://github.com/sole/demoscene.git
demoscene / releases / ppg / ppg_01_sotg / src / main.cpp
100644 468 lines (381 sloc) 10.104 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
/**
 
"PPG01: Scene of the girls"
A joke prod!
 
Start date 20030803
Released 20031102
Source released 20090629
 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
Copyright 2003-2009 Soledad Penades http://soledadpenades.com
This file is part of ppg01_sotg
ppg01_sotg is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3 only, as published
by the Free Software Foundation.
ppg01_sotg is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ppg01_sotg. If not, see <http://www.gnu.org/licenses/>.
*/
 
#include <stdlib.h>
#if defined(_MSC_VER)
#include "SDL.h"
#include "SDL_opengl.h"
#else
#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"
#endif
 
#include <getopt.h>
#include <math.h>
 
#include "scenes.h"
#include "math3D.h"
#include "Music.h"
#include "textures.h"
#include "Demo.h"
#include "SOIL/SOIL.h"
 
#define VANCHO 50
#define VALTO 50
#define TAM (4*(VANCHO+1)*(VALTO+1))
 
Music miMusic;
Demo *miDemo;
int multiSampling;
int multiSamplingBuffers;
int startOrder;
int startRow;
 
float t0;
float angulo=0;
bool active=true;
 
SDL_Surface *screen;
Uint32 flags;
 
void loader(float porcentaje) {
// Es muy OB_VIOOO, dibuja una barra proporcional al porcentaje
// Tan simple que da risa
// Eso si, porcentaje debe ser 0..100
 
glViewport(0,0,(GLsizei) 640 ,(GLsizei) 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(1,0.0,0.0,0);
glClear(GL_COLOR_BUFFER_BIT);
 
glFrustum(-1.0,1.0,-1.0,1.0,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1,1,1);
 
ponOrtopedico(110,10);
 
glColor3f(0.6,0.0,0.0);
glLineWidth(2.0);
glBegin(GL_LINE_LOOP);
glVertex3f(-50.5,-0.1,0);
glVertex3f(50.5,-0.1,0);
glVertex3f(50.5,0.3,0);
glVertex3f(-50.5,0.3,0);
 
glEnd();
 
 
float ancho=porcentaje;
float alto=0.2;
 
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,1,porcentaje/100);
glBegin(GL_QUADS);
glVertex3f(-50,0,0);
glVertex3f(-50+ancho,0,0);
glVertex3f(-50+ancho,alto,0);
glVertex3f(-50,alto,0);
 
glEnd();
glDisable(GL_BLEND);
quitaOrtopedico();
glFlush();
SDL_GL_SwapBuffers();
}
 
int init(void) {
printf(" ___ \n"
" / / ______ __ __\n"
" / / / __ / / \\_/ \\ ____\n"
" ___/ / / /_/ / / /\\ /\\ \\_/ __ \\\n"
" / __ / / ____/ / / \\_/ \\ /_/ /\n"
"/ /_/ /__/ /_____/ / \\_____/\n"
"\\_________________/\n"
);
printf("D.E.M.O. (Discrete Effort to Merely Outstand) v0.1 by Sole\n");
printf("Now loading SOTG\n");
glClearColor(0.10,0.10,0.0,1.0);
glShadeModel(GL_FLAT);
printf("Precalc::trigtables\n");
loader(0);
prepareTables();
setCurrentHeight(HEIGHT);
setCurrentWidth(WIDTH);
printf("Initializing sound...\n");
int musicrdo=miMusic.initSound();
if(musicrdo>=0) {
printf("Loading music...\n");
loader(10);
miMusic.loadMod("./data/mysotg.it");
printf("Initializing scenes...\n");
loader(40);
initScenes();
loader(60);
printf("Wait...\n");
 
for(int kaka=61;kaka<100;kaka++) {
loader((float)kaka);
}
 
} else {
return(-1);
}
return(1);
}
 
void finish(void)
{
 
printf("Freeing sound\n");
miMusic.freeSound();
 
printf("Freeing more data...\n");
finishScenes();
 
SDL_Quit();
 
exit(0);
}
 
int display(void) {
 
int pattern,row;
float musicSeconds;
float fft[512];
 
glClear(GL_COLOR_BUFFER_BIT);
if(!miMusic.isPlaying())
{
miMusic.playSound();
miMusic.playMod();
miMusic.setPos(startOrder, startRow);
}
 
miMusic.syncro();
pattern=miMusic.getPattern();
row=miMusic.getRow();
musicSeconds = miMusic.getSeconds();
 
if(miMusic.hasFinished())
{
return 0;
}
 
// Lanzo las escenas segun corresponda
switch(pattern) {
// Patron 0, escena del simbolo femenino ;)
case 0: sceneSimbolo(row);
break;
// Patron 1, los latidos donde sale 'scene of the girls'
case 1: sceneLatidos(row);
break;
// Círculos y créditos
case 2: sceneCircles(row);
break;
case 3: sceneRotante(row, musicSeconds);
break;
case 4: sceneRotante2(row, musicSeconds);
break;
case 5: scene4segundos(row);
break;
case 6:
case 7: miMusic.getFFT(fft,512);
sceneSurfaceBlur(miMusic.getPattern(), row, musicSeconds, fft);
break;
case 8:
case 9: sceneDiscos2(row, musicSeconds);
break;
case 10:
case 11:
case 12:
case 13:sceneDiscos3(row, musicSeconds);
break;
default:
return(0);
break;
}
 
return(1);
 
}
 
void list_modes()
{
SDL_Rect** modes;
int i;
 
modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
 
if (modes == (SDL_Rect**)0)
{
fprintf(stdout, "No modes available!\n");
exit(-1);
}
 
if (modes == (SDL_Rect**)-1)
{
fprintf(stdout, "All resolutions available.\n");
exit(0);
}
else
{
printf("Available Fullscreen Modes\n");
for (i=0; modes[i]; ++i)
{
fprintf(stdout, "%dx%d\n", modes[i]->w, modes[i]->h);
}
 
exit(1);
}
 
}
 
void parse_arguments(int argc, char*argv[], int *width, int *height, int *fullscreen, int *multiSampling, int *multiSamplingBuffers, int *order, int *row)
{
int option_index = 0, c;
 
// Set some defaults to begin with
*fullscreen = 0;
*width = 640;
*height = 480;
*multiSampling = 0;
*multiSamplingBuffers = 4;
*order = 0;
*row = 0;
 
static struct option long_options[] =
{
{"fullscreen", no_argument, fullscreen, 1},
{"width", required_argument, NULL, 'w'},
{"height", required_argument, NULL, 'h'},
{"antialias", no_argument, multiSampling, 1},
{"antialias-samples", required_argument, NULL, 'a'},
{"start-order", required_argument, NULL, 'o'},
{"start-row", required_argument, NULL, 'r'},
{"list-modes", no_argument, NULL, 'l'},
{"help", no_argument, NULL, '?'},
{0, 0, 0, 0}
};
 
while(1)
{
c = getopt_long (argc, argv, "w:h:o:r:l", long_options, &option_index);
 
if(c == -1) { break; }
 
switch (c)
{
case 'w':
*width = atoi((char*)optarg);
break;
 
case 'h':
*height = atoi((char*)optarg);
break;
 
case 'a':
*multiSamplingBuffers = atoi((char*)optarg);
break;
 
case 'o':
*order = atoi((char*)optarg);
break;
 
case 'r':
*row = atoi((char*)optarg);
break;
 
case 'l':
list_modes();
break;
 
case '?':
printf("Usage:\n"
"%s [options]\n\n"
"where options is one or more of the following:\n\n"
"-w, --width WIDTH: screen width in pixels (default=640)\n"
"-h, --height HEIGHT: screen height in pixels (default=480)\n"
"--fullscreen: use fullscreen (default=no)\n"
"--antialias: use antialias (default=no)\n"
"--antialias-samples: how many antialias samples to use (default=4)\n"
"-o, --start-order ORDER: begin playing at order number ORDER (default=0)\n"
"-r, --start-row ROW: begin playing at row number ROW (default=0)\n"
"-l, --list-modes: show available accelerated fullscreen size combinations\n"
"-?, --help: show this message\n"
, argv[0]);
exit(0);
}
    }
}
 
void save_screenshot(int width, int height)
{
float ms = miMusic.getMilliseconds();
char filename[255];
sprintf(filename, "screenshot-%05d.bmp", (int)ms);
 
int save_result = SOIL_save_screenshot
(
filename,
SOIL_SAVE_TYPE_BMP,
0, 0, width, height
);
 
if(save_result)
{
printf("Screenshot saved to %s\n", filename);
}
 
}
 
// Entry point
int main(int argc, char *argv[])
{
int width, height, fullscreen;
 
// Initialize SDL's subsystems
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
 
// Parse command line parameters
parse_arguments(argc, argv, &width, &height, &fullscreen, &multiSampling, &multiSamplingBuffers, &startOrder, &startRow);
 
// printf("Using width = %d, height = %d, fullscreen = %d\nstart order = %d, row = %d\n", width, height, fullscreen, startOrder, startRow);
 
atexit(finish);
 
 
    
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
 
 
flags = SDL_OPENGL;
 
if(fullscreen)
{
flags |= SDL_FULLSCREEN;
}
 
if(multiSampling)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, true);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, multiSamplingBuffers);
}
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);//vsync, SDL manual says it's on by default but I highly doubt it
 
// Attempt to create the opengl window with 32bit pixels.
screen = SDL_SetVideoMode(width, height, 32, flags);
 
// If we fail, return error.
if ( screen == NULL )
{
fprintf(stderr, "Unable to set %dx%d opengl video (fullscreen = %d, antialias samples = %d): %s\n", width, height, fullscreen, multiSamplingBuffers, SDL_GetError());
list_modes();
exit(1);
}
 
SDL_ShowCursor(SDL_DISABLE);
 
miDemo = new Demo(width, height);
init();
 
// Main loop: loop forever.
while (display())
{
// Render stuff
;
 
SDL_GL_SwapBuffers();
 
// Poll for events, and handle the ones we care about.
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_KEYUP:
// If escape is pressed, return (and thus, quit)
if (event.key.keysym.sym == SDLK_ESCAPE)
{
return 0;
}
 
if(event.key.keysym.sym == SDLK_RIGHT)
{
miMusic.setPos(miMusic.getPattern() + 1, 0);
break;
}
 
if(event.key.keysym.sym == SDLK_LEFT)
{
int prev = miMusic.getPattern() - 1;
if(prev < 0) prev = 0;
miMusic.setPos(prev, 0);
break;
}
 
if(event.key.keysym.sym == SDLK_s)
{
save_screenshot(width, height);
break;
}
 
break;
case SDL_QUIT:
return(0);
}
}
}
return 0;
}