comparison src/main.c @ 0:785057719d9b

Import.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Aug 2013 12:25:43 +0300
parents
children acfb339ab87d
comparison
equal deleted inserted replaced
-1:000000000000 0:785057719d9b
1 // MIDISYS-ENGINE for windows and osx
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <math.h>
7 #include <fstream>
8 #include <map>
9 #include <wchar.h>
10 #include <time.h>
11
12 #include "freetype-gl.h"
13 #include "vertex-buffer.h"
14 #include "markup.h"
15 #include "shader.h"
16 #include "mat4.h"
17
18 #if defined(_WIN32) || defined(_WIN64)
19 # define wcpncpy wcsncpy
20 # define wcpcpy wcscpy
21 #endif
22
23 #ifndef __APPLE__
24 #include <malloc.h>
25 #endif
26
27 #define XXX 1
28 #include "bass.h"
29 #include "midifile.h"
30 #include "midiutil.h"
31
32 int quitflag = 0;
33
34 // GLUT window handle (1 for windowed display, 0 for fullscreen gamemode)
35 GLuint window = 0;
36 // demo running speed multiplier
37 float demo_speed_x = 1.0f;
38
39 // remove for non-debug build
40 int debugmode = 0;
41 // jump to demo position; 0 for whole demo
42 int jump_to = 0;
43 // some debugging flags
44 bool load_textures = true;
45
46 // midi sync
47
48 MIDI_MSG timeline[64][100000] = {NULL};
49 char timeline_trackname[64][512] = {-1};
50 int timeline_trackindex[64] = { 0 };
51 int timeline_tracklength[64] = { -1 };
52 int timeline_trackcount = 0;
53
54 // midi track number of mapping data
55 int mapping_tracknum[1000] = {-1};
56 // midi to shader param map from mapping.txt
57 int mapping_paramnum[1000] = {-1};
58 // track to map from
59 char mapping_trackname[1000][512] = {-1};
60 // map type: 0 == trig (noteon / off), 1 == param (modwheel / cc value)
61 int mapping_type[1000] = {-1};
62 // number of active mappings from midi to shader param
63 int mapping_count = 0;
64
65 // current shader param values
66 int scene_shader_params[16] = {-1};
67 int scene_shader_param_type[16] = {-1};
68
69 float millis = 0;
70
71 // scene globals
72 // vhs
73 float vhsbeat = 0.0;
74 float vhsbeat_start = 0;
75
76 #ifdef __APPLE__
77 #include "glew.h"
78 #include <OpenGL/OpenGL.h>
79 #include <OpenGL/glu.h>
80 #include "freeglut.h"
81 #else
82 #include <GL/glew.h>
83 #include <GL/glu.h>
84 #include <GL/freeglut.h>
85 #endif
86
87 #include <assimp/Importer.hpp>
88 //#include <assimp/PostProcess.h>
89 #include <assimp/postprocess.h>
90 #include <assimp/scene.h>
91 #include <assimp/DefaultLogger.hpp>
92 #include <assimp/LogStream.hpp>
93
94 #include "stb_image.c"
95
96
97 #include <oggplayer.h>
98 #include <algorithm>
99
100 #include "ggets.h"
101 #include "ggets.c"
102
103 // fbo
104
105 GLuint fb;
106 GLuint fb_tex;
107 GLuint fb2;
108 GLuint fb_tex2;
109
110 GLuint fake_framebuffer;
111 GLuint fake_framebuffer_tex;
112
113
114 #define KEYEVENTS_COUNT 507
115 unsigned char keyrec[507] = {98,105,108,111,116,114,105,112,32,111,112,101,114,97,116,105,110,103,32,115,121,115,116,101,109,32,52,46,50,48,13,97,108,108,32,108,101,102,116,115,32,97,110,100,32,114,105,103,104,116,115,32,114,101,118,101,114,115,101,100,13,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,13,99,97,116,32,110,111,116,101,46,116,120,116,13,49,54,58,51,48,32,98,101,32,97,116,32,116,104,101,32,97,103,114,101,101,100,32,112,108,97,99,101,13,49,56,58,51,48,32,115,119,97,108,108,111,119,32,99,97,112,115,117,108,101,115,13,97,102,116,101,114,32,101,102,102,101,99,116,58,32,112,114,111,101,99,8,8,116,101,120,8,99,116,32,109,101,116,97,108,115,13,119,97,105,116,32,102,111,114,32,97,109,97,115,8,8,8,8,109,97,115,107,32,115,105,103,110,97,108,13,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,13,99,97,116,32,98,105,108,111,116,114,105,112,95,99,114,101,100,105,116,115,46,116,120,116,13,97,101,103,105,115,13,100,101,112,13,101,101,118,8,8,118,101,97,103,101,110,8,8,8,110,103,101,108,13,104,97,100,100,97,115,13,111,97,115,105,122,13,112,97,104,97,109,111,107,97,13,115,112,105,105,107,107,105,13,118,105,115,121,13,122,111,118,13,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,69,68,69,83,8,65,57,65,105,39,109,13,103,101,116,116,105,110,103,32,115,111,109,101,116,104,105,110,103,32,110,111,119,13,105,8,46,46,46,105,39,109,32,102,101,101,108,105,110,103,32,105,116,32,116,111,111,46,13,105,116,39,115,46,46,46,46,32,105,116,39,115,46,46,46,46,46,46,46,46,46,13,105,116,39,115,32,107,105,99,107,107,107,105,105,105,105,105,105,105,105,105,105,110,110,110,110,110,110,110,110,110,110,103,103,103,103,103,103,103,103,105,105,105,105,105,105,105,105,105,110,110,110,110,110,110,110,110,110,13};
116 int keymillis[507] = {0,84,133,278,414,574,624,667,780,1045,1104,1185,1249,1329,1456,1537,1701,1753,1801,1891,2009,2099,2205,2672,2762,2905,3013,3103,3204,3317,3593,3837,3945,4079,4202,4273,4359,4429,4574,4610,4648,4729,4858,4905,4986,5080,5180,5253,5366,5440,5689,5820,6004,6079,6238,6299,6416,6495,6624,6796,7149,7291,7814,7845,7878,7910,7942,7975,8007,8040,8071,8104,8137,8169,8204,8237,8269,8301,8334,8367,8398,8431,8465,8496,8528,8561,8591,8623,8656,8688,8719,9198,9403,9460,9667,9777,9938,10014,10051,10089,10279,10618,10774,10873,11230,15891,16480,16917,17262,17987,18708,21302,21803,21920,22036,22135,22216,22353,22491,22549,22706,22821,22939,23096,23150,23303,23400,23454,23891,23930,23956,24016,24077,24387,28893,29377,29730,29985,30654,30829,33772,34315,34383,34521,34655,34791,34877,34972,35140,35179,35220,35322,35413,35498,35551,35627,36409,43630,44014,44155,44228,44372,44460,44596,44661,44794,44840,44950,45009,45217,45280,45398,45456,45610,45713,45846,46112,46237,46286,46340,46702,46935,47033,47087,47160,47284,47324,47393,47463,47519,47636,47790,49371,49417,49446,49539,49612,49721,49769,49867,49926,49998,50091,50164,50245,50420,50544,50669,50780,50856,50899,50921,51003,51075,51352,51420,51568,51663,51717,51844,52608,52905,53437,53469,53501,53533,53567,53598,53631,53663,53694,53728,53759,53792,53823,53855,53889,53920,53954,53987,54019,54051,54082,54115,54146,54179,54211,54244,54544,54700,54893,55387,56136,56247,56430,56502,56766,56831,56896,57004,57070,57206,57249,57271,57667,57831,57975,58045,58209,58315,58384,58444,58630,58736,58822,58927,59433,59758,59833,59952,60038,60133,60697,60984,61047,61106,61560,61885,62091,62106,62626,62757,62786,62832,63009,63115,63211,63228,63557,63679,63805,63980,64059,64099,64215,64663,65414,65494,65620,65795,65820,65902,66303,66604,66666,66725,66845,66929,67443,67820,67886,68047,68105,68236,68290,68416,68496,68865,69309,69422,69535,69677,69846,69965,70153,70608,71440,71520,71620,71718,71943,72258,72359,72941,73284,73559,74087,74120,74151,74183,74214,74249,74281,74315,74347,74378,74411,74442,74578,74703,74820,75021,75184,75338,75491,75983,76650,76976,77252,77294,77624,78108,78162,78932,79324,79777,80101,80598,80997,81157,81230,81367,81487,81976,82114,82182,82253,82550,82641,82690,82765,83021,83131,83184,83374,83422,83518,83829,83895,84017,84901,85534,85972,86047,86189,86325,86642,87409,87637,87710,87790,87866,87986,88086,88134,88307,88350,88405,88894,89235,89320,89406,89571,89715,90247,91658,91929,92036,92609,92713,93112,93263,93393,93539,94091,94249,94433,94711,94806,95220,95405,95541,95707,95992,96150,96306,96442,96600,97012,98638,98805,99329,99462,100393,100771,101191,102156,102308,102553,102984,103505,103675,103864,104079,104212,104361,104545,104890,105043,105235,105456,105682,105811,105979,106157,106330,106509,106670,106838,106997,107165,107573,107753,107952,108102,108259,108415,108591,108696,108847,108987,109123,109261,109418,109553,109665,109864,109969,110112,110232,110372,110506,110648,110781,110936,111062,111063};
117
118
119 #define KEYEVENTS_COUNT2 212
120 unsigned char keyrec2[212] = {85,115,32,104,105,103,104,32,112,114,101,99,105,115,105,111,110,32,116,111,111,115,108,44,32,101,8,8,8,8,8,108,115,32,44,8,8,44,32,101,110,103,105,110,101,101,114,101,100,32,116,111,32,101,120,101,99,117,116,101,13,116,104,101,32,115,104,111,114,116,45,115,105,103,8,103,104,116,101,100,32,105,100,101,111,108,111,103,105,99,97,108,32,102,108,97,118,111,117,114,32,111,102,32,116,111,100,97,121,13,65,115,32,108,111,110,103,32,97,115,32,116,104,101,114,101,32,105,115,32,97,32,99,111,109,109,111,110,32,101,118,8,110,121,8,101,109,121,32,116,111,32,117,110,105,116,101,32,117,115,13,119,101,39,108,108,32,107,101,101,108,8,112,32,109,97,114,99,104,105,110,103,44,32,108,105,107,101,32,97,32,119,101,108,108,45,111,105,108,101,100,32,109,97,99,104,105,110,101,46,46,46};
121 int keymillis2[212] = {0,157,253,413,518,573,654,794,940,1045,1110,1315,1406,1502,1599,1666,2283,2362,2972,3058,3189,3358,3459,3677,3747,3859,4049,4184,4320,4475,4589,4628,4677,4762,4907,5201,5327,5375,5456,5556,5802,5911,6008,6244,6380,6536,6855,6920,7061,7142,7254,7338,7535,8560,8680,8812,9067,9201,9284,9357,10544,11841,11961,12027,12091,12216,12402,12514,12634,12791,12933,13357,13472,13589,13857,14062,14490,14688,14751,15278,15395,15707,15812,15893,15953,16162,16316,16359,16463,16577,16632,16762,16899,17085,17180,17643,17815,17911,17972,18791,18888,19011,19219,19303,19516,19628,19771,19876,19895,20575,21102,21344,21518,21926,22072,22158,22208,22559,22659,22756,22866,23123,23290,23374,23457,23539,23605,23691,23767,23859,23955,24060,24357,24433,24502,24651,24700,24839,24981,25542,25672,25903,26080,26194,26632,26738,26835,26920,27000,27101,27164,27233,27448,27785,27899,27969,28050,28118,28234,28355,28892,29245,29372,29555,29730,29871,29973,30140,30219,30360,30476,30773,30817,30886,31118,31193,31264,31454,31494,31542,31893,31955,32193,32267,32405,32485,32638,32661,32745,32834,32927,33070,33166,33273,33401,33648,33995,34047,34253,34327,34421,34500,34629,34725,34861,34936,34999,35231,35315,35415,35515,35615};
122
123
124
125 const int __SIGNAL_ACTIVATE__ = 0;
126 const int __SIGNAL_COMPLETE__ = 1;
127 const int __SIGNAL_HISTORY_NEXT__ = 2;
128 const int __SIGNAL_HISTORY_PREV__ = 3;
129 #define MAX_LINE_LENGTH 511
130
131
132 const int MARKUP_NORMAL = 0;
133 const int MARKUP_DEFAULT = 0;
134 const int MARKUP_ERROR = 1;
135 const int MARKUP_WARNING = 2;
136 const int MARKUP_OUTPUT = 3;
137 const int MARKUP_BOLD = 4;
138 const int MARKUP_ITALIC = 5;
139 const int MARKUP_BOLD_ITALIC = 6;
140 const int MARKUP_FAINT = 7;
141 #define MARKUP_COUNT 8
142
143
144 // ------------------------------------------------------- typedef & struct ---
145 typedef struct {
146 float x, y, z;
147 float s, t;
148 float r, g, b, a;
149 } vertex_t;
150
151 struct _console_t {
152 vector_t * lines;
153 wchar_t * prompt;
154 wchar_t killring[MAX_LINE_LENGTH+1];
155 wchar_t input[MAX_LINE_LENGTH+1];
156 size_t cursor;
157 markup_t markup[MARKUP_COUNT];
158 vertex_buffer_t * buffer;
159 vec2 pen;
160 void (*handlers[4])( struct _console_t *, wchar_t * );
161 };
162 typedef struct _console_t console_t;
163
164 // ------------------------------------------------------- global variables ---
165 static console_t * console;
166 texture_atlas_t *atlas;
167 GLuint shader;
168 mat4 model, view, projection;
169
170
171 // ------------------------------------------------------------ console_new ---
172 console_t *
173 console_new( void )
174 {
175 console_t *self = (console_t *) malloc( sizeof(console_t) );
176 if( !self )
177 {
178 return self;
179 }
180 self->lines = vector_new( sizeof(wchar_t *) );
181 self->prompt = (wchar_t *) wcsdup( L"" );
182 self->cursor = 0;
183 self->buffer = vertex_buffer_new( "vertex:3f,tex_coord:2f,color:4f" );
184 self->input[0] = L'\0';
185 self->killring[0] = L'\0';
186 self->handlers[__SIGNAL_ACTIVATE__] = 0;
187 self->handlers[__SIGNAL_COMPLETE__] = 0;
188 self->handlers[__SIGNAL_HISTORY_NEXT__] = 0;
189 self->handlers[__SIGNAL_HISTORY_PREV__] = 0;
190 self->pen.x = self->pen.y = 0;
191
192 atlas = texture_atlas_new( 512, 512, 1 );
193
194 vec4 white = {{0.2,1,0.2,0.7}};
195 vec4 black = {{0,0,0,1}};
196 vec4 none = {{0,0,1,0}};
197
198 markup_t normal;
199 normal.family = "data/fonts/VeraMono.ttf";
200 normal.size = 23.0;
201 normal.bold = 0;
202 normal.italic = 0;
203 normal.rise = 0.0;
204 normal.spacing = 0.0;
205 normal.gamma = 1.0;
206 normal.foreground_color = white;
207 normal.foreground_color.r = 0.45;
208 normal.foreground_color.g = 0.65;
209 normal.foreground_color.b = 0.45;
210
211 normal.font = texture_font_new( atlas, "data/fonts/term.ttf", 33 );
212
213 markup_t bold = normal;
214 bold.bold = 1;
215 bold.font = texture_font_new( atlas, "data/fonts/VeraMoBd.ttf", 23 );
216
217 markup_t italic = normal;
218 italic.italic = 1;
219 bold.font = texture_font_new( atlas, "data/fonts/VeraMoIt.ttf", 23 );
220
221 markup_t bold_italic = normal;
222 bold.bold = 1;
223 italic.italic = 1;
224 italic.font = texture_font_new( atlas, "data/fonts/VeraMoBI.ttf", 13 );
225
226 markup_t faint = normal;
227 faint.foreground_color.r = 0.25;
228 faint.foreground_color.g = 0.45;
229 faint.foreground_color.b = 0.25;
230
231 markup_t error = normal;
232 error.foreground_color.r = 1.00;
233 error.foreground_color.g = 0.00;
234 error.foreground_color.b = 0.00;
235
236 markup_t warning = normal;
237 warning.foreground_color.r = 1.00;
238 warning.foreground_color.g = 0.50;
239 warning.foreground_color.b = 0.50;
240
241 markup_t output = normal;
242 output.foreground_color.r = 0.00;
243 output.foreground_color.g = 0.00;
244 output.foreground_color.b = 1.00;
245
246 self->markup[MARKUP_NORMAL] = normal;
247 self->markup[MARKUP_ERROR] = error;
248 self->markup[MARKUP_WARNING] = warning;
249 self->markup[MARKUP_OUTPUT] = output;
250 self->markup[MARKUP_FAINT] = faint;
251 self->markup[MARKUP_BOLD] = bold;
252 self->markup[MARKUP_ITALIC] = italic;
253 self->markup[MARKUP_BOLD_ITALIC] = bold_italic;
254
255 return self;
256 }
257
258
259
260 // -------------------------------------------------------- console_delete ---
261 void
262 console_delete( console_t *self )
263 { }
264
265
266
267 // ----------------------------------------------------- console_add_glyph ---
268 void
269 console_add_glyph( console_t *self,
270 wchar_t current,
271 wchar_t previous,
272 markup_t *markup )
273 {
274 texture_glyph_t *glyph = texture_font_get_glyph( markup->font, current );
275 if( previous != L'\0' )
276 {
277 self->pen.x += texture_glyph_get_kerning( glyph, previous );
278 }
279 float r = markup->foreground_color.r;
280 float g = markup->foreground_color.g;
281 float b = markup->foreground_color.b;
282 float a = markup->foreground_color.a;
283 float x0 = self->pen.x + glyph->offset_x;
284 float y0 = self->pen.y + glyph->offset_y;
285 float x1 = x0 + glyph->width;
286 float y1 = y0 - glyph->height;
287 float s0 = glyph->s0;
288 float t0 = glyph->t0;
289 float s1 = glyph->s1;
290 float t1 = glyph->t1;
291
292 GLuint indices[] = {0,1,2, 0,2,3};
293 vertex_t vertices[] = { { x0,y0,0, s0,t0, r,g,b,a },
294 { x0,y1,0, s0,t1, r,g,b,a },
295 { x1,y1,0, s1,t1, r,g,b,a },
296 { x1,y0,0, s1,t0, r,g,b,a } };
297 vertex_buffer_push_back( self->buffer, vertices, 4, indices, 6 );
298
299 self->pen.x += glyph->advance_x;
300 self->pen.y += glyph->advance_y;
301 }
302
303
304
305 // -------------------------------------------------------- console_render ---
306 void
307 console_render( console_t *self )
308 {
309 int viewport[4];
310 glGetIntegerv( GL_VIEWPORT, viewport );
311
312 size_t i, index;
313 self->pen.x = 0;
314 self->pen.y = viewport[3];
315 vertex_buffer_clear( console->buffer );
316
317 int cursor_x = self->pen.x;
318 int cursor_y = self->pen.y;
319
320 markup_t markup;
321
322 // console_t buffer
323 markup = self->markup[MARKUP_FAINT];
324 self->pen.y -= markup.font->height;
325
326 for( i=0; i<self->lines->size; ++i )
327 {
328 wchar_t *text = * (wchar_t **) vector_get( self->lines, i ) ;
329 if( wcslen(text) > 0 )
330 {
331 console_add_glyph( console, text[0], L'\0', &markup );
332 for( index=1; index < wcslen(text)-1; ++index )
333 {
334 console_add_glyph( console, text[index], text[index-1], &markup );
335 }
336 }
337 self->pen.y -= markup.font->height - markup.font->linegap;
338 self->pen.x = 0;
339 cursor_x = self->pen.x;
340 cursor_y = self->pen.y;
341 }
342
343 // Prompt
344 markup = self->markup[MARKUP_BOLD];
345 if( wcslen( self->prompt ) > 0 )
346 {
347 console_add_glyph( console, self->prompt[0], L'\0', &markup );
348 for( index=1; index < wcslen(self->prompt); ++index )
349 {
350 console_add_glyph( console, self->prompt[index], self->prompt[index-1], &markup );
351 }
352 }
353 cursor_x = (int) self->pen.x;
354
355 // Input
356 markup = self->markup[MARKUP_NORMAL];
357 if( wcslen(self->input) > 0 )
358 {
359 console_add_glyph( console, self->input[0], L'\0', &markup );
360 if( self->cursor > 0)
361 {
362 cursor_x = (int) self->pen.x;
363 }
364 for( index=1; index < wcslen(self->input); ++index )
365 {
366 console_add_glyph( console, self->input[index], self->input[index-1], &markup );
367 if( index < self->cursor )
368 {
369 cursor_x = (int) self->pen.x;
370 }
371 }
372 }
373
374 float cursorblink = 0.7+abs(cos(millis*0.05)+0.3);
375
376 // Cursor (we use the black character (-1) as texture )
377 texture_glyph_t *glyph = texture_font_get_glyph( markup.font, -1 );
378 float r = markup.foreground_color.r;
379 float g = markup.foreground_color.g;
380 float b = markup.foreground_color.b;
381 float a = markup.foreground_color.a*cursorblink;
382 float x0 = cursor_x+1;
383 float y0 = cursor_y + markup.font->descender;
384 float x1 = cursor_x+14;
385 float y1 = y0 + markup.font->height - markup.font->linegap;
386
387 if (y0 == 714) { y0 = 648+33; y1 = y0 + markup.font->height - markup.font->linegap; }
388
389 float s0 = glyph->s0;
390 float t0 = glyph->t0;
391 float s1 = glyph->s1;
392 float t1 = glyph->t1;
393 GLuint indices[] = {0,1,2, 0,2,3};
394 vertex_t vertices[] = { { x0,y0,0, s0,t0, r,g,b,a },
395 { x0,y1,0, s0,t1, r,g,b,a },
396 { x1,y1,0, s1,t1, r,g,b,a },
397 { x1,y0,0, s1,t0, r,g,b,a } };
398 vertex_buffer_push_back( self->buffer, vertices, 4, indices, 6 );
399 glEnable( GL_TEXTURE_2D );
400 glEnable(GL_BLEND);
401 glActiveTexture(GL_TEXTURE0);
402 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
403 glBindTexture(GL_TEXTURE_2D, atlas->id);
404
405 glUseProgram( shader );
406 {
407 glUniform1i( glGetUniformLocation( shader, "texture" ),
408 0 );
409 glUniformMatrix4fv( glGetUniformLocation( shader, "model" ),
410 1, 0, model.data);
411 glUniformMatrix4fv( glGetUniformLocation( shader, "view" ),
412 1, 0, view.data);
413 glUniformMatrix4fv( glGetUniformLocation( shader, "projection" ),
414 1, 0, projection.data);
415 vertex_buffer_render( console->buffer, GL_TRIANGLES );
416 }
417
418
419 }
420
421
422
423 // ------------------------------------------------------- console_connect ---
424 void
425 console_connect( console_t *self,
426 const char *signal,
427 void (*handler)(console_t *, wchar_t *))
428 {
429 if( strcmp( signal,"activate" ) == 0 )
430 {
431 self->handlers[__SIGNAL_ACTIVATE__] = handler;
432 }
433 else if( strcmp( signal,"complete" ) == 0 )
434 {
435 self->handlers[__SIGNAL_COMPLETE__] = handler;
436 }
437 else if( strcmp( signal,"history-next" ) == 0 )
438 {
439 self->handlers[__SIGNAL_HISTORY_NEXT__] = handler;
440 }
441 else if( strcmp( signal,"history-prev" ) == 0 )
442 {
443 self->handlers[__SIGNAL_HISTORY_PREV__] = handler;
444 }
445 }
446
447
448
449 // --------------------------------------------------------- console_print ---
450 void
451 console_print( console_t *self, wchar_t *text )
452 {
453 // Make sure there is at least one line
454 if( self->lines->size == 0 )
455 {
456 wchar_t *line = wcsdup( L"" );
457 vector_push_back( self->lines, &line );
458 }
459
460 if (self->lines->size > 10)
461 {
462 vector_erase(self->lines,0);
463 }
464
465 // Make sure last line does not end with '\n'
466 wchar_t *last_line = *(wchar_t **) vector_get( self->lines, self->lines->size-1 ) ;
467 if( wcslen( last_line ) != 0 )
468 {
469 if( last_line[wcslen( last_line ) - 1] == L'\n' )
470 {
471 wchar_t *line = wcsdup( L"" );
472 vector_push_back( self->lines, &line );
473 }
474 }
475 last_line = *(wchar_t **) vector_get( self->lines, self->lines->size-1 ) ;
476
477 wchar_t *start = text;
478 wchar_t *end = wcschr(start, L'\n');
479 size_t len = wcslen( last_line );
480 if( end != NULL)
481 {
482 wchar_t *line = (wchar_t *) malloc( (len + end - start + 2)*sizeof( wchar_t ) );
483 wcpncpy( line, last_line, len );
484 wcpncpy( line + len, text, end-start+1 );
485
486 line[len+end-start+1] = L'\0';
487
488 vector_set( self->lines, self->lines->size-1, &line );
489 free( last_line );
490 if( (end-start) < (wcslen( text )-1) )
491 {
492 console_print(self, end+1 );
493 }
494 return;
495 }
496 else
497 {
498 wchar_t *line = (wchar_t *) malloc( (len + wcslen(text) + 1) * sizeof( wchar_t ) );
499 wcpncpy( line, last_line, len );
500 wcpcpy( line + len, text );
501 vector_set( self->lines, self->lines->size-1, &line );
502 free( last_line );
503 return;
504 }
505 }
506
507
508
509 // ------------------------------------------------------- console_process ---
510 void
511 console_process( console_t *self,
512 const char *action,
513 const unsigned char key )
514 {
515 size_t len = wcslen(self->input);
516
517 //printf("console_process:%d\n", key);
518
519 if( strcmp(action, "type") == 0 )
520 {
521 if( len < MAX_LINE_LENGTH )
522 {
523 memmove( self->input + self->cursor+1,
524 self->input + self->cursor,
525 (len - self->cursor+1)*sizeof(wchar_t) );
526 self->input[self->cursor] = (wchar_t) key;
527 self->cursor++;
528 }
529 else
530 {
531 fprintf( stderr, "Input buffer is full\n" );
532 }
533 }
534 else
535 {
536 if( strcmp( action, "enter" ) == 0 )
537 {
538 if( console->handlers[__SIGNAL_ACTIVATE__] )
539 {
540 (*console->handlers[__SIGNAL_ACTIVATE__])(console, console->input);
541 }
542 console_print( self, self->prompt );
543 console_print( self, self->input );
544 console_print( self, L"\n" );
545 self->input[0] = L'\0';
546 self->cursor = 0;
547 }
548 else if( strcmp( action, "right" ) == 0 )
549 {
550 if( self->cursor < wcslen(self->input) )
551 {
552 self->cursor += 1;
553 }
554 }
555 else if( strcmp( action, "left" ) == 0 )
556 {
557 if( self->cursor > 0 )
558 {
559 self->cursor -= 1;
560 }
561 }
562 else if( strcmp( action, "delete" ) == 0 )
563 {
564 memmove( self->input + self->cursor,
565 self->input + self->cursor+1,
566 (len - self->cursor)*sizeof(wchar_t) );
567 }
568 else if( strcmp( action, "backspace" ) == 0 )
569 {
570 if( self->cursor > 0 )
571 {
572 memmove( self->input + self->cursor-1,
573 self->input + self->cursor,
574 (len - self->cursor+1)*sizeof(wchar_t) );
575 self->cursor--;
576 }
577 }
578 else if( strcmp( action, "kill" ) == 0 )
579 {
580 if( self->cursor < len )
581 {
582 wcpcpy(self->killring, self->input + self->cursor );
583 self->input[self->cursor] = L'\0';
584 fwprintf(stderr, L"Kill ring: %ls\n", self->killring);
585 }
586
587 }
588 else if( strcmp( action, "yank" ) == 0 )
589 {
590 size_t l = wcslen(self->killring);
591 if( (len + l) < MAX_LINE_LENGTH )
592 {
593 memmove( self->input + self->cursor + l,
594 self->input + self->cursor,
595 (len - self->cursor)*sizeof(wchar_t) );
596 memcpy( self->input + self->cursor,
597 self->killring, l*sizeof(wchar_t));
598 self->cursor += l;
599 }
600 }
601 else if( strcmp( action, "home" ) == 0 )
602 {
603 self->cursor = 0;
604 }
605 else if( strcmp( action, "end" ) == 0 )
606 {
607 self->cursor = wcslen( self->input );
608 }
609 else if( strcmp( action, "clear" ) == 0 )
610 {
611 }
612 else if( strcmp( action, "history-prev" ) == 0 )
613 {
614 if( console->handlers[__SIGNAL_HISTORY_PREV__] )
615 {
616 (*console->handlers[__SIGNAL_HISTORY_PREV__])(console, console->input);
617 }
618 }
619 else if( strcmp( action, "history-next" ) == 0 )
620 {
621 if( console->handlers[__SIGNAL_HISTORY_NEXT__] )
622 {
623 (*console->handlers[__SIGNAL_HISTORY_NEXT__])(console, console->input);
624 }
625 }
626 else if( strcmp( action, "complete" ) == 0 )
627 {
628 if( console->handlers[__SIGNAL_COMPLETE__] )
629 {
630 (*console->handlers[__SIGNAL_COMPLETE__])(console, console->input);
631 }
632 }
633 }
634 }
635
636
637
638
639
640
641
642
643 // debug
644
645 int mouseX;
646 int mouseY;
647
648 // shaders
649
650 GLuint shaders[10];
651 const char* shaderss[] = { "data/shaders/v3f-t2f-c4f.frag",
652 "data/shaders/projector",
653 "data/shaders/eye",
654 "data/shaders/eye_post",
655 "data/shaders/fsquad",
656 "data/shaders/copquad",
657 "data/shaders/redcircle",
658 "data/shaders/vhs",
659 "data/shaders/yuv2rgb",
660 "data/shaders/hex"};
661 enum shaderi { nannanna, projector, eye, eye_post, fsquad, copquad, redcircle, vhs, yuv2rgb, hex };
662
663 GLuint depth_rb = 0;
664 GLuint depth_rb2 = 0;
665 GLuint depth_rb3 = 0;
666 // textures
667
668 int textures[65] = {-1};
669 const char* texturess[] = {"data/gfx/scene.jpg",
670 "data/gfx/dude1.jpg",
671 "data/gfx/dude2.jpg",
672 "data/gfx/mask.jpg",
673 "data/gfx/note.jpg",
674 "data/gfx/exit.jpg",
675 "data/gfx/v0.png",
676 "data/gfx/v1.png",
677 "data/gfx/v2.png",
678 "data/gfx/v3.png",
679 "data/gfx/v4.png",
680 "data/gfx/v5.png",
681 "data/gfx/v6.png",
682 "data/gfx/v7.png",
683 "data/gfx/v8.png",
684 "data/gfx/v9.png",
685 "data/gfx/v9a.png",
686 "data/gfx/v9b.png",
687 "data/gfx/v9c.png",
688 "data/gfx/copkiller1.jpg",
689 "data/gfx/prip1.jpg",
690 "data/gfx/copkiller2.jpg",
691 "data/gfx/prip2.jpg",
692 "data/gfx/copkiller3.jpg",
693 "data/gfx/prip3.jpg",
694 "data/gfx/copkiller4.jpg",
695 "data/gfx/prip4.jpg",
696 "data/gfx/copkiller5.jpg",
697 "data/gfx/prip5.jpg",
698 "data/gfx/copkiller6.jpg",
699 "data/gfx/prip6.jpg",
700 "data/gfx/copkiller7.jpg",
701 "data/gfx/prip7.jpg",
702 "data/gfx/copkiller8.jpg",
703 "data/gfx/prip8.jpg",
704 "data/gfx/copkiller9.jpg",
705 "data/gfx/prip9.jpg",
706 "data/gfx/copkiller10.jpg",
707 "data/gfx/prip10.jpg",
708 "data/gfx/copkiller11.jpg",
709 "data/gfx/prip11.jpg",
710 "data/gfx/copkiller12.jpg",
711 "data/gfx/prip12.jpg",
712 "data/gfx/copkiller13.jpg",
713 "data/gfx/prip13.jpg",
714 "data/gfx/copkiller14.jpg",
715 "data/gfx/prip14.jpg",
716 "data/gfx/copkiller15.jpg",
717 "data/gfx/prip15.jpg",
718 "data/gfx/aegis.jpg",
719 "data/gfx/ll1.png",
720 "data/gfx/ll2.png",
721 "data/gfx/ll3.png",
722 "data/gfx/ll4.png",
723 "data/gfx/ll5.png",
724 "data/gfx/grayeye.jpg",
725 "data/gfx/room1.jpg",
726 "data/gfx/room2.jpg",
727 "data/gfx/room3.jpg",
728 "data/gfx/majic1.jpg",
729 "data/gfx/majic2.jpg",
730 "data/gfx/majic3.jpg",
731 "data/gfx/majic4.jpg",
732 "data/gfx/bilogon.png",
733 "data/gfx/noise.jpg"};
734 enum texturi { tex_scene, tex_dude, tex_dude2, tex_mask, tex_note, tex_exit,
735 tex_v0,tex_v1,tex_v2,tex_v3,tex_v4,tex_v5,tex_v6,tex_v7,tex_v8,tex_v9,tex_v9a,tex_v9b,tex_v9c,
736 tex_copkiller, tex_prip,
737 tex_copkiller2, tex_prip2,
738 tex_copkiller3, tex_prip3,
739 tex_copkiller4, tex_prip4,
740 tex_copkiller5, tex_prip5,
741 tex_copkiller6, tex_prip6,
742 tex_copkiller7, tex_prip7,
743 tex_copkiller8, tex_prip8,
744 tex_copkiller9, tex_prip9,
745 tex_copkiller10,tex_prip10,
746 tex_copkiller11,tex_prip11,
747 tex_copkiller12,tex_prip12,
748 tex_copkiller13,tex_prip13,
749 tex_copkiller14,tex_prip14,
750 tex_copkiller15,tex_prip15,
751
752 tex_aegis, tex_ll1,tex_ll2,tex_ll3,tex_ll4,tex_ll5,
753 tex_grayeye, tex_room, tex_room2, tex_room3,
754 tex_majestic1, tex_majestic2, tex_majestic3, tex_majestic4,
755 tex_bilogon,
756 tex_noise};
757
758 // texture switchers
759
760 int room_texnum = 0;
761
762 // assimp scenes
763
764 Assimp::Importer importer[7];
765
766 const aiScene *kapsule, *bilothree, *brieflycase,
767 *bilothorn, *biloflat, *bilotetra;
768
769 std::map<std::string, GLuint*> textureIdMap; // map image filenames to textureIds
770 GLuint* textureIds; // pointer to texture array
771
772 static float kujalla_angle = 0.f;
773 int beatmode = -1;
774
775 // assimp defines
776
777 #define aisgl_min(x,y) (x<y?x:y)
778 #define aisgl_max(x,y) (y>x?y:x)
779
780 // misc. gfx system
781
782 static GLfloat g_nearPlane = 0.001;
783 static GLfloat g_farPlane = 1000;
784 static int c_Width = 640;
785 static int c_Height = 360;
786 static int g_Width = 1280;
787 static int g_Height = 720;
788
789 class YUVFrame {
790 public:
791 YUVFrame(OggPlayer oggstream):ogg(oggstream) {
792 width = ogg.width(); height = ogg.height();
793 // The textures are created when rendering the first frame
794 y_tex = u_tex = v_tex = -1 ;
795 }
796 ~YUVFrame() {
797 glDeleteTextures(1,&y_tex);
798 glDeleteTextures(1,&u_tex);
799 glDeleteTextures(1,&v_tex);
800 }
801 void play() {
802 ogg.play();
803 }
804 void close()
805 {
806 ogg.close();
807 }
808 void render() {
809 update();
810 if(-1==y_tex) return; // not ready yet
811 glUseProgram(shaders[yuv2rgb]);
812
813 GLint widthLoc5 = glGetUniformLocation(shaders[yuv2rgb], "width");
814 GLint heightLoc5 = glGetUniformLocation(shaders[yuv2rgb], "height");
815 glUniform1f(widthLoc5, g_Width);
816 glUniform1f(heightLoc5, g_Height);
817
818 GLint y_pos = glGetUniformLocation(shaders[yuv2rgb],"y_tex");
819 GLint u_pos = glGetUniformLocation(shaders[yuv2rgb],"u_tex");
820 GLint v_pos = glGetUniformLocation(shaders[yuv2rgb],"v_tex");
821
822 glDisable(GL_BLEND);
823
824 glActiveTexture(GL_TEXTURE0);
825 glBindTexture(GL_TEXTURE_2D, y_tex);
826 glUniform1i(y_pos, 0);
827 glActiveTexture(GL_TEXTURE1);
828 glBindTexture(GL_TEXTURE_2D, u_tex);
829 glUniform1i(u_pos, 1);
830 glActiveTexture(GL_TEXTURE2);
831 glBindTexture(GL_TEXTURE_2D, v_tex);
832 glUniform1i(v_pos, 2);
833
834 glLoadIdentity();
835
836 glTranslatef(-1.2, -1.0, -1.0);
837
838 int i=0;
839 int j=0;
840 glBegin(GL_QUADS);
841 glVertex2f(i, j);
842 glVertex2f(i + 100, j);
843 glVertex2f(i + 100, j + 100);
844 glVertex2f(i, j + 100);
845 glEnd();
846
847 }
848 private:
849 void update() {
850 YUVBuffer yuv;
851 // yuv_buffer_try_lock(...) returns false if the last read frame is
852 // still up to date, in this case we can simply retender the
853 // last frame without an update
854 // We don't need to call unlock unless the lock operation was successfull
855 if(!ogg.yuv_buffer_try_lock(&yuv)) return;
856 // Create the textures if needed, at this point we
857 // know how big the textures should be.
858 // The sample plyer that comes with the official SDK
859 // assummes uv_width=y_width/2 , uv_height=y_height/2
860 // but I'm not sure whether that is always true
861 if(-1==y_tex){
862 y_tex = gen_texture(yuv.y_width,yuv.y_height);
863 u_tex = gen_texture(yuv.uv_width,yuv.uv_height);
864 v_tex = gen_texture(yuv.uv_width,yuv.uv_height);
865 }
866 int y_offset = ogg.offset_x() + yuv.y_stride * ogg.offset_y();
867 int uv_offset = ogg.offset_x()/(yuv.y_width/yuv.uv_width)+
868 yuv.uv_stride * ogg.offset_y()/(yuv.y_height/yuv.uv_height);
869 update_texture(y_tex,yuv.y+y_offset,yuv.y_width,yuv.y_height,yuv.y_stride);
870 update_texture(u_tex,yuv.u+uv_offset,yuv.uv_width,yuv.uv_height,yuv.uv_stride);
871 update_texture(v_tex,yuv.v+uv_offset,yuv.uv_width,yuv.uv_height,yuv.uv_stride);
872 ogg.yuv_buffer_unlock();
873 }
874 GLuint gen_texture(int w,int h) {
875 GLuint tex;
876 glGenTextures(1,&tex);
877 glBindTexture(GL_TEXTURE_2D,tex);
878 glTexImage2D(GL_TEXTURE_2D,0,1,w,h,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,NULL);
879 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
880 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
881 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT );
882 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT );
883 return tex;
884 }
885 void update_texture(GLuint tex, unsigned char* buf,int w,int h, int stride) {
886 glPixelStorei(GL_UNPACK_ROW_LENGTH,stride);
887 glBindTexture(GL_TEXTURE_2D,tex);
888 glTexSubImage2D(GL_TEXTURE_2D,0,0,0,w,h,GL_LUMINANCE,GL_UNSIGNED_BYTE,buf);
889 // set GL_UNPACK_ROW_LENGTH back to 0 to avoid bugs
890 glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
891 }
892 OggPlayer ogg;
893 GLuint y_tex,u_tex,v_tex;
894 int width,height;
895 };
896
897 YUVFrame* myVideoFrame;
898
899 void InitFBO();
900
901 int frame = 0;
902
903 // effect pointers && logic && state
904
905 int current_scene;
906
907 void dummy(float dt) {}
908
909 void Loader();
910 void LeadMaskScene();
911 void CopScene();
912 void MarssiScene();
913 void LongScene();
914 void EyeScene();
915 void RedCircleScene();
916 void BiloThreeScene();
917 void KolmeDeeScene();
918
919 void KolmeDeeLogic(float dt);
920 //void LoaderLogic(float dt);
921 void ConsoleLogic(float dt);
922 void ConsoleLogic2(float dt);
923
924 typedef void (*SceneRenderCallback)();
925 SceneRenderCallback scene_render[] = {
926 &Loader,
927 &LeadMaskScene,
928 &CopScene,
929 &MarssiScene,
930 &LongScene,
931 &EyeScene,
932 &RedCircleScene,
933 &BiloThreeScene
934 };
935
936 typedef void (*SceneLogicCallback)(float);
937 SceneLogicCallback scene_logic[] = {
938 &dummy,
939 &ConsoleLogic,
940 &dummy,
941 &ConsoleLogic2,
942 &dummy,
943 &dummy,
944 &dummy,
945 &dummy
946 };
947
948 // audio
949
950 float scene_start_millis = 0;
951
952 int music_started = -1;
953
954 DWORD music_channel = 0;
955
956
957 /////////////////////////////////////////////////////////
958 //////////////////////// PLAYLIST ////////////////////////
959 ///////////////////////////////////////////////////////////
960
961 void reshape(GLint width, GLint height)
962 {
963 g_Width = width;
964 g_Height = height;
965
966 printf("--- MIDISYS ENGINE: reshape event: %dx%d\n", (int)width, (int)height);
967
968 glViewport(0, 0, g_Width, g_Height);
969 glMatrixMode(GL_PROJECTION);
970 glLoadIdentity();
971 gluPerspective(65.0, (float)g_Width / g_Height, g_nearPlane, g_farPlane);
972 glMatrixMode(GL_MODELVIEW);
973
974 glDeleteTextures(1, &fb_tex);
975 glDeleteRenderbuffersEXT(1, &depth_rb);
976 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
977 glDeleteFramebuffersEXT(1, &fb);
978
979 glDeleteTextures(1, &fb_tex2);
980 glDeleteRenderbuffersEXT(1, &depth_rb2);
981 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
982 glDeleteFramebuffersEXT(1, &fb2);
983
984 glDeleteTextures(1, &fake_framebuffer_tex);
985 glDeleteRenderbuffersEXT(1, &depth_rb3);
986 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
987 glDeleteFramebuffersEXT(1, &fake_framebuffer);
988
989 InitFBO();
990 }
991
992
993 int demo_playlist()
994 {
995 int sc = current_scene;
996 if (millis >= 0 && millis < 111844) // 55922
997 {
998 current_scene = 1; // lead masks
999 }
1000 else if (millis >= 111844 && millis < 148800)
1001 {
1002 current_scene = 2; // cops
1003 }
1004 else if (millis >= 148800 && millis < 184000)
1005 {
1006 current_scene = 3; // marssi
1007 }
1008 else if (millis >= 184000 && millis < 188737)
1009 {
1010 current_scene = 4; // "long live the new flesh"
1011 }
1012 else if (millis >= 188737 && millis < 264000)
1013 {
1014 current_scene = 5; // eye horror
1015 }
1016 else if (millis >= 264000 && millis < 300200)
1017 {
1018 current_scene = 6; // outro 1 / redcircle
1019 }
1020 else if (millis >= 300200 && millis < 320000)
1021 {
1022 current_scene = 7; // outro 2 / bilothree
1023 }
1024
1025 if (sc != current_scene)
1026 {
1027 if (current_scene == 4) {
1028 myVideoFrame->close();
1029 }
1030
1031 if (current_scene == 6)
1032 {
1033 reshape(g_Width, g_Height);
1034 }
1035 /*if(current_scene == 1)
1036 {
1037 //printf("xx XX xxxxxxxRESHAPING HAXXXXxxxxx xxx XX xx");
1038 //glutLeaveMainLoop();
1039 //glutReshapeWindow(g_Width, g_Height);
1040 //glutFullScreen();
1041 //glutMainLoop();
1042 }*/
1043 scene_start_millis = millis;
1044 vector_clear(console->lines);
1045 }
1046 }
1047
1048 ///////////////////////////////////////////////////// HELPER FUNCTIONS
1049
1050 void BassError(const char *text)
1051 {
1052 printf("BASS error(%d): %s\n",BASS_ErrorGetCode(),text);
1053 BASS_Free();
1054 exit(0);
1055 }
1056
1057 void InitAudio(const char *pFilename)
1058 {
1059 DWORD chan;
1060 QWORD pos;
1061
1062 printf("--- MIDISYS-ENGINE: InitAudio()\n");
1063
1064 if (!BASS_Init(-1,44100,0,0,NULL)) BassError("InitAudio() - can't initialize device\n");
1065
1066 printf("\tInitAudio() - loading soundtrack from file \"%s\"\n", pFilename);
1067
1068 int success = 0;
1069
1070 if ((chan=BASS_StreamCreateFile(FALSE,pFilename,0,0,BASS_STREAM_PRESCAN))
1071 || (chan=BASS_StreamCreateURL(pFilename,0,BASS_STREAM_PRESCAN,0,0))) {
1072 pos=BASS_ChannelGetLength(chan,BASS_POS_BYTE);
1073 if (BASS_StreamGetFilePosition(chan,BASS_FILEPOS_DOWNLOAD)!=-1) {
1074 // streaming from the internet
1075 if (pos!=-1)
1076 {
1077 printf("\tInitAudio() - streaming internet file [%I64u bytes]\n",pos);
1078 success = 1;
1079 }
1080 else
1081 {
1082 printf("\tstreaming internet file\n");
1083 success = 1;
1084 }
1085 } else
1086 {
1087 printf("\tstreaming file [%I64u bytes]\n",pos);
1088 success = 1;
1089 }
1090 }
1091
1092 if (success == 1)
1093 {
1094 music_channel = chan;
1095 }
1096 else
1097 {
1098 printf("InitAudio() error! could not load file.\n");
1099 exit(1);
1100 }
1101 }
1102
1103 void HexList(BYTE *pData, int iNumBytes)
1104 {
1105 int i;
1106
1107 for(i=0;i<iNumBytes;i++)
1108 printf("%.2x ", pData[i]);
1109 }
1110
1111 char *File2String(const char *path)
1112 {
1113 FILE *fd;
1114 long len,
1115 r;
1116 char *str;
1117
1118 if (!(fd = fopen(path, "r")))
1119 {
1120 fprintf(stderr, "\terror, can't open file '%s' for reading\n", path);
1121 return NULL;
1122 }
1123
1124 fseek(fd, 0, SEEK_END);
1125 len = ftell(fd);
1126
1127 #ifdef SUPERVERBOSE
1128 printf("\tshader source file \"%s\" is %ld bytes long\n", path, len);
1129 #endif
1130
1131 fseek(fd, 0, SEEK_SET);
1132
1133 if (!(str = (char*) malloc(len * sizeof(char))))
1134 {
1135 fprintf(stderr, "\terror, can't malloc space for file \"%s\"\n", path);
1136 return NULL;
1137 }
1138
1139 r = fread(str, sizeof(char), len, fd);
1140
1141 str[r - 1] = '\0'; /* Shader sources have to term with null */
1142
1143 fclose(fd);
1144
1145 return str;
1146 }
1147
1148 void PrintShaderLog(GLuint obj)
1149 {
1150 int infologLength = 0;
1151 int maxLength;
1152
1153 if(glIsShader(obj))
1154 glGetShaderiv(obj,GL_INFO_LOG_LENGTH,&maxLength);
1155 else
1156 glGetProgramiv(obj,GL_INFO_LOG_LENGTH,&maxLength);
1157
1158 char infoLog[maxLength];
1159
1160 if (glIsShader(obj))
1161 glGetShaderInfoLog(obj, maxLength, &infologLength, infoLog);
1162 else
1163 glGetProgramInfoLog(obj, maxLength, &infologLength, infoLog);
1164
1165 if (infologLength > 0)
1166 {
1167 printf("\n%s\n",infoLog);
1168 }
1169 }
1170
1171 void DebugPrintEvent(int ev, MIDI_MSG msg)
1172 {
1173 #if 0
1174 char str[128];
1175 unsigned int j;
1176 if (muGetMIDIMsgName(str, ev)) printf("%s\t", str);
1177
1178 switch(ev)
1179 {
1180 case msgNoteOff:
1181 muGetNameFromNote(str, msg.MsgData.NoteOff.iNote);
1182 printf("(%.2d) %s", msg.MsgData.NoteOff.iChannel, str);
1183 break;
1184 case msgNoteOn:
1185 muGetNameFromNote(str, msg.MsgData.NoteOn.iNote);
1186 printf("\t(%.2d) %s %d", msg.MsgData.NoteOn.iChannel, str, msg.MsgData.NoteOn.iVolume);
1187 break;
1188 case msgNoteKeyPressure:
1189 muGetNameFromNote(str, msg.MsgData.NoteKeyPressure.iNote);
1190 printf("(%.2d) %s %d", msg.MsgData.NoteKeyPressure.iChannel,
1191 str,
1192 msg.MsgData.NoteKeyPressure.iPressure);
1193 break;
1194 case msgSetParameter:
1195 muGetControlName(str, msg.MsgData.NoteParameter.iControl);
1196 printf("(%.2d) %s -> %d", msg.MsgData.NoteParameter.iChannel,
1197 str, msg.MsgData.NoteParameter.iParam);
1198 break;
1199 case msgSetProgram:
1200 muGetInstrumentName(str, msg.MsgData.ChangeProgram.iProgram);
1201 printf("(%.2d) %s", msg.MsgData.ChangeProgram.iChannel, str);
1202 break;
1203 case msgChangePressure:
1204 muGetControlName(str, msg.MsgData.ChangePressure.iPressure);
1205 printf("(%.2d) %s", msg.MsgData.ChangePressure.iChannel, str);
1206 break;
1207 case msgSetPitchWheel:
1208 printf("(%.2d) %d", msg.MsgData.PitchWheel.iChannel,
1209 msg.MsgData.PitchWheel.iPitch);
1210 break;
1211
1212 case msgMetaEvent:
1213 printf("---- ");
1214 switch(msg.MsgData.MetaEvent.iType)
1215 {
1216 case metaMIDIPort:
1217 printf("MIDI Port = %d", msg.MsgData.MetaEvent.Data.iMIDIPort);
1218 break;
1219
1220 case metaSequenceNumber:
1221 printf("Sequence Number = %d",msg.MsgData.MetaEvent.Data.iSequenceNumber);
1222 break;
1223
1224 case metaTextEvent:
1225 printf("Text = '%s'",msg.MsgData.MetaEvent.Data.Text.pData);
1226 break;
1227 case metaCopyright:
1228 printf("Copyright = '%s'",msg.MsgData.MetaEvent.Data.Text.pData);
1229 break;
1230 case metaTrackName:
1231 printf("Track name = '%s'",msg.MsgData.MetaEvent.Data.Text.pData);
1232 break;
1233 case metaInstrument:
1234 printf("Instrument = '%s'",msg.MsgData.MetaEvent.Data.Text.pData);
1235 break;
1236 case metaLyric:
1237 printf("Lyric = '%s'",msg.MsgData.MetaEvent.Data.Text.pData);
1238 break;
1239 case metaMarker:
1240 printf("Marker = '%s'",msg.MsgData.MetaEvent.Data.Text.pData);
1241 break;
1242 case metaCuePoint:
1243 printf("Cue point = '%s'",msg.MsgData.MetaEvent.Data.Text.pData);
1244 break;
1245 case metaEndSequence:
1246 printf("End Sequence");
1247 break;
1248 case metaSetTempo:
1249 printf("Tempo = %d",msg.MsgData.MetaEvent.Data.Tempo.iBPM);
1250 break;
1251 case metaSMPTEOffset:
1252 printf("SMPTE offset = %d:%d:%d.%d %d",
1253 msg.MsgData.MetaEvent.Data.SMPTE.iHours,
1254 msg.MsgData.MetaEvent.Data.SMPTE.iMins,
1255 msg.MsgData.MetaEvent.Data.SMPTE.iSecs,
1256 msg.MsgData.MetaEvent.Data.SMPTE.iFrames,
1257 msg.MsgData.MetaEvent.Data.SMPTE.iFF
1258 );
1259 break;
1260 case metaTimeSig:
1261 printf("Time sig = %d/%d",msg.MsgData.MetaEvent.Data.TimeSig.iNom,
1262 msg.MsgData.MetaEvent.Data.TimeSig.iDenom/MIDI_NOTE_CROCHET);
1263 break;
1264 case metaKeySig:
1265 if (muGetKeySigName(str, msg.MsgData.MetaEvent.Data.KeySig.iKey))
1266 printf("Key sig = %s", str);
1267 break;
1268
1269 case metaSequencerSpecific:
1270 printf("Sequencer specific = ");
1271 HexList(msg.MsgData.MetaEvent.Data.Sequencer.pData, msg.MsgData.MetaEvent.Data.Sequencer.iSize);
1272 break;
1273 }
1274 break;
1275
1276 case msgSysEx1:
1277 case msgSysEx2:
1278 printf("Sysex = ");
1279 HexList(msg.MsgData.SysEx.pData, msg.MsgData.SysEx.iSize);
1280 break;
1281 }
1282
1283 if (ev == msgSysEx1 || ev == msgSysEx1 || (ev==msgMetaEvent && msg.MsgData.MetaEvent.iType==metaSequencerSpecific))
1284 {
1285 /* Already done a hex dump */
1286 }
1287 else
1288 {
1289 printf("\t[");
1290 if (msg.bImpliedMsg) printf("%.2x!", msg.iImpliedMsg);
1291 for(j=0;j<msg.iMsgSize;j++)
1292 printf("%.2x ", msg.data[j]);
1293 printf("]\n");
1294 }
1295 #endif
1296 }
1297
1298 void LoadMIDIEventList(const char *pFilename)
1299 {
1300 printf("--- MIDISYS ENGINE: LoadMIDIEventList(\"%s\")\n", pFilename);
1301 MIDI_FILE *mf = midiFileOpen(pFilename);
1302 int ev;
1303
1304 int timeline_index = 0;
1305 int track_index = 0;
1306 MIDI_MSG msg;
1307
1308 if (mf)
1309 {
1310 int i, iNum;
1311
1312 midiReadInitMessage(&msg);
1313 iNum = midiReadGetNumTracks(mf);
1314
1315 for(i=0;i<iNum;i++)
1316 {
1317 #ifdef SUPERVERBOSE
1318 printf("# Track %d\n", i);
1319 #endif
1320 while(midiReadGetNextMessage(mf, i, &msg))
1321 {
1322 #ifdef SUPERVERBOSE
1323 printf(" %.6ld ", msg.dwAbsPos);
1324 #endif
1325
1326 if (msg.bImpliedMsg) { ev = msg.iImpliedMsg; }
1327 else { ev = msg.iType; }
1328
1329 memcpy(&timeline[track_index][timeline_index], &msg, sizeof(MIDI_MSG));
1330
1331 if (ev == msgMetaEvent && msg.MsgData.MetaEvent.iType == metaTrackName)
1332 {
1333 strncpy(timeline_trackname[track_index], msg.MsgData.MetaEvent.Data.Text.pData, 8);
1334 timeline_trackname[track_index][8] == '\0';
1335 printf("track #%d, name = \"%s\"\n", track_index, timeline_trackname[track_index]);
1336 }
1337
1338 #ifdef SUPERVERBOSE
1339 DebugPrintEvent(ev,msg);
1340 #endif
1341
1342 timeline_index++;
1343
1344 }
1345 printf("track length: %d\n", timeline_index);
1346 timeline_tracklength[track_index] = timeline_index;
1347 track_index++;
1348 timeline_index = 0;
1349 }
1350
1351 timeline_trackcount = track_index;
1352 midiReadFreeMessage(&msg);
1353
1354 midiFileClose(mf);
1355 }
1356
1357 //timeline_length = timeline_index+1;
1358 printf("--- MIDISYS ENGINE: LoadMIDIEventList() success\n");
1359 }
1360
1361 void ParseMIDITimeline(const char* mappingFile)
1362 {
1363 printf("--- MIDISYS ENGINE: ParseMIDITimeline(\"%s\")\n", mappingFile);
1364 int cnt;
1365 char *line;
1366
1367 FILE *mapfile;
1368
1369 if ((mapfile = fopen(mappingFile, "r")))
1370 {
1371 cnt = 0;
1372 while (0 == fggets(&line, mapfile)) {
1373 char* token = strtok(line, ",");
1374 int paramnum = atoi(token);
1375 mapping_paramnum[cnt] = paramnum;
1376
1377 token = strtok(NULL, ",");
1378 sprintf(mapping_trackname[cnt],"%s",token);
1379
1380 token = strtok(NULL, ",");
1381 if (strcmp("param",token) == 0) mapping_type[cnt] = 1;
1382 else mapping_type[cnt] = 0;
1383
1384 // token = strtok(NULL, ",");
1385 // sprintf(englines[cnt],"%s",token);
1386
1387 int i = 0;
1388 int found = -1;
1389 for (i = 0; i < timeline_trackcount; i++)
1390 {
1391 if (strcmp(timeline_trackname[i], mapping_trackname[cnt]) == 0)
1392 {
1393 printf("MIDI track #%d (\"%s\") maps to shader param %d, type: %s\n", i, mapping_trackname[cnt], mapping_paramnum[cnt], mapping_type[cnt] == 0 ? "trig" : "param");
1394 mapping_tracknum[cnt] = i;
1395 cnt++;
1396 found = 1;
1397 }
1398 if (found == 1) break;
1399 }
1400 }
1401 mapping_count = cnt;
1402 }
1403 else
1404 {
1405 printf("ParseMIDITimeline error: MIDI mapping file \"%s\" cannot be opened\n", mappingFile);
1406 exit(1);
1407 }
1408 printf("--- MIDISYS ENGINE: ParseMIDITimeline() success\n");
1409 }
1410
1411
1412 void stbi_flip_y(int w, int h, int comp, stbi_uc *data)
1413 {
1414 size_t y, i, stride = w * comp;
1415 uint8 *out = data;
1416
1417 for (y = 0; y < (h>>1); ++y) {
1418 stbi_uc *p1 = out + y * stride;
1419 stbi_uc *p2 = out + (h-1-y) * stride;
1420 for (i = 0; i < stride; ++i) {
1421 stbi_uc t = p1[i];
1422 p1[i] = p2[i];
1423 p2[i] = t;
1424 }
1425 }
1426 }
1427
1428 int scale_image_RGB_to_NTSC_safe(int width, int height, int channels,stbi_uc* data) {
1429 const float scale_lo = 16.0f - 0.499f;
1430 const float scale_hi = 235.0f + 0.499f;
1431 int i, j;
1432 int nc = channels;
1433
1434 unsigned char* orig = data;
1435
1436 unsigned char scale_LUT[256];
1437 /* error check */
1438 if( (width < 1) || (height < 1) ||
1439 (channels < 1) || (orig == NULL) )
1440 {
1441 /* nothing to do */
1442 return 0;
1443 }
1444 /* set up the scaling Look Up Table */
1445 for( i = 0; i < 256; ++i )
1446 {
1447 scale_LUT[i] = (unsigned char)((scale_hi - scale_lo) * i / 255.0f + scale_lo);
1448 }
1449 /* for channels = 2 or 4, ignore the alpha component */
1450 nc -= 1 - (channels & 1);
1451 /* OK, go through the image and scale any non-alpha components */
1452 for( i = 0; i < width*height*channels; i += channels )
1453 {
1454 for( j = 0; j < nc; ++j )
1455 {
1456 orig[i+j] = scale_LUT[orig[i+j]];
1457 }
1458 }
1459 return 1;
1460 }
1461
1462
1463 GLuint LoadTexture(const char* pFilename, int invert)
1464 {
1465 if(!load_textures) return;
1466
1467 if (strcmp(pFilename,"") == 0) return 99999;
1468 printf(" - LoadTexture(\"%s\")", pFilename);
1469 GLuint tex_2d;
1470 unsigned char *data;
1471 int x, y, comp;
1472
1473 FILE *file = fopen(pFilename, "rb");
1474 if (!file)
1475 return 0;
1476
1477 data = stbi_load_from_file(file, &x, &y, &comp, 0);
1478 fclose(file);
1479 //gluBuild2DMipmaps( GL_TEXTURE_2D, 4, x, y, GL_RGBA, GL_UNSIGNED_BYTE, data );
1480
1481 glGenTextures( 1, &tex_2d );
1482 glBindTexture( GL_TEXTURE_2D, tex_2d );
1483 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1484 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
1485 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
1486 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1487 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1488
1489
1490 if (invert == 1)
1491 {
1492 stbi_flip_y(x, y, comp, data);
1493 }
1494 else
1495 {
1496 }
1497
1498 scale_image_RGB_to_NTSC_safe(x,y,comp,data);
1499
1500 if( comp == 3 ) {
1501 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, x, y, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
1502 } else if( comp == 4 ) {
1503 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data );
1504 }
1505
1506
1507 if(0 == tex_2d)
1508 {
1509 printf(" error loading texture from file \"%s\"\n", pFilename);
1510 exit(1);
1511 }
1512
1513 printf(" success\n");
1514
1515 return tex_2d;
1516 }
1517
1518 GLuint LoadTexture(const char* pFilename)
1519 {
1520 return LoadTexture(pFilename, 1);
1521 }
1522
1523 int LoadGLTextures(const aiScene* scene) {
1524
1525 if (scene->HasTextures())
1526 {
1527 printf("ERROR: support for meshes with embedded textures is not implemented\n");
1528 exit(1);
1529 }
1530
1531 /* scan scene's materials for textures */
1532 for (unsigned int m=0; m<scene->mNumMaterials; m++)
1533 {
1534 int texIndex = 0;
1535 aiReturn texFound = AI_SUCCESS;
1536
1537 aiString path; // filename
1538
1539 while (texFound == AI_SUCCESS)
1540 {
1541 texFound = scene->mMaterials[m]->GetTexture(aiTextureType_DIFFUSE, texIndex, &path);
1542 GLuint texnum = LoadTexture(path.data, 0);
1543 textureIdMap[path.data] = texnum;
1544 texIndex++;
1545 }
1546 }
1547 //return success;
1548 return true;
1549 }
1550
1551 GLuint LoadShader(const char* pFilename)
1552 {
1553 fprintf(stdout," - LoadShader(\"%s\")", pFilename);
1554
1555 #ifdef SUPERVERBOSE
1556 printf("\n");
1557 #endif
1558
1559 char vsName[256] = "";
1560 strcpy(vsName, pFilename);
1561 strcat(vsName, ".vs");
1562
1563 char fsName[256] = "";
1564 strcpy(fsName, pFilename);
1565 strcat(fsName, ".fs");
1566
1567 #ifdef SUPERVERBOSE
1568 fprintf(stdout,"\tLoadShader(\"%s\") vertex shader source file: \"%s\"\n", pFilename, vsName);
1569 #endif
1570
1571 GLchar *vsSource = File2String(vsName);
1572
1573 #ifdef SUPERVERBOSE
1574 fprintf(stdout,"\tLoadShader(\"%s\") vertex shader source:\n----------------------------------------------------\n%s\n----------------------------------------------------\n", pFilename, vsSource);
1575 #endif
1576
1577 #ifdef SUPERVERBOSE
1578 fprintf(stdout,"\tLoadShader(\"%s\") fragment shader source file: \"%s\"\n", pFilename, fsName);
1579 #endif
1580
1581 GLchar *fsSource = File2String(fsName);
1582
1583 #ifdef SUPERVERBOSE
1584 fprintf(stdout,"\tLoadShader(\"%s\") fragment shader source:\n----------------------------------------------------\n%s\n----------------------------------------------------\n", pFilename, fsSource);
1585 #endif
1586
1587 GLuint vs, fs, sp;
1588
1589 #ifdef SUPERVERBOSE
1590 printf("\tLoadShader(): vs glCreateShader\n");
1591 #endif
1592 vs = glCreateShader(GL_VERTEX_SHADER);
1593 PrintShaderLog(vs);
1594 #ifdef SUPERVERBOSE
1595 printf("\tLoadShader(): vs glShaderSource\n");
1596 #endif
1597 glShaderSource(vs, 1, (const GLchar**)&vsSource, NULL);
1598 PrintShaderLog(vs);
1599 #ifdef SUPERVERBOSE
1600 printf("\tLoadShader(): vs glCompileShader\n");
1601 #endif
1602 glCompileShader(vs);
1603 PrintShaderLog(vs);
1604 #ifdef SUPERVERBOSE
1605 printf("\tLoadShader(): vs compiled\n");
1606 #endif
1607
1608 #ifdef SUPERVERBOSE
1609 printf("\tLoadShader(): fs glCreateShader\n");
1610 #endif
1611 fs = glCreateShader(GL_FRAGMENT_SHADER);
1612 PrintShaderLog(fs);
1613 #ifdef SUPERVERBOSE
1614 printf("\tLoadShader(): fs glShaderSource\n");
1615 #endif
1616 glShaderSource(fs, 1, (const GLchar**)&fsSource, NULL);
1617 PrintShaderLog(fs);
1618 #ifdef SUPERVERBOSE
1619 printf("\tLoadShader(): fs glCompileShader\n");
1620 #endif
1621 glCompileShader(fs);
1622 PrintShaderLog(fs);
1623 #ifdef SUPERVERBOSE
1624 printf("\tLoadShader(): fs compiled\n");
1625 #endif
1626
1627 free(vsSource);
1628 free(fsSource);
1629
1630 #ifdef SUPERVERBOSE
1631 printf("\tLoadShader(): glCreateProgram\n");
1632 #endif
1633 sp = glCreateProgram();
1634 PrintShaderLog(sp);
1635 #ifdef SUPERVERBOSE
1636 printf("\tLoadShader(): glAttachShader vs\n");
1637 #endif
1638 glAttachShader(sp, vs);
1639 PrintShaderLog(sp);
1640 #ifdef SUPERVERBOSE
1641 printf("\tLoadShader(): glAttachShader fs\n");
1642 #endif
1643 glAttachShader(sp, fs);
1644 PrintShaderLog(sp);
1645 #ifdef SUPERVERBOSE
1646 printf("\tLoadShader(): glLinkProgram\n");
1647 #endif
1648 glLinkProgram(sp);
1649 PrintShaderLog(sp);
1650
1651 #ifdef SUPERVERBOSE
1652 fprintf(stdout,"--- MIDISYS ENGINE: LoadShader(\"%s\") success\n", pFilename);
1653 #else
1654 printf(" success\n");
1655 #endif
1656
1657 return sp;
1658 }
1659
1660 ///////////////////////////////////////////////////////////////// EFFECTS
1661 ///////////////////////////////////////////////////////////////// EFFECTS
1662 ///////////////////////////////////////////////////////////////// EFFECTS
1663 ///////////////////////////////////////////////////////////////// EFFECTS
1664 ///////////////////////////////////////////////////////////////// EFFECTS
1665
1666
1667 // Can't send color down as a pointer to aiColor4D because AI colors are ABGR.
1668 void Color4f(const aiColor4D *color)
1669 {
1670 glColor4f(color->r, color->g, color->b, color->a);
1671 }
1672
1673 void set_float4(float f[4], float a, float b, float c, float d)
1674 {
1675 f[0] = a;
1676 f[1] = b;
1677 f[2] = c;
1678 f[3] = d;
1679 }
1680
1681 void color4_to_float4(const aiColor4D *c, float f[4])
1682 {
1683 f[0] = c->r;
1684 f[1] = c->g;
1685 f[2] = c->b;
1686 f[3] = c->a;
1687 }
1688
1689 void apply_material(const aiMaterial *mtl)
1690 {
1691 float c[4];
1692
1693 GLenum fill_mode;
1694 int ret1, ret2;
1695 aiColor4D diffuse;
1696 aiColor4D specular;
1697 aiColor4D ambient;
1698 aiColor4D emission;
1699 float shininess, strength;
1700 int two_sided;
1701 int wireframe;
1702 unsigned int max; // changed: to unsigned
1703
1704 int texIndex = 0;
1705 aiString texPath; //contains filename of texture
1706
1707 if(AI_SUCCESS == mtl->GetTexture(aiTextureType_DIFFUSE, texIndex, &texPath))
1708 {
1709 //bind texture
1710 GLuint texId = textureIdMap.at(texPath.data);
1711 if (texId != 99999) glBindTexture(GL_TEXTURE_2D, texId);
1712 }
1713
1714 set_float4(c, 0.8f, 0.8f, 0.8f, 1.0f);
1715 if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
1716 color4_to_float4(&diffuse, c);
1717 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, c);
1718
1719 set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
1720 if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &specular))
1721 color4_to_float4(&specular, c);
1722 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
1723
1724 set_float4(c, 0.2f, 0.2f, 0.2f, 1.0f);
1725 if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &ambient))
1726 color4_to_float4(&ambient, c);
1727 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, c);
1728
1729 set_float4(c, 0.0f, 0.0f, 0.0f, 1.0f);
1730 if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &emission))
1731 color4_to_float4(&emission, c);
1732 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, c);
1733
1734 max = 1;
1735 ret1 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS, &shininess, &max);
1736 max = 1;
1737 ret2 = aiGetMaterialFloatArray(mtl, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
1738 if((ret1 == AI_SUCCESS) && (ret2 == AI_SUCCESS))
1739 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess * strength);
1740 else {
1741 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
1742 set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f);
1743 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
1744 }
1745
1746 max = 1;
1747 if(AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_ENABLE_WIREFRAME, &wireframe, &max))
1748 fill_mode = wireframe ? GL_LINE : GL_FILL;
1749 else
1750 fill_mode = GL_FILL;
1751 glPolygonMode(GL_FRONT_AND_BACK, fill_mode);
1752
1753 max = 1;
1754 if((AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided)
1755 glEnable(GL_CULL_FACE);
1756 else
1757 glDisable(GL_CULL_FACE);
1758 }
1759
1760
1761 void recursive_render (const struct aiScene *sc, const struct aiNode* nd, float scale)
1762 {
1763
1764 unsigned int i;
1765 unsigned int n=0, t;
1766 aiMatrix4x4 m = nd->mTransformation;
1767
1768 aiMatrix4x4 m2;
1769 aiMatrix4x4::Scaling(aiVector3D(scale, scale, scale), m2);
1770 m = m * m2;
1771
1772 // update transform
1773 m.Transpose();
1774 glPushMatrix();
1775 glMultMatrixf((float*)&m);
1776
1777 // draw all meshes assigned to this node
1778 for (; n < nd->mNumMeshes; ++n)
1779 {
1780 const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]];
1781
1782 apply_material(sc->mMaterials[mesh->mMaterialIndex]);
1783
1784
1785 if(mesh->mNormals == NULL)
1786 {
1787 glDisable(GL_LIGHTING);
1788 }
1789 else
1790 {
1791 glEnable(GL_LIGHTING);
1792 }
1793
1794 if(mesh->mColors[0] != NULL)
1795 {
1796 glEnable(GL_COLOR_MATERIAL);
1797 }
1798 else
1799 {
1800 glDisable(GL_COLOR_MATERIAL);
1801 }
1802
1803
1804
1805 for (t = 0; t < mesh->mNumFaces; ++t) {
1806 const struct aiFace* face = &mesh->mFaces[t];
1807 GLenum face_mode;
1808
1809 switch(face->mNumIndices)
1810 {
1811 case 1: face_mode = GL_POINTS; break;
1812 case 2: face_mode = GL_LINES; break;
1813 case 3: face_mode = GL_TRIANGLES; break;
1814 default: face_mode = GL_POLYGON; break;
1815 }
1816
1817 glBegin(face_mode);
1818
1819 for(i = 0; i < face->mNumIndices; i++) // go through all vertices in face
1820 {
1821 int vertexIndex = face->mIndices[i]; // get group index for current index
1822 if(mesh->mColors[0] != NULL)
1823 Color4f(&mesh->mColors[0][vertexIndex]);
1824 if(mesh->mNormals != NULL)
1825
1826 if(mesh->HasTextureCoords(0)) //HasTextureCoords(texture_coordinates_set)
1827 {
1828 glTexCoord2f(mesh->mTextureCoords[0][vertexIndex].x, 1 - mesh->mTextureCoords[0][vertexIndex].y); //mTextureCoords[channel][vertex]
1829 }
1830
1831 glNormal3fv(&mesh->mNormals[vertexIndex].x);
1832 glVertex3fv(&mesh->mVertices[vertexIndex].x);
1833 }
1834
1835 glEnd();
1836
1837 }
1838
1839 }
1840
1841
1842 // draw all children
1843 for (n = 0; n < nd->mNumChildren; ++n)
1844 {
1845 recursive_render(sc, nd->mChildren[n], scale);
1846 }
1847
1848 glPopMatrix();
1849 }
1850 float jormymillis = 0.0;
1851 float startti = 0;
1852 float startti2 = 0;
1853 float pantime = 0;
1854 void BiloThreeScene()
1855 {
1856 float mymillis = (millis-scene_start_millis);
1857 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
1858 glUseProgram(0);
1859
1860 float colmy = mymillis*0.0001;
1861 if (colmy > 0.5) colmy = 0.5;
1862
1863 if (millis > 302800) colmy-=((millis-302800)*0.00001);
1864
1865 glClearColor(colmy, 0.0f, 0.0f, 0.0f);
1866 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1867
1868 glDisable(GL_TEXTURE_2D);
1869 glEnable(GL_BLEND);
1870 glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_DST_COLOR);
1871
1872 glShadeModel(GL_SMOOTH); // Enables Smooth Shading
1873 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
1874 glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
1875 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculation
1876
1877 glDisable(GL_LIGHTING);
1878 glEnable(GL_LIGHT0); // Uses default lighting parameters
1879 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
1880 glEnable(GL_NORMALIZE);
1881
1882 float zoom = -300.0f+(((mymillis-jormymillis)*atan(mymillis*0.005))*0.05);
1883
1884 if (zoom > -0.5 && startti == 0) { startti = mymillis; }
1885 if (zoom >= -0.5) { zoom = -0.5; jormymillis+=290;}
1886
1887 glLoadIdentity();
1888
1889 if (jormymillis > 300*60 && startti2 == 0)
1890 {
1891 startti2 = mymillis;
1892 }
1893
1894 if (jormymillis > 300*60)
1895 {
1896 pantime = mymillis-startti2;
1897 }
1898
1899 glTranslatef(0.0f, startti2 > 0 ? -7.5f-pantime*0.0008 : -7.5f, zoom+pantime*0.001*atan(pantime*0.005));
1900 if (jormymillis > 0) {
1901 glRotatef(jormymillis*0.0026,-1.0,0.0,0.0);
1902 }
1903
1904 float zoomfactor = 2.0+jormymillis*0.0001;
1905 if (zoomfactor > 4.0) zoomfactor = 4.0;
1906
1907 if (startti > 0) recursive_render(bilothree, bilothree->mRootNode, zoomfactor-0.5);
1908 recursive_render(bilothree, bilothree->mRootNode, zoomfactor);
1909 recursive_render(bilothree, bilothree->mRootNode, 6.0-zoomfactor);
1910
1911 }
1912
1913
1914
1915
1916 void KolmeDeeLogic(float dt)
1917 {
1918 kujalla_angle += dt*0.01;
1919 }
1920
1921 void kapsule_render()
1922 {
1923
1924 glEnable(GL_BLEND);
1925 glUseProgram(0);
1926 glEnable(GL_TEXTURE_2D);
1927 glShadeModel(GL_SMOOTH); // Enables Smooth Shading
1928 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
1929 glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
1930 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculation
1931
1932 glEnable(GL_LIGHTING);
1933 glEnable(GL_LIGHT0); // Uses default lighting parameters
1934 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
1935 glEnable(GL_NORMALIZE);
1936
1937 GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
1938 GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
1939 GLfloat LightPosition[]= { 0.0f, 0.0f, 15.0f, 1.0f };
1940
1941 glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
1942 glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
1943 glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
1944 glEnable(GL_LIGHT1);
1945
1946 glLoadIdentity();
1947
1948 glTranslatef(0.0f, 0.0f, -50.0f+cos(millis*0.05)*25); // Move 40 Units And Into The Screen
1949 glRotatef(millis*0.01,1.0,0,0);
1950 glRotatef(millis*0.008,0.0,0.0,1.0);
1951 glRotatef(millis*0.006,0.0,1.0,0.0);
1952
1953 recursive_render(kapsule, kapsule->mRootNode, 2.5);
1954 glDisable(GL_DEPTH_TEST);
1955 glDisable(GL_LIGHTING);
1956 glDisable(GL_NORMALIZE);
1957 }
1958
1959 float brimillis = 0.0;
1960 float bristart = 0.0;
1961 float brixrot = 0.0;
1962 float briyrot = 0.0;
1963
1964 void brieflycase_render()
1965 {
1966 if (bristart == 0) {bristart = millis;}
1967 brimillis = millis-bristart;
1968
1969 glEnable(GL_BLEND);
1970 glUseProgram(0);
1971 glEnable(GL_TEXTURE_2D);
1972 glShadeModel(GL_SMOOTH); // Enables Smooth Shading
1973 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
1974 glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
1975 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculation
1976
1977 glEnable(GL_LIGHTING);
1978 glEnable(GL_LIGHT0); // Uses default lighting parameters
1979 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
1980 glEnable(GL_NORMALIZE);
1981
1982 float brifade = 1.0f;
1983
1984 if (brimillis <= 1000) {
1985 brifade = brimillis*0.001;
1986 if (brifade > 1.0f) brifade = 1.0f;
1987 }
1988 GLfloat LightAmbient[]= { 0.5f*brifade, 0.5f*brifade, 0.5f*brifade, 1.0f*brifade };
1989 GLfloat LightDiffuse[]= { 1.0f*brifade, 1.0f*brifade, 1.0f*brifade, 1.0f*brifade };
1990 GLfloat LightPosition[]= { 0.0f, 0.0f, 15.0f*brifade, 1.0f*brifade };
1991
1992 glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
1993 glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
1994 glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
1995 glEnable(GL_LIGHT1);
1996
1997 glLoadIdentity();
1998
1999 //nosto
2000 if (brimillis > 1000 && brimillis < 3000)
2001 {
2002 briyrot=(brimillis-1000)*0.047*(1.0-(cos(brimillis*0.001)));
2003 if (briyrot > 90.0f) briyrot = 90.0f;
2004 }
2005
2006 if (brimillis > 5000)
2007 {
2008 brixrot=(brimillis-5000)*0.047*2* 1.0-(cos((brimillis-4000)*0.0001));
2009 // if (brixrot > 180.0f) brixrot = 180.0f;
2010 }
2011
2012 glTranslatef(0.0f, 0.0f, -50.0f+brixrot*0.2); // Move 40 Units And Into The Screen
2013 //glRotatef(millis*0.001,1.0,0,0);
2014 glRotatef(-briyrot,1.0,0.0,0.0);
2015 glRotatef(brixrot,0.0,0.0,1.0);
2016
2017 recursive_render(brieflycase, brieflycase->mRootNode, 2.5);
2018 glDisable(GL_DEPTH_TEST);
2019 glDisable(GL_LIGHTING);
2020 glDisable(GL_NORMALIZE);
2021 }
2022
2023
2024 void
2025 on_key_press ( unsigned char key)
2026 {
2027 if (key == 1)
2028 {
2029 console_process( console, "home", 0 );
2030 }
2031 else if (key == 4)
2032 {
2033 console_process( console, "delete", 0 );
2034 }
2035 else if (key == 5)
2036 {
2037 console_process( console, "end", 0 );
2038 }
2039 else if (key == 8)
2040 {
2041 console_process( console, "backspace", 0 );
2042 }
2043 else if (key == 9)
2044 {
2045 console_process( console, "complete", 0 );
2046 }
2047 else if (key == 11)
2048 {
2049 console_process( console, "kill", 0 );
2050 }
2051 else if (key == 12)
2052 {
2053 console_process( console, "clear", 0 );
2054 }
2055 else if (key == 13)
2056 {
2057 console_process( console, "enter", 0 );
2058 }
2059 else if (key == 25)
2060 {
2061 console_process( console, "yank", 0 );
2062 }
2063 else if (key == 27)
2064 {
2065 console_process( console, "escape", 0 );
2066 }
2067 else if (key == 127)
2068 {
2069 console_process( console, "backspace", 0 );
2070 }
2071 else if( key > 31)
2072 {
2073 console_process( console, "type", key );
2074 }
2075 }
2076
2077 /*void LoaderLogic(float dt)
2078 {
2079 printf("DEBUG: LoaderLogic(%f)\n", dt);
2080 }*/
2081
2082 int keyindex = 0;
2083 int nextmillis = 0;
2084 void ConsoleLogic(float dt)
2085 {
2086 // int kmillis = (int)(millis-15750);
2087 int kmillis = (int)(millis-scene_start_millis);
2088
2089 //printf("kmillis:%d\n",kmillis);
2090 if (kmillis >= 0 && kmillis >= keymillis[keyindex])
2091 {
2092 if(keyindex >= 0 && keyindex < KEYEVENTS_COUNT)
2093 {
2094 on_key_press(keyrec[keyindex]);
2095 }
2096
2097 keyindex++;
2098 }
2099 }
2100
2101 int keyindex2 = 0;
2102
2103 void ConsoleLogic2(float dt)
2104 {
2105 int kmillis = -2000+(int)((millis-scene_start_millis)*1.3);
2106
2107 //printf("kmillis:%d\n",kmillis);
2108 if (kmillis >= 0 && kmillis >= keymillis2[keyindex2])
2109 {
2110 if(keyindex2 >= 0 && keyindex2 < KEYEVENTS_COUNT2)
2111 {
2112 on_key_press(keyrec2[keyindex2]);
2113 }
2114
2115 keyindex2++;
2116 }
2117 }
2118
2119 int kolmedeeindex = 0;
2120
2121 const aiScene* Import3DFromFile(const std::string& pFile)
2122 {
2123 fprintf(stdout," - Import3DFromFile(\"%s\")", pFile.c_str());
2124
2125 //check if file exists
2126 std::ifstream fin(pFile.c_str());
2127 if(!fin.fail())
2128 {
2129 fin.close();
2130 }
2131 else
2132 {
2133 printf(" could not open file %s\n", pFile.c_str());
2134 exit(1);
2135 }
2136
2137 const aiScene* scener = importer[kolmedeeindex].ReadFile( pFile, aiProcessPreset_TargetRealtime_Quality);
2138
2139 // If the import failed, report it
2140 if( !scener)
2141 {
2142 printf(" import failed %s\n", pFile.c_str());
2143 exit(1);
2144 }
2145
2146 kolmedeeindex++;
2147
2148 fprintf(stdout," success\n");
2149
2150 // We're done. Everything will be cleaned up by the importer destructor
2151 return scener;
2152 }
2153
2154 int shader_index = 1; // 1 not 0 because console shader is loaded separately
2155 bool LoadShaders()
2156 {
2157 if(shader_index == sizeof(shaders) / sizeof(shaders[0])) return false;
2158 shaders[shader_index] = LoadShader(shaderss[shader_index]);
2159 shader_index++;
2160
2161 return true;
2162 }
2163 int texture_index = 0;
2164 bool LoadTextures()
2165 {
2166 if(texture_index == sizeof(textures) / sizeof(textures[0])) return false;
2167 textures[texture_index] = LoadTexture(texturess[texture_index]);
2168 texture_index++;
2169
2170 return true;
2171 }
2172 int assets_3dmodel_total = 1;
2173 bool Load3DAssets()
2174 {
2175 kapsule = Import3DFromFile("data/models/kapsule.obj");
2176 LoadGLTextures(kapsule);
2177
2178 return true;
2179 }
2180
2181 bool assets_loaded = false;
2182 int skip_frames = 10;
2183 int skip_frames_count = 0;
2184 clock_t t_loader_begin = 0, t_loader_d;
2185 int assets_index = -1, assets_total = -1;
2186 int loader_phase = -1;
2187 float loading_time = 0;
2188 void Loader()
2189 {
2190 if(t_loader_begin == 0) { current_scene = 0; t_loader_begin = clock(); assets_total = ((sizeof(shaders) / sizeof(shaders[0])) + (sizeof(textures) / sizeof(textures[0])) + assets_3dmodel_total ); } else { loading_time = (float)((((float)t_loader_d - (float)t_loader_begin) / 1000000.0F ) * 1000); }
2191 if(assets_total == -1) {
2192 printf("ERROR: Loader(): No assets to load and/or something is just terribly wrong! Terminating...\n");
2193 exit(1);
2194 }
2195
2196 float phase = (float)((float)(assets_index) / (float)(assets_total));
2197 const aiScene* loaderscene = bilothorn;
2198
2199 //glClearColor (phase,phase,phase,1.0);
2200 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2201
2202 float mymillis = phase*1750;
2203 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); // default
2204 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2205
2206 glUseProgram(0);
2207
2208 glDisable(GL_TEXTURE_2D);
2209 glEnable(GL_BLEND);
2210 glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
2211
2212 glShadeModel(GL_SMOOTH); // Enables Smooth Shading
2213 //glClearColor(1.0f-phase,1.0f-phase,1.0f-phase, 1.0f);
2214 glClearDepth(1.0f); // Depth Buffer Setup
2215 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
2216 glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
2217 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculation
2218
2219 glDisable(GL_LIGHTING);
2220 glEnable(GL_LIGHT0); // Uses default lighting parameters
2221 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
2222 glDisable(GL_NORMALIZE);
2223
2224 float r, g, b, a = 1.0f;
2225 if(loader_phase < 1) {
2226 r = g = b = sin(loading_time*100);
2227 } else {
2228 r = g = b = a;
2229 }
2230 GLfloat LightAmbient[]= { r, g, b, a };
2231 GLfloat LightDiffuse[]= { r, g, b, a };
2232 GLfloat LightPosition[]= { 0.0f, 0.0f, 15.0f, 1.0f};
2233 //GLfloat LightAmbient[]= { 0.0f, 1.0f-phase, 0.0f, 1.0f };
2234 // GLfloat LightDiffuse[]= { 0.0f, 1.0f-phase, 0.0f, 1.0f };
2235 // GLfloat LightPosition[]= { 0.0f, 0.0f, 15.0f, 1.0f };
2236
2237 glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
2238 glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
2239 glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
2240 glEnable(GL_LIGHT1);
2241
2242 float zoom = -50.0f+((mymillis)*0.05*0.2)*((phase+0.5f)*(phase+0.5f)*(phase+0.5f));
2243
2244 if (zoom > -0.5 && startti == 0) { startti = mymillis; }
2245 if (zoom >= -0.5) { zoom = -0.5; jormymillis=(mymillis-startti); }
2246
2247
2248 if (jormymillis > 0) {
2249 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2250 }
2251
2252 glLoadIdentity();
2253
2254 glRotatef(180.0f*phase*0.974,0.0,0.0,1.0);
2255 glTranslatef(0.0f, 0.0f, zoom);
2256 /*if (jormymillis > 0) {
2257 glRotatef(jormymillis*0.0026,-1.0,0.0,0.0);
2258 }*/
2259
2260 skip_frames_count++;
2261 if(skip_frames_count == skip_frames) {
2262 skip_frames_count = 0;
2263 assets_index++;
2264 printf("--- MIDISYS-ENGINE: Loading asset #%i", assets_index);
2265
2266 // begin loading animation
2267
2268 if(loader_phase == -1) {
2269 loader_phase = 0;
2270 } else if(loader_phase == 0) {
2271 if(!LoadShaders()) {
2272 loader_phase = 1;
2273 } else {
2274 }
2275 } else if(loader_phase == 1) {
2276 if(!LoadTextures()) {
2277 loader_phase = 2;
2278 } else {
2279 }
2280 } else if(loader_phase == 2) {
2281 printf("..%i", assets_total);
2282 // load all 3d models; after that all asset loading is done
2283 Load3DAssets();
2284 loader_phase = 3;
2285 } else {
2286 assets_loaded = true;
2287 }
2288 } else {
2289 // format bilotrip terminal 1.6.2.0
2290
2291 /*if(phase > 0.975f) {
2292 phase = 1.0f-phase;
2293 }*/
2294 glClearColor ((1.0f-phase)*0.86,(1.0f-phase)*0.86,(1.0f-phase)*0.86,1.0);
2295 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2296 glFlush();
2297 glutSwapBuffers();
2298 }
2299
2300 //printf("n:%i\n",(int)((float)((float)(assets_index) / (float)(assets_total)) * 3.0f));
2301 /*glBegin(GL_TRIANGLES);
2302 glVertex3f(-25.0f,-25.0f,-50.0f);
2303 glVertex3f(-25.0f,25.0f,-50.0f);
2304 glVertex3f(25.0f,25.0f,-50.0f);
2305 glEnd();*/
2306 //glTranslatef(0.0,floor(phase+0.25f),0.0);
2307 for(int n = 0; n < (int)(phase*6.9f); n++) {
2308 if(n<3) {
2309 int t = floor(n/3);
2310 float tf = (float)(t)*120.0f;
2311 if(n!=0&&n%3==0) glTranslatef(0.0,0.0,tf);
2312 glRotatef(120.0f,0.0,0.0,((float)(n)*phase));
2313 recursive_render(loaderscene, loaderscene->mRootNode, 2.0+jormymillis*0.001);
2314 }
2315 //if (jormymillis > 0)recursive_render(loaderscene, loaderscene->mRootNode, 4.0-jormymillis*0.001);
2316 }
2317
2318
2319 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
2320 glDisable(GL_BLEND);
2321 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2322
2323
2324 glUseProgram(shaders[hex]);
2325 float widthLoc5 = glGetUniformLocation(shaders[hex], "width");
2326 float heightLoc5 = glGetUniformLocation(shaders[hex], "height");
2327 float timeLoc5 = glGetUniformLocation(shaders[hex], "time");
2328 float effuLoc5 = glGetUniformLocation(shaders[hex], "effu");
2329
2330 glUniform1f(widthLoc5, g_Width);
2331 glUniform1f(heightLoc5, g_Height);
2332 glUniform1f(timeLoc5, mymillis/100);
2333 glUniform1f(effuLoc5, jormymillis > 0 ? 1.0 : 0.0);
2334
2335 glActiveTexture(GL_TEXTURE0);
2336 glBindTexture(GL_TEXTURE_2D, fb_tex);
2337
2338 float location5 = glGetUniformLocation(shaders[hex], "texture0");
2339 glUniform1i(location5, 0);
2340
2341 glLoadIdentity();
2342
2343 glTranslatef(-1.2, -1.0, -1.0);
2344 //glTranslatef(0.0, 0.0, -1.0);
2345
2346 int i=0;
2347 int j=0;
2348 glBegin(GL_QUADS);
2349 glVertex2f(i, j);
2350 glVertex2f(i + 100, j);
2351 glVertex2f(i + 100, j + 100);
2352 glVertex2f(i, j + 100);
2353 glEnd();
2354
2355 glFlush();
2356 glutSwapBuffers();
2357
2358 glDisable(GL_DEPTH_TEST); // Enables Depth Testing
2359 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); // default
2360 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
2361 glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
2362 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculation
2363 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // default
2364 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
2365
2366 if (quitflag == 0) glutPostRedisplay();
2367 }
2368
2369 int vieterframe = 0;
2370 float vieterstart = 0;
2371
2372 void LeadMaskScene()
2373 {
2374 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); // fbo
2375 glClear(GL_DEPTH_BUFFER_BIT);
2376 float mymillis = millis;
2377 glUseProgram(shaders[projector]);
2378
2379 int kuvaflag = 0;
2380
2381 if (millis >= 0 && millis < 25000) {
2382 kuvaflag = 0;
2383 }
2384 else if (millis >= 25000 && millis < 37000) {
2385 kuvaflag = 1;
2386 }
2387 else if (millis >= 37000 && millis < 48500) {
2388 kuvaflag = 2;
2389 }
2390 else if (millis >= 48500 && millis < 64000) {
2391 kuvaflag = 3;
2392 }
2393 else if (millis >= 64000 && millis < 76100) {
2394 kuvaflag = 4;
2395 }
2396 else if (millis >= 76100 && millis < 84000) {
2397 kuvaflag = 5;
2398 }
2399 else if (millis >= 84000) {
2400 kuvaflag = 6;
2401 if (vieterstart == 0) vieterstart = mymillis;
2402 vieterframe = (int)((mymillis-vieterstart)*0.004);
2403 if (vieterframe > 12) { vieterframe = 0; vieterstart = 0; }
2404 }
2405
2406 glEnable(GL_BLEND);
2407 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2408 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
2409
2410 GLint widthLoc5 = glGetUniformLocation(shaders[projector], "width");
2411 GLint heightLoc5 = glGetUniformLocation(shaders[projector], "height");
2412 GLint timeLoc5 = glGetUniformLocation(shaders[projector], "time");
2413 GLint alphaLoc5 = glGetUniformLocation(shaders[projector], "alpha");
2414
2415 glUniform1f(widthLoc5, g_Width);
2416 glUniform1f(heightLoc5, g_Height);
2417 glUniform1f(timeLoc5, mymillis - (millis < 64000 ? 0 : 50000));
2418 glUniform1f(alphaLoc5, mymillis*0.0001+0.2-cos(mymillis*0.0005)*0.15);
2419
2420 glActiveTexture(GL_TEXTURE0);
2421 if (kuvaflag == 0)
2422 glBindTexture(GL_TEXTURE_2D, textures[tex_scene]);
2423 else if (kuvaflag == 1)
2424 glBindTexture(GL_TEXTURE_2D, textures[tex_dude]);
2425 else if (kuvaflag == 2)
2426 glBindTexture(GL_TEXTURE_2D, textures[tex_dude2]);
2427 else if (kuvaflag == 3)
2428 glBindTexture(GL_TEXTURE_2D, textures[tex_mask]);
2429 else if (kuvaflag == 4)
2430 glBindTexture(GL_TEXTURE_2D, textures[tex_note]);
2431 else if (kuvaflag == 5)
2432 glBindTexture(GL_TEXTURE_2D, textures[tex_exit]);
2433 else if (kuvaflag == 6)
2434 glBindTexture(GL_TEXTURE_2D, textures[tex_v0+vieterframe]);
2435
2436 GLint location5 = glGetUniformLocation(shaders[projector], "texture0");
2437 glUniform1i(location5, 0);
2438
2439 glLoadIdentity();
2440 glTranslatef(-1.2, -1.0, -1.0);
2441
2442 glBegin(GL_QUADS);
2443
2444 int i,j;
2445
2446 for (i = -50; i < 50; i+=10)
2447 for (j = -50; j < 50; j+=10)
2448 {
2449 glVertex2f(i, j);
2450 glVertex2f(i + 1, j);
2451 glVertex2f(i + 1, j + 1);
2452 glVertex2f(i, j + 1);
2453 }
2454 glEnd();
2455
2456 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2); // default
2457
2458 glUseProgram(shaders[fsquad]);
2459
2460 glEnable(GL_BLEND);
2461 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2462 glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_DST_COLOR);
2463
2464 GLint widthLoc6 = glGetUniformLocation(shaders[fsquad], "width");
2465 GLint heightLoc6 = glGetUniformLocation(shaders[fsquad], "height");
2466 GLint timeLoc6 = glGetUniformLocation(shaders[fsquad], "time");
2467 GLint alphaLoc6 = glGetUniformLocation(shaders[fsquad], "alpha");
2468 GLint gammaLoc = glGetUniformLocation(shaders[fsquad], "gamma");
2469 GLint gridLoc6 = glGetUniformLocation(shaders[fsquad], "grid");
2470 GLint alphamodeLoc5 = glGetUniformLocation(shaders[fsquad], "alphamode");
2471 glUniform1f(alphamodeLoc5, 0.0f);
2472
2473 glUniform1f(gridLoc6, 0.001+cos(mymillis)*0.0005);
2474
2475
2476 glUniform1f(widthLoc6, g_Width);
2477 glUniform1f(heightLoc6, g_Height);
2478 glUniform1f(timeLoc6, mymillis/100);
2479 glUniform1f(alphaLoc6, 0.1+abs(cos(mymillis*0.08)*0.05));
2480 glUniform1f(gammaLoc, 0.0f);
2481
2482 glActiveTexture(GL_TEXTURE0);
2483 glBindTexture(GL_TEXTURE_2D, fb_tex);
2484
2485 GLint location6 = glGetUniformLocation(shaders[fsquad], "texture0");
2486 glUniform1i(location6, 0);
2487
2488 glLoadIdentity();
2489
2490 glTranslatef(-1.2, -1.0, -1.0);
2491
2492 i=0;
2493 j=0;
2494 glBegin(GL_QUADS);
2495 glVertex2f(i, j);
2496 glVertex2f(i + 100, j);
2497 glVertex2f(i + 100, j + 100);
2498 glVertex2f(i, j + 100);
2499 glEnd();
2500
2501 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
2502
2503 glUseProgram(shaders[fsquad]);
2504
2505 glDisable(GL_BLEND);
2506
2507 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2508
2509 GLint widthLoc7 = glGetUniformLocation(shaders[fsquad], "width");
2510 GLint heightLoc7 = glGetUniformLocation(shaders[fsquad], "height");
2511 GLint timeLoc7 = glGetUniformLocation(shaders[fsquad], "time");
2512 GLint alphaLoc7 = glGetUniformLocation(shaders[fsquad], "alpha");
2513 GLint gammaLoc2 = glGetUniformLocation(shaders[fsquad], "gamma");
2514 GLint gridLoc = glGetUniformLocation(shaders[fsquad], "grid");
2515 GLint alphamodeLoc7 = glGetUniformLocation(shaders[fsquad], "alphamode");
2516 glUniform1f(alphamodeLoc7, 0.0f);
2517
2518 glUniform1f(widthLoc7, g_Width);
2519 glUniform1f(heightLoc7, g_Height);
2520 glUniform1f(timeLoc7, mymillis/100);
2521 glUniform1f(alphaLoc7, 1.0);
2522 glUniform1f(gammaLoc2, 4.0f);
2523 glUniform1f(gridLoc, 1.0f+tan(mymillis*10)*0.3);
2524
2525 glActiveTexture(GL_TEXTURE0);
2526 glBindTexture(GL_TEXTURE_2D, fb_tex2);
2527
2528 GLint location7 = glGetUniformLocation(shaders[fsquad], "texture0");
2529 glUniform1i(location7, 0);
2530
2531 glLoadIdentity();
2532
2533 glTranslatef(-1.2, -1.0, -1.0);
2534
2535 i=0;
2536 j=0;
2537 glBegin(GL_QUADS);
2538 glVertex2f(i, j);
2539 glVertex2f(i + 100, j);
2540 glVertex2f(i + 100, j + 100);
2541 glVertex2f(i, j + 100);
2542 glEnd();
2543
2544 glUseProgram(shaders[projector]);
2545
2546 glEnable(GL_BLEND);
2547 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
2548 glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA);
2549
2550 widthLoc5 = glGetUniformLocation(shaders[projector], "width");
2551 heightLoc5 = glGetUniformLocation(shaders[projector], "height");
2552 timeLoc5 = glGetUniformLocation(shaders[projector], "time");
2553 alphaLoc5 = glGetUniformLocation(shaders[projector], "alpha");
2554
2555 glUniform1f(widthLoc5, g_Width);
2556 glUniform1f(heightLoc5, g_Height);
2557 glUniform1f(timeLoc5, mymillis);
2558 glUniform1f(alphaLoc5, 1.0);
2559
2560 glActiveTexture(GL_TEXTURE0);
2561 glBindTexture(GL_TEXTURE_2D, textures[tex_scene]);
2562
2563 location5 = glGetUniformLocation(shaders[projector], "texture0");
2564 glUniform1i(location5, 0);
2565
2566 glLoadIdentity();
2567 glTranslatef(-1.2, -1.0, -1.0);
2568
2569 glBegin(GL_QUADS);
2570
2571
2572 for (i = -50; i < 50; i+=10)
2573 for (j = -50; j < 50; j+=10)
2574 {
2575 glVertex2f(i, j);
2576 glVertex2f(i + 1, j);
2577 glVertex2f(i + 1, j + 1);
2578 glVertex2f(i, j + 1);
2579 }
2580 glEnd();
2581
2582
2583 if (millis > 37400 && millis < 37600) kapsule_render();
2584
2585
2586 }
2587
2588 int copbeatcounter = -1;
2589 int coptexid = 0;
2590 void CopScene()
2591 {
2592 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
2593
2594 float mymillis = (millis-scene_start_millis);
2595 glUseProgram(shaders[copquad]);
2596
2597 glEnable(GL_BLEND);
2598
2599
2600 float joo = cos(mymillis);
2601 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, joo < 0.5 ? GL_MODULATE : GL_SUBTRACT );
2602 glBlendFunc(GL_SRC_COLOR, joo < 0.5 ? GL_DST_ALPHA : GL_ONE_MINUS_DST_COLOR);
2603
2604 GLint widthLoc5 = glGetUniformLocation(shaders[copquad], "width");
2605 GLint heightLoc5 = glGetUniformLocation(shaders[copquad], "height");
2606 GLint timeLoc5 = glGetUniformLocation(shaders[copquad], "time");
2607 GLint alphaLoc5 = glGetUniformLocation(shaders[copquad], "alpha");
2608 GLint gridLoc6 = glGetUniformLocation(shaders[copquad], "grid");
2609 glUniform1f(gridLoc6, tan(mymillis));
2610
2611 glUniform1f(widthLoc5, g_Width);
2612 glUniform1f(heightLoc5, g_Height);
2613 glUniform1f(timeLoc5, mymillis/100);
2614 glUniform1f(alphaLoc5, cos(mymillis*0.1)*0.01);
2615
2616 if (scene_shader_params[2] == 36) { copbeatcounter++; }
2617 if (copbeatcounter > 0) { coptexid++; copbeatcounter = 0;}
2618
2619 //int texind = (int)(mymillis*(0.001/2));
2620 int texind = coptexid;
2621 if (texind > 30) texind = 30;
2622
2623 glActiveTexture(GL_TEXTURE0);
2624 glBindTexture(GL_TEXTURE_2D, textures[tex_copkiller + texind]);
2625
2626 glActiveTexture(GL_TEXTURE1);
2627 glBindTexture(GL_TEXTURE_2D, textures[texind == tex_copkiller ? tex_copkiller+17 :
2628 tex_copkiller + (abs(texind-1))]);
2629
2630 GLint location5 = glGetUniformLocation(shaders[copquad], "texture0");
2631 glUniform1i(location5, 0);
2632
2633 GLint location6 = glGetUniformLocation(shaders[copquad], "texture1");
2634 glUniform1i(location6, 1);
2635
2636 glLoadIdentity();
2637
2638 glTranslatef(-1.2, -1.0, -1.0);
2639
2640 int i=0;
2641 int j=0;
2642 glBegin(GL_QUADS);
2643 glVertex2f(i, j);
2644 glVertex2f(i + 100, j);
2645 glVertex2f(i + 100, j + 100);
2646 glVertex2f(i, j + 100);
2647 glEnd();
2648
2649 }
2650
2651 static int video_started = 0;
2652
2653 void MarssiScene()
2654 {
2655 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
2656 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
2657 glDisable(GL_BLEND);
2658
2659 if (video_started == 0)
2660 {
2661 myVideoFrame->play();
2662 video_started = 1;
2663 }
2664
2665 myVideoFrame->render();
2666 }
2667
2668 void LongScene()
2669 {
2670 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
2671 glDisable(GL_BLEND);
2672 glClearColor(0,0,0,0);
2673 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
2674
2675 glUseProgram(shaders[fsquad]);
2676 float mymillis = (((millis)-scene_start_millis));
2677
2678 GLint widthLoc5 = glGetUniformLocation(shaders[fsquad], "width");
2679 GLint heightLoc5 = glGetUniformLocation(shaders[fsquad], "height");
2680 GLint timeLoc5 = glGetUniformLocation(shaders[fsquad], "time");
2681 GLint alphaLoc5 = glGetUniformLocation(shaders[fsquad], "alpha");
2682 GLint gammaLoc = glGetUniformLocation(shaders[fsquad], "gamma");
2683 GLint gridLoc6 = glGetUniformLocation(shaders[fsquad], "grid");
2684 glUniform1f(gridLoc6, 0.0f);
2685 glUniform1f(gammaLoc, 0.0f);
2686 GLint alphamodeLoc5 = glGetUniformLocation(shaders[fsquad], "alphamode");
2687 glUniform1f(alphamodeLoc5, 0.0f);
2688
2689 glUniform1f(widthLoc5, g_Width);
2690 glUniform1f(heightLoc5, g_Height);
2691 glUniform1f(timeLoc5, mymillis/100);
2692 glUniform1f(alphaLoc5, 0.0);
2693
2694 glActiveTexture(GL_TEXTURE0);
2695 glBindTexture(GL_TEXTURE_2D, textures[tex_aegis]);
2696
2697 GLint location5 = glGetUniformLocation(shaders[fsquad], "texture0");
2698 glUniform1i(location5, 0);
2699
2700 glLoadIdentity();
2701
2702 glTranslatef(-1.2, -1.0, -1.0);
2703
2704 int i=0;
2705 int j=0;
2706 glBegin(GL_QUADS);
2707 glVertex2f(i, j);
2708 glVertex2f(i + 100, j);
2709 glVertex2f(i + 100, j + 100);
2710 glVertex2f(i, j + 100);
2711 glEnd();
2712
2713 //
2714 if (mymillis > 2500) {
2715 int plussati = 0;
2716 if (mymillis > 2800)plussati=400;
2717 glEnable(GL_BLEND);
2718 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2719 int lloff = (int)(((plussati+mymillis)-2500)*0.0025);
2720 if (lloff >= 4) lloff = 4;
2721 widthLoc5 = glGetUniformLocation(shaders[fsquad], "width");
2722 heightLoc5 = glGetUniformLocation(shaders[fsquad], "height");
2723 timeLoc5 = glGetUniformLocation(shaders[fsquad], "time");
2724 alphaLoc5 = glGetUniformLocation(shaders[fsquad], "alpha");
2725 float alphamodeLoc = glGetUniformLocation(shaders[fsquad], "alphamode");
2726
2727 glUniform1f(widthLoc5, g_Width);
2728 glUniform1f(heightLoc5, g_Height);
2729 glUniform1f(timeLoc5, mymillis/100);
2730 glUniform1f(alphaLoc5, 1.0);
2731 glUniform1f(alphamodeLoc, 1.0);
2732
2733 glActiveTexture(GL_TEXTURE0);
2734 glBindTexture(GL_TEXTURE_2D, textures[tex_ll1+lloff]);
2735
2736 GLint location5 = glGetUniformLocation(shaders[fsquad], "texture0");
2737 glUniform1i(location5, 0);
2738
2739 glLoadIdentity();
2740
2741 glTranslatef(-1.2, -1.0, -1.0);
2742
2743 int i=0;
2744 int j=0;
2745 glBegin(GL_QUADS);
2746 glVertex2f(i, j);
2747 glVertex2f(i + 100, j);
2748 glVertex2f(i + 100, j + 100);
2749 glVertex2f(i, j + 100);
2750 glEnd();
2751
2752 }
2753
2754 }
2755
2756 int majic_texnum = 0;
2757 int noclearframes = 0;
2758 void EyeScene()
2759 {
2760 int i, j;
2761
2762 int lisuri = 0;
2763
2764 //printf("millis:%f\n",millis);
2765 if (millis > 225200) lisuri = 50000+(millis-225200)*0.5;
2766 if (lisuri > 150000) lisuri = 150000;
2767
2768 float mymillis = (((millis)-scene_start_millis)*100);
2769 float mymillis2 = (((millis+lisuri)-scene_start_millis)*100);
2770 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); // fbo
2771
2772 glClearColor((float)(scene_shader_params[1]/127)*0.7,(float)(scene_shader_params[1]/127)*0.4,(float)(scene_shader_params[1]/127)*0.8,0.9-0.005*(float)(scene_shader_params[1]/127));
2773
2774 if ((scene_shader_params[0] == 65 && scene_shader_param_type[0] == 0) || noclearframes > 200)
2775 {
2776 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2777 beatmode = -beatmode;
2778 noclearframes = 0;
2779 }
2780 else
2781 {
2782 noclearframes++;
2783 }
2784
2785 // render fbo copy to fbo
2786 glEnable(GL_BLEND);
2787 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2788 glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_DST_COLOR);
2789
2790 glUseProgram(shaders[eye_post]);
2791
2792 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2793
2794 GLint widthLoc3 = glGetUniformLocation(shaders[eye_post], "width");
2795 GLint heightLoc3 = glGetUniformLocation(shaders[eye_post], "height");
2796 GLint timeLoc3 = glGetUniformLocation(shaders[eye_post], "time");
2797
2798 glUniform1f(widthLoc3, g_Width);
2799 glUniform1f(heightLoc3, g_Height);
2800 glUniform1f(timeLoc3, mymillis/100);
2801
2802 glActiveTexture(GL_TEXTURE0);
2803 glBindTexture(GL_TEXTURE_2D, fb_tex);
2804
2805 GLint location3 = glGetUniformLocation(shaders[eye_post], "texture0");
2806 glUniform1i(location3, 0);
2807
2808 glLoadIdentity();
2809
2810 glRotatef(45,0.0,0.0,1.0f);
2811 glTranslatef(-1.2, -1.0, 0.0+(tan(mymillis*0.00001)*0.1)*(millis-155520)*0.0001);
2812
2813 i=0;
2814 j=0;
2815 glBegin(GL_QUADS);
2816 glVertex2f(i, j);
2817 glVertex2f(i + 100, j);
2818 glVertex2f(i + 100, j + 100);
2819 glVertex2f(i, j + 100);
2820 glEnd();
2821
2822 // render eye
2823
2824 glEnable(GL_BLEND);
2825 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2826 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
2827
2828 glUseProgram(shaders[eye]);
2829
2830 GLfloat waveTime = 1+atan(mymillis*0.0001)*0.1,
2831 waveWidth = cos(mymillis*0.000001)*1000+atan(mymillis*0.00001)*2.0,
2832 waveHeight = sin(mymillis*0.0001)*100*atan(mymillis*0.00001)*2.0;
2833
2834 GLint waveTimeLoc = glGetUniformLocation(shaders[eye], "waveTime");
2835 GLint waveWidthLoc = glGetUniformLocation(shaders[eye], "waveWidth");
2836 GLint waveHeightLoc = glGetUniformLocation(shaders[eye], "waveHeight");
2837
2838 GLint widthLoc = glGetUniformLocation(shaders[eye], "width");
2839 GLint heightLoc = glGetUniformLocation(shaders[eye], "height");
2840
2841 GLint timeLoc = glGetUniformLocation(shaders[eye], "time");
2842
2843 glActiveTexture(GL_TEXTURE0);
2844 glBindTexture(GL_TEXTURE_2D, textures[tex_grayeye]);
2845
2846 GLuint location;
2847 location = glGetUniformLocation(shaders[eye], "texture0");
2848 glUniform1i(location, 0);
2849
2850 glLoadIdentity();
2851
2852 glTranslatef(0.0, 0.0, -150.0+sin(mymillis*0.0000004)*120);
2853 glRotatef(-75.0, 1.0, 0.0, 0.0);
2854 glRotatef(mymillis*0.01, 0.0, 0.0, 1.0);
2855
2856 glUniform1f(waveTimeLoc, waveTime);
2857 glUniform1f(waveWidthLoc, waveWidth);
2858 glUniform1f(waveHeightLoc, waveHeight);
2859
2860 glUniform1f(widthLoc, g_Width);
2861 glUniform1f(heightLoc, g_Height);
2862
2863 glUniform1f(timeLoc, mymillis2/100);
2864
2865
2866 int zoom = 0;
2867
2868 for (zoom = 0; zoom < 8; zoom++)
2869 {
2870
2871 glTranslatef(-0.01, -0.01, -0.1);
2872 glRotatef((90*zoom+mymillis*0.01)*0.1, 1.0, 0.0, 0.0);
2873 glRotatef((45*zoom+mymillis*0.01)*0.1, 0.0, 0.0, 1.0);
2874 glRotatef((25*zoom+mymillis*0.01)*0.1, 0.0, 1.0, 0.0);
2875 glBegin(GL_QUADS);
2876
2877 for (i = -50; i < 50; i+=10)
2878 for (j = -50; j < 50; j+=10)
2879 {
2880 glVertex2f(i, j);
2881 glVertex2f(i + 1, j);
2882 glVertex2f(i + 1, j + 1);
2883 glVertex2f(i, j + 1);
2884 }
2885 glEnd();
2886 }
2887
2888 // eye postprocess to screen
2889
2890 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
2891
2892 glUseProgram(shaders[eye_post]);
2893
2894 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2895
2896 glDisable(GL_BLEND);
2897
2898 GLint widthLoc2 = glGetUniformLocation(shaders[eye_post], "width");
2899 GLint heightLoc2 = glGetUniformLocation(shaders[eye_post], "height");
2900 GLint timeLoc2 = glGetUniformLocation(shaders[eye_post], "time");
2901
2902 glUniform1f(widthLoc2, g_Width);
2903 glUniform1f(heightLoc2, g_Height);
2904 glUniform1f(timeLoc2, mymillis/100);
2905
2906 glActiveTexture(GL_TEXTURE0);
2907 glBindTexture(GL_TEXTURE_2D, fb_tex);
2908
2909 if (scene_shader_params[0] != -1 && scene_shader_param_type[0] == 0)
2910 {
2911 room_texnum = (int)(rand() % 3);
2912 }
2913
2914 glActiveTexture(GL_TEXTURE1);
2915 glBindTexture(GL_TEXTURE_2D, textures[tex_room + room_texnum]);
2916
2917 GLint location2 = glGetUniformLocation(shaders[eye_post], "texture0");
2918 glUniform1i(location2, 0);
2919
2920 GLint location4 = glGetUniformLocation(shaders[eye_post], "texture1");
2921 glUniform1i(location4, 1);
2922
2923 glLoadIdentity();
2924
2925 glTranslatef(-1.2, -1.0, -1.0);
2926
2927 i=0;
2928 j=0;
2929 glBegin(GL_QUADS);
2930 glVertex2f(i, j);
2931 glVertex2f(i + 100, j);
2932 glVertex2f(i + 100, j + 100);
2933 glVertex2f(i, j + 100);
2934 glEnd();
2935
2936 // text overlay
2937
2938 if (beatmode == 1)
2939 {
2940 glUseProgram(shaders[fsquad]);
2941
2942 glEnable(GL_BLEND);
2943 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SUBTRACT);
2944 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_COLOR);
2945
2946 GLint widthLoc5 = glGetUniformLocation(shaders[fsquad], "width");
2947 GLint heightLoc5 = glGetUniformLocation(shaders[fsquad], "height");
2948 GLint timeLoc5 = glGetUniformLocation(shaders[fsquad], "time");
2949 GLint alphaLoc5 = glGetUniformLocation(shaders[fsquad], "alpha");
2950 GLint alphamodeLoc5 = glGetUniformLocation(shaders[fsquad], "alphamode");
2951 glUniform1f(alphamodeLoc5, 0.0f);
2952
2953 glUniform1f(widthLoc5, g_Width);
2954 glUniform1f(heightLoc5, g_Height);
2955 glUniform1f(timeLoc5, mymillis/100);
2956 glUniform1f(alphaLoc5, cos(mymillis*0.1)*0.1);
2957
2958 glActiveTexture(GL_TEXTURE0);
2959
2960 majic_texnum = (int)(rand() % 4);
2961
2962 glBindTexture(GL_TEXTURE_2D, textures[tex_majestic1+majic_texnum]);
2963
2964 GLint location5 = glGetUniformLocation(shaders[fsquad], "texture0");
2965 glUniform1i(location5, 0);
2966
2967 glLoadIdentity();
2968
2969 glTranslatef(-1.2, -1.0, -1.0);
2970
2971 i=0;
2972 j=0;
2973 glBegin(GL_QUADS);
2974 glVertex2f(i, j);
2975 glVertex2f(i + 100, j);
2976 glVertex2f(i + 100, j + 100);
2977 glVertex2f(i, j + 100);
2978 glEnd();
2979 }
2980
2981 }
2982
2983 int redcounter = 1;
2984
2985 void RedCircleScene()
2986 {
2987 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // fbo
2988
2989 glUseProgram(shaders[redcircle]);
2990 float mymillis = (millis-scene_start_millis)*160;
2991
2992 glClearColor(0,0,0,0);
2993 if (scene_shader_params[2] == 36) { redcounter++; }
2994 if (redcounter > 4) { redcounter = 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
2995
2996 glEnable(GL_BLEND);
2997 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
2998 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2999
3000 GLint widthLoc2 = glGetUniformLocation(shaders[redcircle], "width");
3001 GLint heightLoc2 = glGetUniformLocation(shaders[redcircle], "height");
3002
3003 glUniform1f(widthLoc2, g_Width);
3004 glUniform1f(heightLoc2, g_Height);
3005
3006 glActiveTexture(GL_TEXTURE0);
3007 glBindTexture(GL_TEXTURE_2D, textures[tex_grayeye]);
3008
3009 GLint location2 = glGetUniformLocation(shaders[redcircle], "texture0");
3010 glUniform1i(location2, 0);
3011
3012 glLoadIdentity();
3013
3014 glTranslatef(0.0, 0.0, -90.0-cos(mymillis*0.0000004)*120);
3015 glRotatef(-75.0, 1.0, 0.0, 0.0);
3016 glRotatef(mymillis*0.01, 0.0, 0.0, 1.0);
3017
3018 glBegin(GL_QUADS);
3019
3020 int i,j;
3021
3022 for (i = -50; i < 50; i+=10)
3023 for (j = -50; j < 50; j+=10)
3024 {
3025
3026 glVertex2f(i, j);
3027 glVertex2f(i + 1, j);
3028 glVertex2f(i + 1, j + 1);
3029 glVertex2f(i, j + 1);
3030 }
3031 glEnd();
3032
3033 }
3034
3035 void VHSPost(float effuon)
3036 {
3037 if (current_scene == 6) effuon = 2.0f;
3038 if (current_scene == 7) effuon = 3.0f;
3039 float mymillis = (millis-scene_start_millis);
3040
3041 if (current_scene == 1 || current_scene == 2)
3042 {
3043 if (millis > 105000 && millis < 112000) brieflycase_render();
3044 }
3045
3046 if (current_scene == 1 || current_scene == 3)
3047 {
3048 // console crap
3049 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer); // default
3050
3051 glLoadIdentity();
3052
3053 mat4_set_identity( &projection );
3054 mat4_set_identity( &model );
3055 mat4_set_identity( &view );
3056
3057 mat4_set_orthographic( &projection, 0, g_Width, 0, g_Height, -1, 1);
3058
3059 console_render( console );
3060 }
3061
3062
3063 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // default
3064 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
3065 glClearDepth(1.0f); // Depth Buffer Setup
3066
3067 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3068
3069 glUseProgram(shaders[vhs]);
3070
3071 glDisable(GL_BLEND);
3072 float widthLoc5 = glGetUniformLocation(shaders[vhs], "width");
3073 float heightLoc5 = glGetUniformLocation(shaders[vhs], "height");
3074 float timeLoc5 = glGetUniformLocation(shaders[vhs], "time");
3075 float effuLoc5 = glGetUniformLocation(shaders[vhs], "effu");
3076
3077 float beatLoc = glGetUniformLocation(shaders[vhs], "beat");
3078 float noiseLoc = glGetUniformLocation(shaders[vhs], "noisetin");
3079
3080 if ((current_scene == 2 || current_scene == 1 || current_scene == 4) && (millis > 55000 && millis < 186000))
3081 {
3082 if (scene_shader_params[2] == 36) { vhsbeat = 1.0f; vhsbeat_start = mymillis; }
3083 vhsbeat-=((mymillis-vhsbeat_start)*0.00005);
3084 if (vhsbeat <= (current_scene == 2 ? 0.2 : 0.1)) vhsbeat = (current_scene == 2 ? 0.2 : 0.1);
3085 }
3086 else if (current_scene == 3) {
3087 if (millis >= 181500 && vhsbeat_start < 181500) {
3088 vhsbeat_start = millis;
3089 //printf("START!\n");
3090 }
3091
3092 if (vhsbeat_start >= 181500)
3093 {
3094 vhsbeat = (millis-vhsbeat_start)*(0.02/30);
3095 //printf("vhsbeat:%f\n", vhsbeat);
3096 }
3097 }
3098 else if (current_scene == 6)
3099 {
3100 if (scene_shader_params[2] == 36) { vhsbeat = 1.0f; vhsbeat_start = mymillis; }
3101 vhsbeat-=((mymillis-vhsbeat_start)*0.0005);
3102 if (vhsbeat < 0.0) vhsbeat = 0.0;
3103
3104 }
3105 else{
3106 vhsbeat = 0.2;
3107 }
3108
3109 float vhsnoise = ((float)(scene_shader_params[5]))/255.0f;
3110 float adder = (((float)(scene_shader_params[4]))/255.0f)-(current_scene == 2 ? 0.2 : 0.5f);
3111
3112 if (current_scene == 4) adder = 0.0;
3113
3114 if (current_scene == 7) vhsnoise = 1.0+cos(millis*0.001);
3115
3116 if (!assets_loaded) vhsnoise=sin(loading_time*0.1);
3117
3118 glUniform1f(widthLoc5, g_Width);
3119 glUniform1f(heightLoc5, g_Height);
3120 glUniform1f(timeLoc5, mymillis/100);
3121 glUniform1f(effuLoc5, effuon);
3122 glUniform1f(beatLoc, vhsbeat+adder);
3123 glUniform1f(noiseLoc, vhsnoise);
3124
3125 glActiveTexture(GL_TEXTURE0);
3126 glBindTexture(GL_TEXTURE_2D, fake_framebuffer_tex);
3127
3128 float location5 = glGetUniformLocation(shaders[vhs], "texture0");
3129 glUniform1i(location5, 0);
3130
3131 glLoadIdentity();
3132
3133 glTranslatef(-1.2, -1.0, -1.0);
3134
3135 int i=0;
3136 int j=0;
3137 glBegin(GL_QUADS);
3138 glVertex2f(i, j);
3139 glVertex2f(i + 100, j);
3140 glVertex2f(i + 100, j + 100);
3141 glVertex2f(i, j + 100);
3142 glEnd();
3143
3144
3145 }
3146
3147
3148 ///////////////////////////////////////////////////////////////// END EFFECTS
3149 ///////////////////////////////////////////////////////////////// END EFFECTS
3150 ///////////////////////////////////////////////////////////////// END EFFECTS
3151 ///////////////////////////////////////////////////////////////// END EFFECTS
3152 ///////////////////////////////////////////////////////////////// END EFFECTS
3153
3154 // update sync from midi + mapping data
3155
3156 void UpdateShaderParams()
3157 {
3158 int intmillis = (int)millis;
3159 int i;
3160
3161
3162 for (i=0; i < mapping_count; i++)
3163 {
3164 int tracknum = mapping_tracknum[i];
3165 int trackidx = timeline_trackindex[tracknum];
3166 if (timeline_trackindex[tracknum] >= timeline_tracklength[tracknum]) continue;
3167
3168 MIDI_MSG currentMsg = timeline[tracknum][trackidx];
3169
3170
3171 int dw = (int)currentMsg.dwAbsPos;
3172 int tarkistus = (int)(dw)*1.212;
3173
3174 // flush midi to correct position if debugging
3175 if (debugmode == 1)
3176 {
3177 while (tarkistus < intmillis)
3178 {
3179 timeline_trackindex[tracknum]++;
3180 trackidx = timeline_trackindex[tracknum];
3181 MIDI_MSG currentMsg2 = timeline[tracknum][trackidx];
3182 dw = (int)currentMsg2.dwAbsPos;
3183 tarkistus = (int)(dw)*1.212;
3184 }
3185 printf("DEBUG: midi track %d flushed to position: %d\n", tracknum, tarkistus);
3186 }
3187
3188 // reset trigs
3189 if (scene_shader_param_type[mapping_paramnum[i]] == 0) scene_shader_params[mapping_paramnum[i]] = -1;
3190
3191 //if (intmillis+155520 < tarkistus*1.212) break;
3192 if (intmillis < tarkistus) continue;
3193
3194 timeline_trackindex[tracknum]++;
3195
3196 int ev = 0;
3197
3198 if (currentMsg.bImpliedMsg) { ev = currentMsg.iImpliedMsg; }
3199 else { ev = currentMsg.iType; }
3200
3201 // DebugPrintEvent(ev, currentMsg);
3202
3203 int trigVal = -1;
3204 int paramVal = -1;
3205
3206 switch(mapping_type[i])
3207 {
3208 // trig
3209 case 0:
3210 {
3211
3212 if (ev == msgNoteOn)
3213 {
3214 trigVal = currentMsg.MsgData.NoteOn.iNote;
3215 // printf("track #%d (%s), len %d, pos %d: dwAbsPos: %d (millis: %d) -> noteon: %d (shadermap num %d)\n", tracknum, timeline_trackname[tracknum], timeline_tracklength[tracknum], timeline_trackindex[tracknum], currentMsg.dwAbsPos, intmillis, trigVal, mapping_paramnum[i]);
3216 // printf("shader param %d trig: %d\n", mapping_paramnum[i], trigVal);
3217 }
3218 else if (ev == msgNoteOff)
3219 {
3220 trigVal = -1;
3221 }
3222
3223 scene_shader_params[mapping_paramnum[i]] = trigVal;
3224 scene_shader_param_type[mapping_paramnum[i]] = 0;
3225 //if (ev == msgNoteOn) printf("sync (%s): %d: trig %d to: %f\n", timeline_trackname[tracknum], intmillis, mapping_paramnum[i], scene_shader_params[mapping_paramnum[i]]);
3226 break;
3227 }
3228
3229 // param:
3230 case 1:
3231 {
3232 if (ev == msgSetParameter)
3233 {
3234 paramVal = currentMsg.MsgData.NoteParameter.iParam;
3235 scene_shader_params[mapping_paramnum[i]] = paramVal;
3236 scene_shader_param_type[mapping_paramnum[i]] = 1;
3237 //printf("sync (%s): %d: param %d to: %d\n", timeline_trackname[tracknum], intmillis, mapping_paramnum[i], scene_shader_params[mapping_paramnum[i]]);
3238 }
3239
3240 break;
3241 }
3242 }
3243 }
3244 debugmode = 0;
3245
3246 }
3247 ///////////////////////////////////////////////////////////////// MAIN LOGIC
3248
3249 void quit()
3250 {
3251 quitflag = 1;
3252 printf("--- MIDISYS ENGINE: time to quit()\n");
3253 if(!window) {
3254 glutLeaveGameMode();
3255 glutLeaveMainLoop();
3256 } else {
3257 glutDestroyWindow(window);
3258 glutLeaveMainLoop();
3259 }
3260 }
3261
3262 double min(double a, double b)
3263 {
3264 if (a<=b) return a;
3265 else return b;
3266 }
3267
3268 GLint gFramesPerSecond = 0;
3269
3270 void FPS(void) {
3271 static GLint Frames = 0; // frames averaged over 1000mS
3272 static GLuint Clock; // [milliSeconds]
3273 static GLuint PreviousClock = 0; // [milliSeconds]
3274 static GLuint NextClock = 0; // [milliSeconds]
3275
3276 ++Frames;
3277 Clock = glutGet(GLUT_ELAPSED_TIME); //has limited resolution, so average over 1000mS
3278 if ( Clock < NextClock ) return;
3279
3280 gFramesPerSecond = Frames/1; // store the averaged number of frames per second
3281
3282 PreviousClock = Clock;
3283 NextClock = Clock+1000; // 1000mS=1S in the future
3284 Frames=0;
3285 }
3286
3287 void logic()
3288 {
3289 if (assets_loaded) {
3290 if (music_started == -1) {
3291 printf("--- MIDISYS-ENGINE: total loading time: %f\n", loading_time);
3292 printf("--- MIDISYS-ENGINE: demo startup\n");
3293 BASS_ChannelPlay(music_channel,FALSE); music_started = 1;
3294 if(jump_to) { BASS_ChannelSetPosition(music_channel, jump_to, BASS_POS_BYTE); }
3295 }
3296
3297 QWORD bytepos = BASS_ChannelGetPosition(music_channel, BASS_POS_BYTE);
3298 double pos = BASS_ChannelBytes2Seconds(music_channel, bytepos);
3299 millis = (float)pos*1000*demo_speed_x;
3300
3301 if (millis > 367000) quit();
3302
3303 demo_playlist();
3304 scene_logic[current_scene](0.0f);
3305 } else {
3306 t_loader_d = clock();
3307 //scene_logic[current_scene]((float)((float)(assets_index) / (float)(assets_total)));
3308 }
3309
3310 // glutPostRedisplay();
3311 }
3312
3313 void timer(int value)
3314 {
3315 const int desiredFPS=60;
3316 glutTimerFunc(1000/desiredFPS, timer, ++value);
3317
3318 logic();
3319
3320 FPS(); //only call once per frame loop to measure FPS
3321 if (quitflag == 0) glutPostRedisplay();
3322 }
3323
3324
3325 ///////////////////////////////////////////////////////////// RENDER FUNCTION
3326
3327 void display(void)
3328 {
3329 UpdateShaderParams();
3330 scene_render[current_scene]();
3331 VHSPost(assets_loaded && current_scene <= 4 ? 1.0 : 0.0);
3332
3333 glFlush();
3334 glutSwapBuffers();
3335 frame++;
3336 logic();
3337 }
3338
3339
3340 // ----------------------------------------------------------------------------
3341 // ----------------------------------------------------------------------------
3342
3343 void keyPress(unsigned char key, int x, int y)
3344 {
3345 if (key == 27) quit();
3346 }
3347
3348 void mouseMotion(int button, int state, int x, int y)
3349 {
3350 mouseX = x;
3351 mouseY = y;
3352 }
3353
3354 void InitFBO()
3355 {
3356 glGenTextures(1, &fb_tex);
3357 glBindTexture(GL_TEXTURE_2D, fb_tex);
3358
3359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
3360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
3361 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3362 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3363
3364
3365 printf("\tframebuffer size: %dx%d\n", g_Width, g_Height);
3366 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, g_Width, g_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
3367 glGenFramebuffersEXT(1, &fb);
3368 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
3369
3370 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fb_tex, 0);
3371
3372 glGenRenderbuffersEXT(1, &depth_rb);
3373 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
3374 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, g_Width, g_Height);
3375
3376 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);
3377
3378 GLenum status;
3379 status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
3380 switch(status)
3381 {
3382 case GL_FRAMEBUFFER_COMPLETE_EXT:
3383 printf("\tInitFBO() status: GL_FRAMEBUFFER_COMPLETE\n");
3384 break;
3385 default:
3386 printf("\tInitFBO() error: status != GL_FRAMEBUFFER_COMPLETE\n");
3387 exit(1);
3388 break;
3389 }
3390
3391 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
3392 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
3393
3394
3395
3396 glGenTextures(1, &fb_tex2);
3397 glBindTexture(GL_TEXTURE_2D, fb_tex2);
3398
3399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
3400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
3401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3403
3404
3405 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, g_Width, g_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
3406 glGenFramebuffersEXT(1, &fb2);
3407 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
3408
3409 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fb_tex2, 0);
3410
3411 glGenRenderbuffersEXT(1, &depth_rb2);
3412 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb2);
3413 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, g_Width, g_Height);
3414
3415 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb2);
3416
3417 status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
3418 switch(status)
3419 {
3420 case GL_FRAMEBUFFER_COMPLETE_EXT:
3421 printf("\tInitFBO() status: GL_FRAMEBUFFER_COMPLETE\n");
3422 break;
3423 default:
3424 printf("\tInitFBO() error: status != GL_FRAMEBUFFER_COMPLETE\n");
3425 exit(1);
3426 break;
3427 }
3428
3429 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
3430 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
3431
3432 //----------
3433
3434 glGenTextures(1, &fake_framebuffer_tex);
3435 glBindTexture(GL_TEXTURE_2D, fake_framebuffer_tex);
3436
3437 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
3438 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
3439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3441
3442
3443 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, g_Width, g_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
3444 glGenFramebuffersEXT(1, &fake_framebuffer);
3445 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fake_framebuffer);
3446
3447 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fake_framebuffer_tex, 0);
3448
3449 glGenRenderbuffersEXT(1, &depth_rb3);
3450 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb3);
3451 glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, g_Width, g_Height);
3452
3453 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb3);
3454
3455 glClearColor(0.0,0.0,0.0,1.0);
3456 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3457
3458 status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
3459 switch(status)
3460 {
3461 case GL_FRAMEBUFFER_COMPLETE_EXT:
3462 printf("\tInitFBO() status: GL_FRAMEBUFFER_COMPLETE\n");
3463 break;
3464 default:
3465 printf("\tInitFBO() error: status != GL_FRAMEBUFFER_COMPLETE\n");
3466 exit(1);
3467 break;
3468 }
3469
3470 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
3471 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
3472
3473
3474
3475 }
3476
3477 void InitGraphics(int argc, char* argv[])
3478 {
3479 fprintf(stdout, "--- MIDISYS ENGINE: InitGraphics()\n");
3480 glutInit(&argc, argv);
3481
3482
3483 if(!window) {
3484 glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
3485 // 1280x720, 32bit pixel depth, 60Hz refresh rate
3486 glutGameModeString( "1280x720:32@60" );
3487
3488 // start fullscreen game mode
3489 glutEnterGameMode();
3490 } else {
3491 window = glutCreateWindow("majestic twelve by bilotrip");
3492 glutReshapeWindow(c_Width, c_Height);
3493 }
3494
3495 glutSetCursor(GLUT_CURSOR_NONE);
3496
3497 GLenum err = glewInit();
3498 if (GLEW_OK != err)
3499 {
3500 /* Problem: glewInit failed, something is seriously wrong. */
3501 fprintf(stderr, "\tInitGraphics() error: %s\n", glewGetErrorString(err));
3502 exit(1);
3503 }
3504 fprintf(stdout, "\tInitGraphics() status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
3505
3506 glEnable(GL_TEXTURE_2D);
3507
3508 glShadeModel(GL_SMOOTH);
3509
3510 #ifdef __APPLE__
3511 int swap_interval = 1;
3512 CGLContextObj cgl_context = CGLGetCurrentContext();
3513 CGLSetParameter(cgl_context, kCGLCPSwapInterval, &swap_interval);
3514 #endif
3515
3516 glutDisplayFunc(display);
3517 glutReshapeFunc(reshape);
3518 glutIdleFunc(logic);
3519 glutKeyboardFunc(keyPress);
3520 glutMouseFunc(mouseMotion);
3521 glutTimerFunc(0,timer,0);
3522
3523 fprintf(stdout, "--- MIDISYS ENGINE: InitGraphics() success\n");
3524 }
3525
3526 void StartMainLoop()
3527 {
3528 printf("--- MIDISYS ENGINE: StartMainLoop()\n");
3529 glutMainLoop();
3530 }
3531
3532 int main(int argc, char* argv[])
3533 {
3534 printf("--- MIDISYS ENGINE: bilotrip foundation MIDISYS ENGINE 4.20 - dosing, please wait\n");
3535
3536 // init graphics
3537
3538 InitGraphics(argc, argv);
3539
3540 // init console
3541
3542 console = console_new();
3543 shader = shader_load("data/shaders/v3f-t2f-c4f.vert",
3544 shaderss[0]);
3545
3546 // load & init video
3547
3548 printf("--- nu laddar vi en videofilmen, det aer jaetteroligt att fuska poe Assembly\n");
3549
3550 OggPlayer ogg("data/video/video.ogg",AF_S16,2,44100,VF_BGRA);
3551 if(ogg.fail()) {
3552 printf("could not open video file \"%s\"\n", "data/video/video.ogg\n");
3553 return -2;
3554 }
3555 YUVFrame yuv_frame(ogg);
3556 myVideoFrame = &yuv_frame;
3557
3558 // init MIDI sync and audio
3559
3560 LoadMIDIEventList("data/music/midicontrols_final.mid");
3561 ParseMIDITimeline("data/music/mapping.txt");
3562 InitAudio("data/music/UusiArtistiNimi_-_The_March_compoVersion.mp3");
3563
3564 // Loader assets
3565
3566 bilothorn = Import3DFromFile("data/models/bilotrip_logo_thorn.3ds");
3567 LoadGLTextures(bilothorn);
3568 biloflat = Import3DFromFile("data/models/bilotrip_logo_flat.obj");
3569 LoadGLTextures(biloflat);
3570 bilothree = Import3DFromFile("data/models/bilotrip.3ds");
3571 LoadGLTextures(bilothree);
3572 bilotetra = Import3DFromFile("data/models/bilotrip_logo_tetra.obj");
3573 LoadGLTextures(bilotetra);
3574 brieflycase = Import3DFromFile("data/models/brieflycase.obj");
3575 LoadGLTextures(brieflycase);
3576
3577 // start mainloop
3578
3579 StartMainLoop();
3580
3581 return 0;
3582 }