-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathe.c
1534 lines (1375 loc) · 51.6 KB
/
e.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
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Endeavor by Team210 - 64k intro by Team210 at Revision 2k19
* Copyright (C) 2018 Alexander Kraus <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
// define this to get some extra bytes
//#define SUPER_SMALL
// WIN32 code
const char *demoname = "Endeavour/Team210";
unsigned int muted = 0.;
int _fltused = 0;
#define ABS(x) ((x)<0?(-x):(x))
#define sign(x) ((x)<0?-1.:1.)
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include <windows.h>
#include "commctrl.h"
#include <mmsystem.h>
#include <Mmreg.h>
#include <GL/gl.h>
#include "glext.h"
// Standard library and CRT rewrite for saving executable size
void *memset(void *ptr, int value, size_t num)
{
for(int i=num-1; i>=0; i--)
((unsigned char *)ptr)[i] = value;
return ptr;
}
size_t strlen(const char *str)
{
int len = 0;
while(str[len] != '\0') ++len;
return len;
}
void *malloc( unsigned int size )
{
return GlobalAlloc(GMEM_ZEROINIT, size) ;
}
// TODO: remove
// #include <stdio.h>
//
// #include <math.h>
#include "sequence.h"
// OpenGL extensions
PFNGLGETPROGRAMIVPROC glGetProgramiv;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
PFNGLCREATESHADERPROC glCreateShader;
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORM2FPROC glUniform2f;
PFNGLUNIFORM1FPROC glUniform1f;
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
PFNGLNAMEDRENDERBUFFERSTORAGEEXTPROC glNamedRenderbufferStorageEXT;
PFNGLUNIFORM1IPROC glUniform1i;
PFNGLACTIVETEXTUREPROC glActiveTexture;
// // TODO: remove below
// void //debug(int shader_handle)
// {
// //printf(" Debugging shader with handle %d.\n", shader_handle);
// int compile_status = 0;
// glGetShaderiv(shader_handle, GL_COMPILE_STATUS, &compile_status);
// if(compile_status != GL_TRUE)
// {
// //printf(" FAILED.\n");
// GLint len;
// glGetShaderiv(shader_handle, GL_INFO_LOG_LENGTH, &len);
// //printf(" Log length: %d\n", len);
// GLchar *CompileLog = (GLchar*)malloc(len*sizeof(GLchar));
// glGetShaderInfoLog(shader_handle, len, NULL, CompileLog);
// //printf(" Error messages:\n%s\n", CompileLog);
// free(CompileLog);
// }
// else
// //printf(" Shader compilation successful.\n");
// }
//
// void //debugp(int program)
// {
// //printf(" Debugging program.\n");
// int compile_status = 0;
// glGetProgramiv(program, GL_LINK_STATUS, &compile_status);
// if(compile_status != GL_TRUE)
// {
// //printf(" FAILED.\n");
// GLint len;
// glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len);
// //printf(" Log length: %d\n", len);
// GLchar *CompileLog = (GLchar*)malloc(len*sizeof(GLchar));
// glGetProgramInfoLog(program, len, NULL, CompileLog);
// //printf(" Error messages:\n%s\n", CompileLog);
// free(CompileLog);
// }
// else
// //printf(" Program linking successful.\n");
// }
// // TODO: remove above
// Graphics shader globals
int w = 1920, h = 1080,
gfx_handle, gfx_program,
time_location, resolution_location,
font_texture_location, font_width_location,
sfx_program, sfx_handle, sfx_blockoffset_location,
sfx_samplerate_location, sfx_volumelocation,
sfx_texs_location,
sfx_sequence_texture_location, sfx_sequence_width_location,
gfx_sequence_texture_location, gfx_sequence_width_location,
gfx_executable_size_location,
load_program, load_resolution_location, load_time_location,
load_progress_location,
post_program, post_resolution_location, post_fsaa_location,
post_channel0_location,
fsaa = 25, txaa = 1,
gfx_fsaa_location, gfx_txaa_location,
logo210_time_location, logo210_resolution_location,
logo210_program, logo210_handle,
greet_time_location, greet_resolution_location,
greet_program, greet_handle,
text_time_location, text_resolution_location,
text_font_width_location, text_executable_size_location,
text_channel0_location, text_font_location,
text_program, text_handle,
logo_small_handle, logo_small_program,
logo_small_time_location, logo_small_resolution_location,
nr4_handle,nr4_program,
nr4_time_location, nr4_resolution_location,
qm_handle,qm_program,
qm_time_location, qm_resolution_location,
trip_handle, trip_program,
trip_time_location, trip_resolution_location,
surface_handle, surface_program,
surface_time_location, surface_resolution_location,
hangout_handle, hangout_program,
hangout_time_location, hangout_resolution_location,
fourtwenty_handle, fourtwenty_program,
fourtwenty_time_location, fourtwenty_resolution_location,
solskogen_handle, solskogen_program,
solskogen_time_location, solskogen_resolution_location;
float font_texture_width;
// Demo globals
#define duration 188.
double t_start = 0.,
t_now = 0.,
t_end = duration;
unsigned int font_texture_handle, sequence_texture_handle;
float executable_size = 0.;
unsigned int loading = 1, music_loading = 0;
int music_block = 0;
unsigned int snd_framebuffer;
unsigned int scene_override = 0, override_index = 0;
// Music shader globals
int sample_rate = 44100, channels = 2;
double duration1 = duration; //3 min running time
float *smusic1;
int music1_size;
float texs = 128;
int block_size = 128*128,
nblocks1;
unsigned int paused = 0;
float progress = .0;
HWAVEOUT hWaveOut;
WAVEHDR silence_header = {0, 0, 0, 0, 0, 0, 0, 0 };
double t_paused;
HANDLE load_music_thread;
DWORD load_music_thread_id;
HANDLE load_gfx_thread;
DWORD load_gfx_thread_id;
GLuint first_pass_framebuffer = 0, first_pass_texture;
HDC hdc;
HGLRC glrc;
GLenum error;
#define NSHADERS 13.
float t_load_end = 0.;
// FFT related stuff
float PI = 3.14159265359;
// typedef struct
// {
// float re,im;
// } complex;
//
// const complex I = { 0.,1. };
// float WINDOW = 256;
//
// complex mul(complex f1, complex f2)
// {
// complex ret = { f1.re*f2.re - f1.im*f2.im, f1.re*f2.im+f1.im*f2.re };
// return ret;
// }
//
// complex add(complex f1, complex f2)
// {
// complex ret = { f1.re + f2.re, f1.im + f2.im };
// return ret;
// }
//
// complex sub(complex f1, complex f2)
// {
// complex ret = { f1.re-f2.re, f1.im - f2.im };
// return ret;
// }
//
// complex cexp(complex arg)
// {
// float f = exp(arg.re);
// complex ret = { f*cos(arg.im), f*sin(arg.im) };
// return ret;
// }
//
// // Radix-2 from Wikipedia
// void genFFT(complex *src, complex * dst, int N, int stride)
// {
// if(N==1)
// dst[0] = src[0];
// else
// {
// genFFT(dst, dst, N/2, 2*stride);
// genFFT(dst+N/2, dst, N/2, 2*stride);
// for(int k=0; k<N/2; k += stride)
// {
// complex t = dst[k],
// arg = { 0., -2.*PI*k/N };
// arg = cexp(arg);
// dst[k] = add(t, mul(arg, dst[k+N/2]));
// dst[k+N/2] = sub(t, mul(arg, dst[k+N/2]));
// }
// }
// }
DWORD WINAPI LoadMusicThread( LPVOID lpParam)
{
#undef VAR_IBLOCKOFFSET
#undef VAR_ISAMPLERATE
#undef VAR_IVOLUME
#undef VAR_ITEXSIZE
#undef VAR_ISEQUENCE
#undef VAR_ISEQUENCEWIDTH
#include "sfx.h"
#ifndef VAR_IVOLUME
#define VAR_IVOLUME "iVolume"
#endif
#ifndef VAR_ISAMPLERATE
#define VAR_ISAMPLERATE "iSampleRate"
#endif
#ifndef VAR_IBLOCKOFFSET
#define VAR_IBLOCKOFFSET "iBlockOffset"
#endif
#ifndef VAR_ITEXSIZE
#define VAR_ITEXSIZE "iTexSize"
#endif
#ifndef VAR_ISEQUENCE
#define VAR_ISEQUENCE "iSequence"
#endif
#ifndef VAR_ISEQUENCEWIDTH
#define VAR_ISEQUENCEWIDTH "iSequenceWidth"
#endif
int sfx_size = strlen(sfx_frag),
sfx_handle = glCreateShader(GL_FRAGMENT_SHADER);
sfx_program = glCreateProgram();
glShaderSource(sfx_handle, 1, (GLchar **)&sfx_frag, &sfx_size);
glCompileShader(sfx_handle);
//printf("---> SFX shader:\n");
//debug(sfx_handle);
glAttachShader(sfx_program, sfx_handle);
glLinkProgram(sfx_program);
//printf("---> SFX program:\n");
//debugp(sfx_program);
glUseProgram(sfx_program);
sfx_samplerate_location = glGetUniformLocation(sfx_program, VAR_ISAMPLERATE);
sfx_blockoffset_location = glGetUniformLocation(sfx_program, VAR_IBLOCKOFFSET);
sfx_volumelocation = glGetUniformLocation(sfx_program, VAR_IVOLUME);
sfx_texs_location = glGetUniformLocation(sfx_program, VAR_ITEXSIZE);
sfx_sequence_texture_location = glGetUniformLocation(sfx_program, VAR_ISEQUENCE);
sfx_sequence_width_location = glGetUniformLocation(sfx_program, VAR_ISEQUENCEWIDTH);
//printf("++++ SFX shader created.\n");
music_loading = 1;
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadLogo210Thread( LPVOID lpParam)
{
// Load gfx shader
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/logo210.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int logo210_size = strlen(logo210_frag),
logo210_handle = glCreateShader(GL_FRAGMENT_SHADER);
logo210_program = glCreateProgram();
glShaderSource(logo210_handle, 1, (GLchar **)&logo210_frag, &logo210_size);
glCompileShader(logo210_handle);
//printf("---> Logo 210 shader:\n");
//debug(logo210_handle);
glAttachShader(logo210_program, logo210_handle);
glLinkProgram(logo210_program);
//printf("---> Logo 210 program:\n");
//debugp(logo210_program);
glUseProgram(logo210_program);
logo210_time_location = glGetUniformLocation(logo210_program, VAR_ITIME);
logo210_resolution_location = glGetUniformLocation(logo210_program, VAR_IRESOLUTION);
//printf("++++ Logo 210 shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadGreetThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/greet.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int greet_size = strlen(greet_frag),
greet_handle = glCreateShader(GL_FRAGMENT_SHADER);
greet_program = glCreateProgram();
glShaderSource(greet_handle, 1, (GLchar **)&greet_frag, &greet_size);
glCompileShader(greet_handle);
//printf("---> Greetings shader:\n");
//debug(greet_handle);
glAttachShader(greet_program, greet_handle);
glLinkProgram(greet_program);
//printf("---> Greetings program:\n");
//debugp(greet_program);
glUseProgram(greet_program);
greet_time_location = glGetUniformLocation(greet_program, VAR_ITIME);
greet_resolution_location = glGetUniformLocation(greet_program, VAR_IRESOLUTION);
//printf("++++ Greetings shader created.\n");
progress += .5/NSHADERS;
return 0;
}
#include "font/font.h"
DWORD WINAPI LoadTextThread(LPVOID lpParam)
{
#undef VAR_IFONTWIDTH
#undef VAR_IEXECUTABLESIZE
#undef VAR_IRESOLUTION
#undef VAR_ICHANNEL0
#undef VAR_IFONT
#undef VAR_ITIME
#include "gfx/text.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
#ifndef VAR_IFONT
#define VAR_IFONT "iFont"
#endif
#ifndef VAR_IFONTWIDTH
#define VAR_IFONTWIDTH "iFontWidth"
#endif
#ifndef VAR_IEXECUTABLESIZE
#define VAR_IEXECUTABLESIZE "iExecutableSize"
#endif
#ifndef VAR_ICHANNEL0
#define VAR_ICHANNEL0 "iChannel0"
#endif
int text_size = strlen(text_frag);
text_handle = glCreateShader(GL_FRAGMENT_SHADER);
text_program = glCreateProgram();
glShaderSource(text_handle, 1, (GLchar **)&text_frag, &text_size);
glCompileShader(text_handle);
//printf("---> Text shader:\n");
//debug(text_handle);
glAttachShader(text_program, text_handle);
glLinkProgram(text_program);
//printf("---> Text program:\n");
//debugp(text_program);
glUseProgram(text_program);
text_time_location = glGetUniformLocation(text_program, VAR_ITIME);
text_resolution_location = glGetUniformLocation(text_program, VAR_IRESOLUTION);
text_font_location= glGetUniformLocation(text_program, VAR_IFONT);
text_font_width_location = glGetUniformLocation(text_program, VAR_IFONTWIDTH);
text_executable_size_location = glGetUniformLocation(text_program, VAR_IEXECUTABLESIZE);
text_channel0_location = glGetUniformLocation(text_program, VAR_ICHANNEL0);
//printf("++++ Text shader created.\n");
// Initialize font texture
//printf("font texture width is: %d\n", font_texture_size); // TODO: remove
glGenTextures(1, &font_texture_handle);
glBindTexture(GL_TEXTURE_2D, font_texture_handle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, font_texture_size, font_texture_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, font_texture);
font_texture_width = font_texture_size;
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadLogoSmallThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/logosmall.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int logo_small_size = strlen(logosmall_frag),
logo_small_handle = glCreateShader(GL_FRAGMENT_SHADER);
logo_small_program = glCreateProgram();
glShaderSource(logo_small_handle, 1, (GLchar **)&logosmall_frag, &logo_small_size);
glCompileShader(logo_small_handle);
//printf("---> Endeavour logo shader:\n");
//debug(logo_small_handle);
glAttachShader(logo_small_program, logo_small_handle);
glLinkProgram(logo_small_program);
//printf("---> Endeavour logo program:\n");
//debugp(logo_small_program);
glUseProgram(logo_small_program);
logo_small_time_location = glGetUniformLocation(logo_small_program, VAR_ITIME);
logo_small_resolution_location = glGetUniformLocation(logo_small_program, VAR_IRESOLUTION);
//printf("++++ Endeavour logo shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadNr4Thread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/nr4.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int nr4_size = strlen(nr4_frag),
nr4_handle = glCreateShader(GL_FRAGMENT_SHADER);
nr4_program = glCreateProgram();
glShaderSource(nr4_handle, 1, (GLchar **)&nr4_frag, &nr4_size);
glCompileShader(nr4_handle);
//printf("---> Endeavour NR4 shader:\n");
//debug(nr4_handle);
glAttachShader(nr4_program, nr4_handle);
glLinkProgram(nr4_program);
//printf("---> Endeavour NR4 program:\n");
//debugp(nr4_program);
glUseProgram(nr4_program);
nr4_time_location = glGetUniformLocation(nr4_program, VAR_ITIME);
nr4_resolution_location = glGetUniformLocation(nr4_program, VAR_IRESOLUTION);
//printf("++++ Endeavour NR4 shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadQMThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/qm.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int qm_size = strlen(qm_frag),
qm_handle = glCreateShader(GL_FRAGMENT_SHADER);
qm_program = glCreateProgram();
glShaderSource(qm_handle, 1, (GLchar **)&qm_frag, &qm_size);
glCompileShader(qm_handle);
//printf("---> Endeavour QM shader:\n");
//debug(qm_handle);
glAttachShader(qm_program, qm_handle);
glLinkProgram(qm_program);
//printf("---> Endeavour QM program:\n");
//debugp(qm_program);
glUseProgram(qm_program);
qm_time_location = glGetUniformLocation(qm_program, VAR_ITIME);
qm_resolution_location = glGetUniformLocation(qm_program, VAR_IRESOLUTION);
//printf("++++ Endeavour QM shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadTripThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/trip.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int trip_size = strlen(trip_frag),
trip_handle = glCreateShader(GL_FRAGMENT_SHADER);
trip_program = glCreateProgram();
glShaderSource(trip_handle, 1, (GLchar **)&trip_frag, &trip_size);
glCompileShader(trip_handle);
//printf("---> Endeavour Trip shader:\n");
//debug(trip_handle);
glAttachShader(trip_program, trip_handle);
glLinkProgram(trip_program);
//printf("---> Endeavour Trip program:\n");
//debugp(trip_program);
glUseProgram(trip_program);
trip_time_location = glGetUniformLocation(trip_program, VAR_ITIME);
trip_resolution_location = glGetUniformLocation(trip_program, VAR_IRESOLUTION);
//printf("++++ Endeavour Trip shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadSurfaceThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/surface.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int surface_size = strlen(surface_frag),
surface_handle = glCreateShader(GL_FRAGMENT_SHADER);
surface_program = glCreateProgram();
glShaderSource(surface_handle, 1, (GLchar **)&surface_frag, &surface_size);
glCompileShader(surface_handle);
//printf("---> Endeavour surface shader:\n");
//debug(surface_handle);
glAttachShader(surface_program, surface_handle);
glLinkProgram(surface_program);
//printf("---> Endeavour surface program:\n");
//debugp(surface_program);
glUseProgram(surface_program);
surface_time_location = glGetUniformLocation(surface_program, VAR_ITIME);
surface_resolution_location = glGetUniformLocation(surface_program, VAR_IRESOLUTION);
//printf("++++ Endeavour surface shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadHangoutThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/hangout.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int hangout_size = strlen(hangout_frag),
hangout_handle = glCreateShader(GL_FRAGMENT_SHADER);
hangout_program = glCreateProgram();
glShaderSource(hangout_handle, 1, (GLchar **)&hangout_frag, &hangout_size);
glCompileShader(hangout_handle);
//printf("---> Endeavour hangout shader:\n");
//debug(hangout_handle);
glAttachShader(hangout_program, hangout_handle);
glLinkProgram(hangout_program);
//printf("---> Endeavour hangout program:\n");
//debugp(hangout_program);
glUseProgram(hangout_program);
hangout_time_location = glGetUniformLocation(hangout_program, VAR_ITIME);
hangout_resolution_location = glGetUniformLocation(hangout_program, VAR_IRESOLUTION);
//printf("++++ Endeavour hangout shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadFourtwentyThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/fourtwenty.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int fourtwenty_size = strlen(fourtwenty_frag),
fourtwenty_handle = glCreateShader(GL_FRAGMENT_SHADER);
fourtwenty_program = glCreateProgram();
glShaderSource(fourtwenty_handle, 1, (GLchar **)&fourtwenty_frag, &fourtwenty_size);
glCompileShader(fourtwenty_handle);
//printf("---> Endeavour fourtwenty shader:\n");
//debug(fourtwenty_handle);
glAttachShader(fourtwenty_program, fourtwenty_handle);
glLinkProgram(fourtwenty_program);
//printf("---> Endeavour fourtwenty program:\n");
//debugp(fourtwenty_program);
glUseProgram(fourtwenty_program);
fourtwenty_time_location = glGetUniformLocation(fourtwenty_program, VAR_ITIME);
fourtwenty_resolution_location = glGetUniformLocation(fourtwenty_program, VAR_IRESOLUTION);
//printf("++++ Endeavour fourtwenty shader created.\n");
progress += .5/NSHADERS;
return 0;
}
DWORD WINAPI LoadSolskogenThread( LPVOID lpParam)
{
#undef VAR_IRESOLUTION
#undef VAR_ITIME
#include "gfx/solskogen.h"
#ifndef VAR_IRESOLUTION
#define VAR_IRESOLUTION "iResolution"
#endif
#ifndef VAR_ITIME
#define VAR_ITIME "iTime"
#endif
int solskogen_size = strlen(solskogen_frag),
solskogen_handle = glCreateShader(GL_FRAGMENT_SHADER);
solskogen_program = glCreateProgram();
glShaderSource(solskogen_handle, 1, (GLchar **)&solskogen_frag, &solskogen_size);
glCompileShader(solskogen_handle);
//printf("---> Endeavour solskogen shader:\n");
//debug(solskogen_handle);
glAttachShader(solskogen_program, solskogen_handle);
glLinkProgram(solskogen_program);
//printf("---> Endeavour solskogen program:\n");
//debugp(solskogen_program);
glUseProgram(solskogen_program);
solskogen_time_location = glGetUniformLocation(solskogen_program, VAR_ITIME);
solskogen_resolution_location = glGetUniformLocation(solskogen_program, VAR_IRESOLUTION);
//printf("++++ Endeavour solskogen shader created.\n");
progress += .5/NSHADERS;
return 0;
}
void quad()
{
glBegin(GL_QUADS);
glVertex3f(-1,-1,0);
glVertex3f(-1,1,0);
glVertex3f(1,1,0);
glVertex3f(1,-1,0);
glEnd();
glFlush();
}
// Pure opengl drawing code, essentially cross-platform
void draw()
{
if(progress >= 1.)
t_load_end = t_now;
if(t_now-t_load_end > 5.)
{
loading = 0;
glUseProgram(0.);
}
// Render first pass
glBindFramebuffer(GL_FRAMEBUFFER, first_pass_framebuffer);
glViewport(0,0,w,h);
glClear(GL_COLOR_BUFFER_BIT);
if(loading)
{
glUseProgram(load_program);
glUniform1f(load_progress_location, progress);
glUniform2f(load_resolution_location, w, h);
glUniform1f(load_time_location, t_now-t_start);
}
else //TODO: arrange scenes in the right order
{
float t = t_now-t_load_end-5.;
if(t > t_end)
ExitProcess(0);
if(scene_override)
{
if(override_index == 1)
{
glUseProgram(logo210_program);
glUniform1f(logo210_time_location, t);
glUniform2f(logo210_resolution_location, w, h);
}
else if(override_index == 4)
{
glUseProgram(logo_small_program);
glUniform1f(logo_small_time_location, t+15.);
t += 15.;
glUniform2f(logo_small_resolution_location, w, h);
}
else if(override_index == 3)
{
glUseProgram(surface_program);
glUniform1f(surface_time_location, t+351.+37.);
t += 37.;
glUniform2f(surface_resolution_location, w, h);
}
else if(override_index == 4)
{
glUseProgram(hangout_program);
glUniform1f(hangout_time_location, t);
t += 57.;
glUniform2f(hangout_resolution_location, w, h);
}
else if(override_index == 5)
{
glUseProgram(nr4_program);
glUniform1f(nr4_time_location, t);
t += 70.;
glUniform2f(nr4_resolution_location, w, h);
}
else if(override_index == 6)
{
glUseProgram(qm_program);
glUniform1f(qm_time_location, t);
t += 90.;
glUniform2f(qm_resolution_location, w, h);
}
else if(override_index == 7)
{
glUseProgram(trip_program);
glUniform1f(trip_time_location, t);
t += 110.;
glUniform2f(trip_resolution_location, w, h);
}
else if(override_index == 8)
{
glUseProgram(fourtwenty_program);
glUniform1f(fourtwenty_time_location, t+130.);
t += 130.;
glUniform2f(fourtwenty_resolution_location, w, h);
}
else if(override_index == 9)
{
glUseProgram(greet_program);
glUniform1f(greet_time_location, t+140.);
t += 140.;
glUniform2f(greet_resolution_location, w, h);
}
else if(override_index == 10)
{
glUseProgram(solskogen_program);
glUniform1f(solskogen_time_location, t);
t += 168.;
glUniform2f(solskogen_resolution_location, w, h);
}
}
else
{
if(t < 15.)
{
glUseProgram(logo210_program);
glUniform1f(logo210_time_location, t);
glUniform2f(logo210_resolution_location, w, h);
}
else if(t<37.)
{
glUseProgram(logo_small_program);
glUniform1f(logo_small_time_location, t);
glUniform2f(logo_small_resolution_location, w, h);
}
else if(t<57.)
{
glUseProgram(surface_program);
glUniform1f(surface_time_location, t+351.);
glUniform2f(surface_resolution_location, w, h);
}
else if(t<70.)
{
glUseProgram(hangout_program);
glUniform1f(hangout_time_location, t-57.);
glUniform2f(hangout_resolution_location, w, h);
}
else if(t<90.) //TODO: move to end
{
glUseProgram(nr4_program);
glUniform1f(nr4_time_location, t-70.);
glUniform2f(nr4_resolution_location, w, h);
}
else if(t<110.) //TODO: move to end
{
glUseProgram(qm_program);
glUniform1f(qm_time_location, t-90.);
glUniform2f(qm_resolution_location, w, h);
}
else if(t<130.)
{
glUseProgram(trip_program);
glUniform1f(trip_time_location, t-110.);
glUniform2f(trip_resolution_location, w, h);
}
else if(t<140.)
{
glUseProgram(fourtwenty_program);
glUniform1f(fourtwenty_time_location, t);
glUniform2f(fourtwenty_resolution_location, w, h);
}
else if(t < 168.)
{
glUseProgram(greet_program);
glUniform1f(greet_time_location, t);
glUniform2f(greet_resolution_location, w, h);
}
else if(t < 178.)
{
glUseProgram(solskogen_program);
glUniform1f(solskogen_time_location, t-168.);
glUniform2f(solskogen_resolution_location, w, h);
}
else ExitProcess(0);
}
quad();
// Render text to buffer
glUseProgram(text_program);
glUniform2f(text_resolution_location, w, h);
glUniform1f(text_font_width_location, font_texture_size);
glUniform1f(text_executable_size_location, executable_size);
glUniform1f(text_time_location, t);
glUniform1i(text_channel0_location, 0);
glUniform1i(text_font_location, 1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, first_pass_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, font_texture_handle);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, font_texture_size, font_texture_size, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}
quad();
// Render second pass (Post processing) to screen
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0,w,h);
glUseProgram(post_program);
glUniform2f(post_resolution_location, w, h);
glUniform1f(post_fsaa_location, fsaa);
glUniform1i(post_channel0_location, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, first_pass_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
quad();
glBindTexture(GL_TEXTURE_2D, 0);
if(music_loading)
{
glBindFramebuffer(GL_FRAMEBUFFER, snd_framebuffer);
glUseProgram(sfx_program);
if(music_block >= nblocks1)
{
if(!muted)
music_loading = 0;
}
else
{
if(!muted)
{
//printf("Rendering SFX block %d/%d -> %le\n", music_block, nblocks1, .5*(float)music_block/(float)nblocks1);
double tstart = (double)(music_block*block_size);
glViewport(0,0,texs,texs);
glUniform1f(sfx_volumelocation, 1.);
glUniform1f(sfx_samplerate_location, (float)sample_rate);
glUniform1f(sfx_blockoffset_location, (float)tstart);
glUniform1i(sfx_texs_location, texs);
glUniform1i(sfx_sequence_texture_location, 0);
glUniform1f(sfx_sequence_width_location, sequence_texture_size);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, sequence_texture_handle);
quad();
glReadPixels(0, 0, texs, texs, GL_RGBA, GL_UNSIGNED_BYTE, smusic1+music_block*block_size);
glFlush();
unsigned short *buf = (unsigned short*)smusic1;
short *dest = (short*)smusic1;
for(int j=2*music_block*block_size; j<2*(music_block+1)*block_size; ++j)
dest[j] = (buf[j]-(1<<15));
}
progress += .5*1./(float)nblocks1;
++music_block;
}
}
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
ExitProcess(0);
break;
case VK_SPACE:
// pause/unpaused render timer
paused = !paused;
if(paused)
waveOutPause(hWaveOut);
else
waveOutRestart(hWaveOut);
break;
}
break;
case WM_RBUTTONDOWN:
ExitProcess(0);
break;