-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.h
329 lines (291 loc) · 6.86 KB
/
common.h
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
/* Lightcyber - 64k Intro by Team210 at Evoke 2k19
* Copyright (C) 2019 DaDummy <>
* Copyright (C) 2019 Alexander Kraus <nr4@z10.info>
*
* 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/>.
*/
#ifndef COMMON_H
#define COMMON_H
#define FALSE (0)
#define TRUE (1)
#define ABS(x) ((x)<0?(-x):(x))
#define sign(x) ((x)<0?-1.:1.)
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# include <windows.h>
# include <Windowsx.h>
# include <commctrl.h>
# include <mmsystem.h>
# include <Mmreg.h>
# include <vfw.h>
#endif
#include <GL/gl.h>
#include <glext.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;
#ifdef WIN32
PFNGLACTIVETEXTUREPROC glActiveTexture;
#endif
// 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;
}
#ifdef DEBUG
#include <stdio.h>
#include <stdlib.h>
// 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 with handle %d.\n", program);
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");
}
#else // DEBUG
#define printf(a)
#endif //DEBUG
int w = 1280, h = 720;
// Supported resolutions
const int nresolutions = 9;
const char *resolution_names[] =
{
// 16:9
"1920*1080",
"1600*900",
"1280*720",
"960*540",
// 4:3
"1600*1200",
"1280*960",
"1024*768",
"800*600",
"640*480"
};
const int widths[] =
{
1920,
1600,
1280,
960,
1600,
1280,
1024,
800,
640
};
const int heights[] =
{
1080,
900,
720,
540,
1200,
960,
768,
600,
480
};
// Supported FSAA entries;
const int nfsaa = 6;
const char *fsaa_names[] =
{
"1x (None)",
"4x",
"9x",
"16x",
"25x",
"36x"
};
const int nbuffersizes = 4;
const char *buffersize_names[] =
{
"128x128 px",
"256x256 px",
"512x512 px",
"1024x1024 px"
};
#include "scenes.h"
#ifdef MIDI
HMIDIOUT hMidiOut;
#endif
int
#ifdef MIDI
// MIDI controller values
fader_0_value,
fader_1_value,
fader_2_value,
fader_3_value,
fader_4_value,
fader_5_value,
fader_6_value,
fader_7_value,
dial_0_value,
dial_1_value,
dial_2_value,
dial_3_value,
dial_4_value,
dial_5_value,
dial_6_value,
dial_7_value,
#endif
// SFX
sfx_program,
sfx_handle,
sfx_blockoffset_location,
sfx_samplerate_location,
sfx_volumelocation,
sfx_texs_location,
sfx_sequence_texture_location,
sfx_sequence_width_location,
// Sequence
sequence_texture_handle,
// Loading bar
load_handle,
load_program,
load_resolution_location,
load_time_location,
load_progress_location,
// Antialiasing
fsaa = 36,
txaa = 1,
// Text
font_texture_handle;
double mx, my;
// Demo globals
#define duration 187.061354
double t_start = 0.,
t_now = 0.,
t_end = duration,
t
#ifdef MIDI
,
time_dial = 0.,
time_fine_dial = 0.,
time_very_fine_dial = 0.,
fader0 = 0,
fader1 = 0,
fader2 = 0,
fader3 = 0,
fader4 = 0,
fader5 = 0,
fader6 = 0,
fader7 = 0
#endif
;
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 = 512;
int block_size = 512 * 512,
nblocks1;
unsigned int paused = 0,
recording = 0;
float progress = .0;
char record_filename[1024];
double t_paused;
GLuint first_pass_framebuffer = 0, first_pass_texture;
GLenum error;
#define NSHADERS 4.
float t_load_end = 0.;
void load_demo();
unsigned long __stdcall LoadMusicThread(void *lpParam);
unsigned long __stdcall LoadTextThread(void * lpParam);
void quad();
void updateBar();
void draw();
#include "sequence.h"
#include "sfx.h"
#define SFX_VAR_IVOLUME "iVolume"
#define SFX_VAR_ISAMPLERATE "iSampleRate"
#define SFX_VAR_IBLOCKOFFSET "iBlockOffset"
#define SFX_VAR_ITEXSIZE "iTexSize"
#define SFX_VAR_ISEQUENCE "iSequence"
#define SFX_VAR_ISEQUENCEWIDTH "iSequenceWidth"
#include "font/font.h"
#include "gfx/load.h"
#define LOAD_VAR_ITIME "iTime"
#define LOAD_VAR_IPROGRESS "iProgress"
#define LOAD_VAR_IRESOLUTION "iResolution"
#include "gfx/symbols.h"
#ifdef WIN32
# include "pal_win32.h"
#else
# include "pal_linux.h"
#endif
#endif