source: trunk/tools/neercs/video/render.cpp @ 2816

Last change on this file since 2816 was 2816, checked in by lolbot, 8 years ago

fixed 542 files out of 2754:

  • removed 0 CR characters
  • removed 0 trailing whitespaces
  • replaced 0 tabs with spaces
  • fixed 542 svn:eol-style properties
  • Property svn:eol-style set to LF
File size: 56.3 KB
Line 
1//
2// Neercs
3//
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#include <cmath>
10#include <cstdio>
11#include <cstdlib>
12#include <ctime>
13#include <string>
14
15#include "core.h"
16#include "lolgl.h"
17#include "loldebug.h"
18
19using namespace std;
20using namespace lol;
21
22#include "../neercs.h"
23#include "render.h"
24#include "text-render.h"
25
26LOLFX_RESOURCE_DECLARE(simple);
27LOLFX_RESOURCE_DECLARE(blurh);
28LOLFX_RESOURCE_DECLARE(blurv);
29LOLFX_RESOURCE_DECLARE(glow);
30LOLFX_RESOURCE_DECLARE(remanence);
31LOLFX_RESOURCE_DECLARE(copper);
32LOLFX_RESOURCE_DECLARE(color);
33LOLFX_RESOURCE_DECLARE(noise);
34LOLFX_RESOURCE_DECLARE(postfx);
35LOLFX_RESOURCE_DECLARE(mirror);
36LOLFX_RESOURCE_DECLARE(radial);
37
38#define PID F_PI/180.0f    // pi ratio
39
40/*
41 * Global variable -- ugly (<rez> sam: c'est toi qui est ugly! \:D/)
42 */
43bool g_setup = false;
44
45/*
46 * Various variables
47 */
48
49int active = true;         // window active flag
50float nearplane = 0.1f;    // nearplane
51float farplane = 1000.0f;  // farplane
52/* timer variable */
53float timer = 0;           // timer
54/* window variable */
55ivec2 screen_size;         // screen size
56/* object variable */
57float main_angle = 0.0f;   // main angle
58float part_angle = 0.0f;   // part angle
59float fx_angle;            // current angle
60/* fs_quad variable */
61float fs_quad_vtx[] =
62{
63    -1.0f,  1.0f, 0, 1.0f,
64    -1.0f, -1.0f, 0, 1.0f,
65     1.0f, -1.0f, 0, 1.0f,
66     1.0f,  1.0f, 0, 1.0f
67};
68/* flash variable */
69bool flash_flag = false;   // flag
70float flash_angle = 0;     // angle
71float flash_value = 0;     // value
72float flash_speed = 2.0f;  // speed
73/* fade variable */
74bool fade_flag = false;    // flag
75float fade_angle = 0;      // angle
76float fade_value = 0;      // value
77float fade_speed = 0.2f;   // speed
78/* sync variable */
79bool sync_flag = false;    // flagsh
80float sync_angle = 0;      // angle
81float sync_value = 0;      // value
82float sync_speed = 1.0f;   // speed
83/* beat variable */
84bool beat_flag = false;    // flag
85float beat_angle = 0;      // angle
86float beat_value = 0;      // value
87float beat_speed = 2.0f;   // speed
88/* common variable */
89float value, angle, radius, scale, speed;
90/* text variable */
91ivec2 map_size(256,256);   // texture map size
92ivec2 canvas_char(0,0);    // canvas char number
93ivec2 canvas_size(0,0);    // caca size
94ivec2 font_size(8,8);      // font size
95ivec2 ratio_2d(1,1);       // 2d ratio
96ivec2 border(0,0);         // border width
97/* shader variable */
98vec2 buffer;               // [new frame mix,old frame mix]
99vec2 remanence;            // remanence [source mix,buffer mix]
100vec2 glow_mix;             // glow mix [source mix,glow mix]
101vec2 glow_large;           // large glow radius [center,corner]
102vec2 glow_small;           // small glow radius [center,corner]
103vec2 blur;                 // blur radius [center,corner]
104vec4 copper_copper;        // copper [base,variable,repeat,color cycle]
105vec3 copper_mask_color;    // color [red,green,blue]
106vec3 color_filter;         // color filter [red,green,blue]
107vec4 color_color;          // color modifier [brightness,contrast,level,grayscale]
108vec2 noise_offset;         // random line [horizontal,vertical]
109float noise_noise;         // noise
110vec3 noise_retrace;        // retrace [strength,length,speed]
111vec2 postfx_deform;        // deformation [ratio,zoom]
112float postfx_vignetting;   // vignetting strength
113float postfx_aberration;   // chromatic aberration
114vec4 postfx_ghost1;        // ghost picture 1 [position x,position y,position z,strength]
115vec4 postfx_ghost2;        // ghost picture 2 [position x,position y,position z,strength]
116vec3 postfx_gradient;      // gradient [position y,height,strength]
117vec3 postfx_gradient_color;// gradient color [red,green,blue]
118vec4 postfx_glass;         // glass [depth,thickness,strength,deform ratio]
119vec4 postfx_moire_h;       // vertical moire [base,variable,repeat,shift]
120vec4 postfx_moire_v;       // horizontal moire [base,variable,repeat,shift]
121vec4 postfx_scanline_h;    // vertical scanline [base,variable,repeat,shift]
122vec4 postfx_scanline_v;    // horizontal scanline [base,variable,repeat,shift]
123vec3 postfx_corner;        // corner [width,radius,blur]
124vec4 mirror;               // mirror [width,height,strength,ratio]
125vec4 radial;               // radial [distance,fade ratio,iteration,strength]
126/* theme variable */
127int theme_i = 0;           // current theme
128const int theme_n = 5;     // theme number
129int theme_var_key = 0;     // theme array key
130/* setup variable */
131bool setup_switch = false;      // switch [option/item]
132int setup_n = 0;                // item/option number
133int setup_h = 8;                // height
134int setup_cursor = 0;           // cursor position
135int setup_option_i = 0;         // selected option
136const int setup_option_n = 15;  // option number
137int setup_option_p = 0;         // option position
138int setup_item_i = 0;           // selected item
139int setup_item_n = 8;           // item number
140int setup_item_p = 0;           // item position
141int setup_item_key = 0;         // item array key
142ivec3 setup_size(29, 9, 12);    // size [w,h,split]
143ivec2 setup_canvas_size(ivec2(setup_size.x + 1, setup_size.y + 1) * font_size * ivec2(2,4));
144ivec2 setup_color(0xaaa, 0x222);// color [foreground,background] 0x678,0x234
145char const *setup_text[]={
146    "main",
147        "2d ratio w",
148        "2d ratio h",
149        "border w",
150        "border h",
151        "",
152        "",
153        "",
154        "",
155    "remanence",
156        "buffer new frame",
157        "buffer old frame",
158        "source mix",
159        "buffer mix",
160        "",
161        "",
162        "",
163        "",
164    "glow",
165        "source mix",
166        "glow mix",
167        "large center",
168        "large corner",
169        "small center",
170        "small corner",
171        "",
172        "",
173    "blur",
174        "blur center",
175        "blur corner",
176        "",
177        "",
178        "",
179        "",
180        "",
181        "",
182    "screen",
183        "deform ratio",
184        "zoom base",
185        "corner width",
186        "corner radius",
187        "corner blur",
188        "vignetting",
189        "",
190        "",
191    "copper",
192        "base",
193        "variable",
194        "repeat",
195        "color cycle",
196        "color r",
197        "color g",
198        "color b",
199        "",
200    "color",
201        "filter red",
202        "filter green",
203        "filter blue",
204        "brightness",
205        "contrast",
206        "level",
207        "grayscale",
208        "aberration",
209    "noise",
210        "offset h",
211        "offset v",
212        "noise",
213        "retrace strength",
214        "retrace length",
215        "retrace speed",
216        "",
217        "",
218    "ghost",
219        "back x",
220        "back y",
221        "back z",
222        "back strength",
223        "front x",
224        "front y",
225        "front z",
226        "front strength",
227    "gradient",
228        "position",
229        "thickness",
230        "strength",
231        "color r",
232        "color g",
233        "color b",
234        "",
235        "",
236    "glass",
237        "depth",
238        "thickness",
239        "strength",
240        "deform ratio",
241        "",
242        "",
243        "",
244        "",
245    "moire",
246        "h base",
247        "h variable",
248        "h repeat",
249        "h shift",
250        "v base",
251        "v variable",
252        "v repeat",
253        "v shift",
254    "scanline",
255        "h base",
256        "h variable",
257        "h repeat",
258        "h shift",
259        "v base",
260        "v variable",
261        "v repeat",
262        "v shift",
263    "mirror",
264        "enable",
265        "width",
266        "height",
267        "strength",
268        "ratio",
269        "",
270        "",
271        "",
272    "radial",
273        "distance",
274        "fade ratio",
275        "iteration",
276        "strength",
277        "",
278        "",
279        "",
280        "",
281    ""
282    };
283
284vec4 setup_conf[]={ // setup variable [start,end,step,value]
285vec4(0), /* main */
286    vec4(1,  8, 1, 0), // ratio_2d.x
287    vec4(1,  8, 1, 0), // ratio_2d.y
288    vec4(0, 16, 1, 0), // border.x
289    vec4(0, 16, 1, 0), // border.y
290    vec4(0),
291    vec4(0),
292    vec4(0),
293    vec4(0),
294vec4(0), /* remanence */
295    vec4(0.0f, 1.0f, 0.1f, 0), // buffer.x
296    vec4(0.0f, 1.0f, 0.1f, 0), // buffer.y
297    vec4(0.0f, 1.0f, 0.1f, 0), // remanence.x
298    vec4(0.0f, 1.0f, 0.1f, 0), // remanence.y
299    vec4(0),
300    vec4(0),
301    vec4(0),
302    vec4(0),
303vec4(0), /* glow */
304    vec4(0.0f, 1.0f, 0.1f, 0), // glow_mix.x
305    vec4(0.0f, 1.0f, 0.1f, 0), // glow_mix.y
306    vec4(0.0f, 4.0f, 0.1f, 0), // glow_large.x
307    vec4(0.0f, 4.0f, 0.1f, 0), // glow_large.y
308    vec4(0.0f, 2.0f, 0.1f, 0), // glow_small.x
309    vec4(0.0f, 2.0f, 0.1f, 0), // glow_small.y
310    vec4(0),
311    vec4(0),
312vec4(0), /* blur */
313    vec4(0, 2, 0.05f, 0), // blur.x
314    vec4(0, 2, 0.05f, 0), // blur.y
315    vec4(0),
316    vec4(0),
317    vec4(0),
318    vec4(0),
319    vec4(0),
320    vec4(0),
321vec4(0), /* screen */
322    vec4(0.0f, 1.0f, 0.05f, 0), // postfx_deform.x
323    vec4(0.2f, 0.7f, 0.01f, 0), // postfx_deform.y
324    vec4(0.0f, 4.0f, 0.10f, 0), // postfx_corner.x
325    vec4(0.0f, 1.0f, 0.05f, 0), // postfx_corner.y
326    vec4(0.8f, 1.0f, 0.01f, 0), // postfx_corner.z
327    vec4(0.0f, 1.0f, 0.10f, 0), // postfx_vignetting
328    vec4(0),
329    vec4(0),
330vec4(0), /* copper */
331    vec4(0.0f, 1.0f, 0.05f, 0), // copper_copper.x
332    vec4(0.0f, 1.0f, 0.05f, 0), // copper_copper.y
333    vec4(0.0f, 1.0f, 0.02f, 0), // copper_copper.z
334    vec4(1.0f, 8.0f, 0.25f, 0), // copper_copper.w
335    vec4(0.0f, 1.0f, 0.05f, 0), // copper_mask_color.x
336    vec4(0.0f, 1.0f, 0.05f, 0), // copper_mask_color.y
337    vec4(0.0f, 1.0f, 0.05f, 0), // copper_mask_color.z
338    vec4(0),
339vec4(0), /* color */
340    vec4( 0.0f, 1.0f, 0.05f, 0), // color_filter.x
341    vec4( 0.0f, 1.0f, 0.05f, 0), // color_filter.y
342    vec4( 0.0f, 1.0f, 0.05f, 0), // color_filter.z
343    vec4( 0.0f, 2.0f, 0.05f, 0), // color_color.x
344    vec4( 0.0f, 2.0f, 0.05f, 0), // color_color.y
345    vec4(-1.0f, 1.0f, 0.05f, 0), // color_color.z
346    vec4( 0.0f, 1.0f, 0.05f, 0), // color_color.w
347    vec4( 0.0f, 8.0f, 0.50f, 0), // postfx_aberration
348vec4(0), /* noise */
349    vec4(0.0f, 4.0f, 0.50f, 0), // noise_offset.x
350    vec4(0.0f, 4.0f, 0.50f, 0), // noise_offset.y
351    vec4(0.0f, 0.5f, 0.05f, 0), // noise_noise
352    vec4(0.0f, 4.0f, 0.25f, 0), // noise_retrace.x
353    vec4(0.0f, 8.0f, 0.50f, 0), // noise_retrace.y
354    vec4(0.0f, 4.0f, 0.25f, 0), // noise_retrace.z
355    vec4(0),
356    vec4(0),
357vec4(0), /* ghost */
358    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost1.x
359    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost1.y
360    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost1.z
361    vec4(-1.0f, 1.0f, 0.05f, 0), // postfx_ghost1.w
362    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost2.x
363    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost2.y
364    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost2.z
365    vec4(-1.0f, 1.0f, 0.05f, 0), // postfx_ghost2.w
366vec4(0), /* gradient */
367    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient.x
368    vec4( 0.0f, 0.5f, 0.05f, 0), // postfx_gradient.y
369    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_gradient.z
370    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient_color.x
371    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient_color.y
372    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient_color.z
373    vec4(0),
374    vec4(0),
375vec4(0), /* glass */
376    vec4(0.0f, 16.0f, 0.50f, 0), // postfx_glass.x
377    vec4(0.0f,  1.0f, 0.05f, 0), // postfx_glass.y
378    vec4(0.0f,  2.0f, 0.05f, 0), // postfx_glass.z
379    vec4(0.0f,  1.0f, 0.05f, 0), // postfx_glass.w
380    vec4(0),
381    vec4(0),
382    vec4(0),
383    vec4(0),
384vec4(0), /* moire */
385    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_moire_h.x
386    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_moire_h.y
387    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_h.z
388    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_h.w
389    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_moire_v.x
390    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_moire_v.y
391    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_v.z
392    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_v.w
393vec4(0), /* scanline */
394    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_scanline_h.x
395    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_scanline_h.y
396    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_h.z
397    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_h.w
398    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_scanline_v.x
399    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_scanline_v.y
400    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_v.z
401    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_v.w
402vec4(0), /* mirror */
403    vec4(0.0f, 2.0f, 0.05f, 0), // mirror.x
404    vec4(0.0f, 2.0f, 0.05f, 0), // mirror.y
405    vec4(0.0f, 1.0f, 0.05f, 0), // mirror.z
406    vec4(1.0f, 8.0f, 1.00f, 0), // mirror.w
407    vec4(0),
408    vec4(0),
409    vec4(0),
410    vec4(0),
411vec4(0), /* radial blur */
412    vec4(2.0f, 8.0f, 0.25f, 0), // radial.x
413    vec4(0.8f, 1.0f, 0.01f, 0), // radial.y
414    vec4(2.0f,32.0f, 2.00f, 0), // radial.z
415    vec4(0.0f, 1.0f, 0.05f, 0), // radial.w
416    vec4(0),
417    vec4(0),
418    vec4(0),
419    vec4(0),
420vec4(0) /* ? */
421};
422
423float theme_var[]={
424/* default */
4250,
426    1,1,                      // ratio_2d
427    0,0,                      // border
428    0,0,0,0,
4290,
430    1.0f,0.8f,                // buffer
431    0.0f,0.0f,                // remanence
432    0,0,0,0,
4330,
434    0.5f,0.0f,                // glow_mix
435    0.0f,0.0f,                // glow_large
436    0.0f,0.0f,                // glow_small
437    0,0,
4380,
439    0.0f,0.0f,                // blur
440    0,0,0,0,0,0,
4410,
442    0.0f,0.5f,                // postfx_deform
443    0.0f,1.0f,1.0f,           // postfx_corner
444    0.0f,                     // postfx_vignetting
445    0,0,
4460,
447    0.75f,0.25f,0.42f,4.0f,   // copper_copper
448    0.05f,1.0f,0.0f,          // copper_mask_color
449    0,
4500,
451    1.0f,1.0f,1.0f,           // color_filter
452    1.0f,1.0f,0.0f,0.0f,      // color_color
453    0.0f,                     // postfx_aberration
4540,
455    0.0f,0.0f,                // noise_offset
456    0.0f,                     // noise_noise
457    0.0f,0.0f,0.0f,           // noise_retrace
458    0,0,
4590,
460    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost1
461    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost2
4620,
463    0.5f,0.0f,0.0f,           // postfx_gradient
464    0.0f,0.0f,0.0f,           // postfx_gradient_color
465    0,0,
4660,
467    8.0f,0.0f,0.0f,0.0f,      // postfx_glass
468    0,0,0,0,
4690,
470    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
471    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_v
4720,
473    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_h
474    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_v
4750,
476    0.0f,0.0f,0.0f,1.0f,      // mirror
477    0,0,0,0,
4780,
479    4.0f,0.9f,1,0.0f,         // radial
480    0,0,0,0,
481/* crt */
4820,
483    2,3,                      // ratio_2d
484    2,1,                      // border
485    0,0,0,0,
4860,
487    0.2f,0.8f,                // buffer
488    0.6f,0.4f,                // remanence
489    0,0,0,0,
4900,
491    0.7f,0.3f,                // glow_mix
492    3.0f,0.0f,                // glow_large
493    1.5f,0.0f,                // glow_small
494    0,0,
4950,
496    0.5f,0.0f,                // blur
497    0,0,0,0,0,0,
4980,
499    0.8f,0.48f,               // postfx_deform
500    0.0f,0.8f,0.96f,          // postfx_corner
501    0.5f,                     // postfx_vignetting
502    0,0,
5030,
504    0.75f,0.25f,0.42f,4.0f,   // copper_copper
505    0.05f,1.0f,0.0f,          // copper_mask_color
506    0,
5070,
508    0.9f,0.95f,0.85f,         // color_filter
509    1.0f,1.25f,0.1f,0.4f,     // color_color
510    4.0f,                     // postfx_aberration
5110,
512    1.0f,1.0f,                // noise_offset
513    0.15f,                    // noise_noise
514    1.0f,1.0f,0.5f,           // noise_retrace
515    0,0,
5160,
517    1.0f,0.0f,0.0f,-0.25f,    // postfx_ghost1
518    1.5f,0.0f,0.0f,0.25f,     // postfx_ghost2
5190,
520    0.5f,0.25f,0.05f,         // postfx_gradient
521    0.9f,0.8f,0.5f,           // postfx_gradient_color
522    0,0,
5230,
524    8.0f,0.25f,0.75f,0.2f,    // postfx_glass
525    0,0,0,0,
5260,
527    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
528    0.75f,-0.25f,0.25f,0.25f, // postfx_moire_v
5290,
530    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_h
531    0.75f,-0.25f,0.5f,0.0f,   // postfx_scanline_v
5320,
533    0.95f,0.9f,0.5f,4.0f,     // mirror
534    0,0,0,0,
5350,
536    4.0f,0.9f,16,0.25f,       // radial
537    0,0,0,0,
538/* amber screen */
5390,
540    2,4,                      // ratio_2d
541    1,0,                      // border
542    0,0,0,0,
5430,
544    0.2f,0.8f,                // buffer
545    0.6f,0.4f,                // remanence
546    0,0,0,0,
5470,
548    0.4f,0.6f,                // glow_mix
549    4.0f,0.0f,                // glow_large
550    2.0f,0.0f,                // glow_small
551    0,0,
5520,
553    0.5f,0.0f,                // blur
554    0,0,0,0,0,0,
5550,
556    0.7f,0.5f,                // postfx_deform
557    0.0f,0.85f,0.98f,         // postfx_corner
558    0.5f,                     // postfx_vignetting
559    0,0,
5600,
561    0.75f,0.25f,0.42f,4.0f,   // copper_copper
562    0.05f,1.0f,0.0f,          // copper_mask_color
563    0,
5640,
565    1.0f,0.7f,0.0f,           // color_filter
566    1.0f,1.25f,0.1f,1.0f,     // color_color
567    1.5f,                     // postfx_aberration
5680,
569    1.0f,0.0f,                // noise_offset
570    0.25f,                    // noise_noise
571    1.0f,2.0f,2.0f,           // noise_retrace
572    0,0,
5730,
574    1.0f,0.0f,0.0f,-0.25f,    // postfx_ghost1
575    1.5f,0.0f,0.0f,0.25f,     // postfx_ghost2
5760,
577    0.0f,0.25f,0.1f,          // postfx_gradient
578    0.25f,0.5f,0.5f,          // postfx_gradient_color
579    0,0,
5800,
581    8.0f,0.0f,0.0f,0.0f,      // postfx_glass
582    0,0,0,0,
5830,
584    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
585    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_v
5860,
587    0.6f,0.4f,1.0f,0.0f,      // postfx_scanline_h
588    0.9f,0.1f,0.75f,0.0f,     // postfx_scanline_v
5890,
590    0.6f,0.6f,0.5f,4.0f,      // mirror
591    0,0,0,0,
5920,
593    4.0f,0.84f,16,0.25f,      // radial
594    0,0,0,0,
595/* lcd */
5960,
597    2,2,                      // ratio_2d
598    1,1,                      // border
599    0,0,0,0,
6000,
601    0.7f,0.3f,                // buffer
602    0.5f,0.5f,                // remanence
603    0,0,0,0,
6040,
605    0.5f,0.5f,                // glow_mix
606    2.4f,0.0f,                // glow_large
607    1.2f,0.0f,                // glow_small
608    0,0,
6090,
610    0.25f,0.0f,               // blur
611    0,0,0,0,0,0,
6120,
613    0.0f,0.5f,                // postfx_deform
614    0.0f,1.0f,1.0f,           // postfx_corner
615    0.0f,                     // postfx_vignetting
616    0,0,
6170,
618    0.75f,0.25f,0.42f,4.0f,   // copper_copper
619    0.05f,1.0f,0.0f,          // copper_mask_color
620    0,
6210,
622    1.0f,1.0f,0.9f,           // color_filter
623    1.15f,1.25f,-0.1f,0.25f,  // color_color
624    3.0f,                     // postfx_aberration
6250,
626    0.0f,0.0f,                // noise_offset
627    0.15f,                    // noise_noise
628    0.0f,0.0f,0.0f,           // noise_retrace
629    0,0,
6300,
631    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost1
632    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost2
6330,
634    0.25f,0.5f,0.1f ,         // postfx_gradient
635    0.7f,0.9f,1.0f,           // postfx_gradient_color
636    0,0,
6370,
638    8.0f,0.0f,0.0f,0.0f,      // postfx_glass
639    0,0,0,0,
6400,
641    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
642    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_v
6430,
644    0.75f,0.25f,0.7f,0.0f,    // postfx_scanline_h
645    0.75f,0.25f,0.7f,0.0f,    // postfx_scanline_v
6460,
647    0.0f,0.0f,0.0f,1.0f,      // mirror
648    0,0,0,0,
6490,
650    4.0f,0.9f,1,0.0f,         // radial
651    0,0,0,0,
652/* granpa tv */
6530,
654    2,4,                      // ratio_2d
655    1,0,                      // border
656    0,0,0,0,
6570,
658    0.2f,0.8f,                // buffer
659    0.6f,0.4f,                // remanence
660    0,0,0,0,
6610,
662    0.4f,0.6f,                // glow_mix
663    2.4f,2.0f,                // glow_large
664    1.2f,1.0f,                // glow_small
665    0,0,
6660,
667    0.5f,0.5f,                // blur
668    0,0,0,0,0,0,
6690,
670    1.0f,0.5f,                // postfx_deform
671    0.0f,0.5f,0.9f,           // postfx_corner
672    0.5f,                     // postfx_vignetting
673    0,0,
6740,
675    0.75f,0.25f,0.42f,4.0f,   // copper_copper
676    0.05f,1.0f,0.0f,          // copper_mask_color
677    0,
6780,
679    0.7f,0.8f,1.0f,           // color_filter
680    0.9f,1.1f,0.0f,1.0f,      // color_color
681    0.0f,                     // postfx_aberration
6820,
683    2.0f,0.0f,                // noise_offset
684    0.25f,                    // noise_noise
685    1.0f,1.0f,4.0f,           // noise_retrace
686    0,0,
6870,
688    -1.0f,0.0f,0.0f,-0.25f,   // postfx_ghost1
689    1.0f,0.0f,0.0f,-0.25f,    // postfx_ghost2
6900,
691    0.5f,0.25f,0.05f,         // postfx_gradient
692    0.9f,0.8f,0.5f,           // postfx_gradient_color
693    0,0,
6940,
695    8.0f,0.0f,0.0f,0.0f,      // postfx_glass
696    0,0,0,0,
6970,
698    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
699    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_v
7000,
701    0.75f,-0.25f,0.75f,0.0f,  // postfx_scanline_h
702    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_v
7030,
704    0.95f,0.9f,0.5f,4.0f,     // mirror
705    0,0,0,0,
7060,
707    4.0f,0.9f,16,0.5f,        // radial
708    0,0,0,0,
709/* intex system 4000 */
7100};
711
712void Render::InitShaderVar()
713{
714    int k = theme_i * setup_option_n * 9 + 1; /* main */
715    ratio_2d = vec2(theme_var[k], theme_var[k + 1]); k += 2;
716    border = vec2(theme_var[k], theme_var[k + 1]); k += 2;
717    k += 5; /* remanence */
718    buffer = vec2(theme_var[k], theme_var[k + 1]); k += 2;
719    remanence = vec2(theme_var[k], theme_var[k + 1]); k += 2;
720    k += 5; /* glow */
721    glow_mix = vec2(theme_var[k], theme_var[k + 1]); k += 2;
722    glow_large = vec2(theme_var[k], theme_var[k + 1]); k += 2;
723    glow_small = vec2(theme_var[k], theme_var[k + 1]); k += 2;
724    k += 3; /* blur */
725    blur = vec2(theme_var[k], theme_var[k + 1]); k += 2;
726    k += 7; /* screen */
727    postfx_deform = vec2(theme_var[k], theme_var[k + 1]); k += 2;
728    postfx_corner = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
729    postfx_vignetting = theme_var[k]; k++;
730    k += 3; /* copper */
731    copper_copper = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
732    copper_mask_color = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
733    k += 2; /* color */
734    color_filter = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
735    color_color = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
736    postfx_aberration = theme_var[k]; k++;
737    k += 1; /* noise */
738    noise_offset = vec2(theme_var[k], theme_var[k + 1]); k += 2;
739    noise_noise = theme_var[k]; k++;
740    noise_retrace = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
741    k += 3; /* ghost */
742    postfx_ghost1 = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
743    postfx_ghost2 = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
744    k += 1; /* gradient */
745    postfx_gradient = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
746    postfx_gradient_color = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
747    k += 3; /* glass */
748    postfx_glass = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
749    k += 5; /* moire */
750    postfx_moire_h = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
751    postfx_moire_v = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
752    k += 1; /* scanline */
753    postfx_scanline_h = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
754    postfx_scanline_v = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
755    k += 1; /* mirror */
756    mirror = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
757    k += 5; /* radial blur */
758    radial = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
759}
760
761void Render::UpdateSize()
762{
763    screen_size = Video::GetSize();
764    canvas_char = (screen_size - border * ratio_2d * font_size * 2) / (font_size * ratio_2d);
765    canvas_char = max(canvas_char, ivec2(1, 1));
766    canvas_size = canvas_char * font_size * ratio_2d;
767
768    border = (screen_size - canvas_size) / 2;
769
770    caca_set_canvas_size(m_cv_screen, canvas_char.x, canvas_char.y);
771    caca_set_canvas_size(m_cv_setup, setup_size.x + 1, setup_size.y + 1);
772}
773
774int calc_item_length()
775{
776    int n = !setup_switch ? setup_option_n : setup_item_n;
777    for (int i = 0; i < n; i++)
778    {
779        int k = !setup_switch ? (i * (setup_item_n + 1)) : (setup_option_i * (setup_item_n + 1) + 1 + i);
780        if (setup_text[k][0] == '\0') return i - 1;
781    }
782    return n - 1;
783}
784
785Shader *shader_simple;
786Shader *shader_blur_h, *shader_blur_v, *shader_glow;
787Shader *shader_remanence, *shader_copper, *shader_color;
788Shader *shader_noise, *shader_postfx, *shader_mirror, *shader_radial;
789// shader variables
790ShaderUniform shader_simple_texture;
791ShaderUniform shader_blur_h_texture,
792              shader_blur_h_radius,
793              shader_blur_v_texture,
794              shader_blur_v_radius;
795ShaderUniform shader_glow_glow,
796              shader_glow_source,
797              shader_glow_mix;
798ShaderUniform shader_remanence_source,
799              shader_remanence_buffer,
800              shader_remanence_mix;
801ShaderUniform shader_copper_texture,
802              shader_copper_screen_size,
803              shader_copper_time,
804              shader_copper_copper,
805              shader_copper_mask_color;
806ShaderUniform shader_color_texture,
807              shader_color_screen_size,
808              shader_color_filter,
809              shader_color_color,
810              shader_color_flash;
811ShaderUniform shader_noise_texture,
812              shader_noise_screen_size,
813              shader_noise_time,
814              shader_noise_offset,
815              shader_noise_noise,
816              shader_noise_retrace;
817ShaderUniform shader_postfx_texture,
818              shader_postfx_texture_2d,
819              shader_postfx_screen_size,
820              shader_postfx_ratio_2d,
821              shader_postfx_time,
822              shader_postfx_deform,
823              shader_postfx_ghost1,
824              shader_postfx_ghost2,
825              shader_postfx_glass,
826              shader_postfx_vignetting,
827              shader_postfx_gradient,
828              shader_postfx_gradient_color,
829              shader_postfx_aberration,
830              shader_postfx_moire_h,
831              shader_postfx_moire_v,
832              shader_postfx_scanline_h,
833              shader_postfx_scanline_v,
834              shader_postfx_corner,
835              shader_postfx_sync,
836              shader_postfx_beat;
837ShaderUniform shader_mirror_texture,
838              shader_mirror_screen_size,
839              shader_mirror_mirror;
840ShaderUniform shader_radial_texture,
841              shader_radial_screen_size,
842              shader_radial_radial;
843
844Framebuffer *fbo_back, *fbo_front, *fbo_screen;
845Framebuffer *fbo_blur_h, *fbo_blur_v;
846Framebuffer *fbo_tmp, *fbo_buffer;
847
848void Render::TraceQuad()
849{
850    glLoadIdentity();
851    glDrawArrays(GL_QUADS, 0, 4);
852}
853
854void Render::ShaderSimple(Framebuffer *fbo_output, int n)
855{
856    shader_simple->Bind();
857    shader_simple->SetUniform(shader_simple_texture, fbo_output->GetTexture(), n);
858    TraceQuad();
859    shader_simple->Unbind();
860}
861
862int Render::InitDraw(void)
863{
864    glDepthMask(GL_TRUE);     // do not write z-buffer
865
866    /* initialise framebuffer objects */
867    fbo_back = new Framebuffer(screen_size);
868    fbo_screen = new Framebuffer(screen_size);
869    fbo_front = new Framebuffer(screen_size);
870    fbo_buffer = new Framebuffer(screen_size);
871    fbo_blur_h = new Framebuffer(screen_size);
872    fbo_blur_v = new Framebuffer(screen_size);
873    fbo_tmp = new Framebuffer(screen_size);
874    // shader simple
875    shader_simple = Shader::Create(LOLFX_RESOURCE_NAME(simple));
876    shader_simple_texture = shader_simple->GetUniformLocation("texture");
877    // shader glow
878    shader_glow = Shader::Create(LOLFX_RESOURCE_NAME(glow));
879    shader_glow_glow = shader_glow->GetUniformLocation("glow");
880    shader_glow_source = shader_glow->GetUniformLocation("source");
881    shader_glow_mix = shader_glow->GetUniformLocation("mix");
882    // shader blur horizontal
883    shader_blur_h = Shader::Create(LOLFX_RESOURCE_NAME(blurh));
884    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
885    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
886    // shader blur vertical
887    shader_blur_v = Shader::Create(LOLFX_RESOURCE_NAME(blurv));
888    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
889    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
890    // shader remanence
891    shader_remanence = Shader::Create(LOLFX_RESOURCE_NAME(remanence));
892    shader_remanence_source = shader_remanence->GetUniformLocation("source");
893    shader_remanence_buffer = shader_remanence->GetUniformLocation("buffer");
894    shader_remanence_mix = shader_remanence->GetUniformLocation("mix");
895    // shader copper
896    shader_copper = Shader::Create(LOLFX_RESOURCE_NAME(copper));
897    shader_copper_texture = shader_copper->GetUniformLocation("texture");
898    shader_copper_screen_size = shader_copper->GetUniformLocation("screen_size");
899    shader_copper_time = shader_copper->GetUniformLocation("time");
900    shader_copper_copper = shader_copper->GetUniformLocation("copper");
901    shader_copper_mask_color = shader_copper->GetUniformLocation("mask_color");
902    // shader color
903    shader_color = Shader::Create(LOLFX_RESOURCE_NAME(color));
904    shader_color_texture = shader_color->GetUniformLocation("texture");
905    shader_color_screen_size = shader_color->GetUniformLocation("screen_size");
906    shader_color_filter = shader_color->GetUniformLocation("filter");
907    shader_color_color = shader_color->GetUniformLocation("color");
908    shader_color_flash = shader_color->GetUniformLocation("flash");
909    // shader noise
910    shader_noise = Shader::Create(LOLFX_RESOURCE_NAME(noise));
911    shader_noise_texture = shader_noise->GetUniformLocation("texture");
912    shader_noise_screen_size = shader_noise->GetUniformLocation("screen_size");
913    shader_noise_time = shader_noise->GetUniformLocation("time");
914    shader_noise_offset = shader_noise->GetUniformLocation("offset");
915    shader_noise_noise = shader_noise->GetUniformLocation("noise");
916    shader_noise_retrace = shader_noise->GetUniformLocation("retrace");
917    // shader postfx
918    shader_postfx = Shader::Create(LOLFX_RESOURCE_NAME(postfx));
919    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
920    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
921    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
922    shader_postfx_ratio_2d = shader_postfx->GetUniformLocation("ratio_2d");
923    shader_postfx_time = shader_postfx->GetUniformLocation("time");
924    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
925    shader_postfx_ghost1 = shader_postfx->GetUniformLocation("ghost1");
926    shader_postfx_ghost2 = shader_postfx->GetUniformLocation("ghost2");
927    shader_postfx_glass = shader_postfx->GetUniformLocation("glass");
928    shader_postfx_gradient = shader_postfx->GetUniformLocation("gradient");
929    shader_postfx_gradient_color = shader_postfx->GetUniformLocation("gradient_color");
930    shader_postfx_vignetting = shader_postfx->GetUniformLocation("vignetting");
931    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
932    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
933    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
934    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
935    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
936    shader_postfx_corner = shader_postfx->GetUniformLocation("corner");
937    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
938    shader_postfx_beat = shader_postfx->GetUniformLocation("beat");
939    // shader mirror
940    shader_mirror = Shader::Create(LOLFX_RESOURCE_NAME(mirror));
941    shader_mirror_texture = shader_mirror->GetUniformLocation("texture");
942    shader_mirror_screen_size = shader_mirror->GetUniformLocation("screen_size");
943    shader_mirror_mirror = shader_mirror->GetUniformLocation("mirror");
944    // shader radial blur
945    shader_radial = Shader::Create(LOLFX_RESOURCE_NAME(radial));
946    shader_radial_texture = shader_radial->GetUniformLocation("texture");
947    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
948    shader_radial_radial = shader_radial->GetUniformLocation("radial");
949    // initialize setup
950    setup_n = calc_item_length();
951    return true;
952}
953
954int Render::CreateGLWindow()
955{
956    InitShaderVar();
957    UpdateSize();
958    InitDraw();
959    return true;
960}
961
962Render::Render(caca_canvas_t *caca)
963  : m_cv_screen(caca),
964    m_cv_setup(caca_create_canvas(1, 1)),
965    m_fps_debug(0),
966    m_ready(false),
967    m_pause(false),
968    m_shader(true),
969    m_shader_remanence(true),
970    m_shader_glow(true),
971    m_shader_blur(true),
972    m_shader_postfx(true),
973    m_shader_copper(true),
974    m_shader_color(true),
975    m_shader_noise(true),
976    m_shader_mirror(true),
977    m_shader_radial(true)
978{
979    m_txt_screen = new TextRender(m_cv_screen, font_size);
980    m_txt_setup = new TextRender(m_cv_setup, font_size);
981}
982
983void Render::TickGame(float seconds)
984{
985    Entity::TickGame(seconds);
986    /* draw setup */
987    if (g_setup)
988    {
989        /* background */
990        caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
991        caca_fill_box(m_cv_setup, 0, 0, setup_size.x + 1, setup_size.y,' ');
992        caca_draw_line(m_cv_setup, setup_size.z - 1, 1, setup_size.z - 1, setup_size.y - 1,'|');
993        /* title */
994        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
995        caca_draw_line(m_cv_setup, 0, 0, setup_size.x, 0, ' ');
996        caca_put_str(m_cv_setup, setup_size.x / 2 - 3, 0, "SETUP");
997        /* informations */
998        /*
999        int w = caca_get_canvas_width(m_cv_screen);
1000        int h = caca_get_canvas_height(m_cv_screen);
1001        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
1002        caca_printf(m_cv_setup, 1, 0, "%i*%i", w, h);
1003        */
1004        /* display option */
1005        for (int i = 0; i < setup_h; i++)
1006        {
1007            int y = 1 + i;
1008            int k = (setup_option_p + i) * (setup_item_n + 1);
1009            if (setup_option_i != setup_option_p + i || setup_switch)
1010            {
1011                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
1012                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
1013            }
1014            else
1015            {
1016                caca_set_color_argb(m_cv_setup, setup_color.y, 0x0f0);//setup_color.x);
1017                caca_draw_line(m_cv_setup, 0, y, setup_size.z - 2, y,' ');
1018                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
1019            }
1020        }
1021        /* display item */
1022        for (int i = 0; i < setup_h; i++)
1023        {
1024            int y = 1 + i;
1025            int k = setup_option_i * (setup_item_n + 1) + 1 + setup_item_p + i;
1026            if (setup_item_i != setup_item_p + i || !setup_switch)
1027            {
1028                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
1029                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
1030            }
1031            else
1032            {
1033                caca_set_color_argb(m_cv_setup, setup_color.y, 0x0f0);//setup_color.x);
1034                caca_draw_line(m_cv_setup, setup_size.z, y, setup_size.x, y,' ');
1035                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
1036            }
1037        }
1038        /* display variable */
1039        int y = setup_size.y;
1040        setup_item_key = setup_option_i * (setup_item_n + 1) + 1 + setup_item_i;
1041        theme_var_key = theme_i * setup_option_n * 9 + setup_item_key;
1042        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
1043        caca_draw_line(m_cv_setup, 0, y, setup_size.x, y,' ');
1044        if (setup_switch)
1045        {
1046            int x = 1;
1047            int w = setup_size.x - 3 - 4;
1048            float bar_w = w / (setup_conf[setup_item_key].y - setup_conf[setup_item_key].x);
1049            int bar_x = bar_w * setup_conf[setup_item_key].x;
1050            if ((setup_conf[setup_item_key].y - setup_conf[setup_item_key].x) / setup_conf[setup_item_key].z > 1)
1051            {
1052                /* work around a bug in libcaca */
1053                if (setup_size.x - 4 < caca_get_canvas_width(m_cv_setup)) caca_printf(m_cv_setup, setup_size.x - 4, y, "%4.2f", theme_var[theme_var_key]);
1054                caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * setup_conf[setup_item_key].y), y,'.');
1055                if (theme_var[theme_var_key] != setup_conf[setup_item_key].x) caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * theme_var[theme_var_key]), y, 'x');
1056            }
1057            else
1058            {
1059                if (setup_conf[setup_item_key] != vec4(0))
1060                {
1061                    caca_put_str(m_cv_setup, setup_size.x - 3, y, (theme_var[theme_var_key] == setup_conf[setup_item_key].y)?"YES":" NO");
1062                }
1063            }
1064        }
1065        else
1066        {
1067            caca_printf(m_cv_setup, 1, y, "%d/%d", setup_option_i, setup_n);
1068        }
1069    }
1070
1071}
1072
1073void Render::Pause()
1074{
1075    m_pause=!m_pause;
1076}
1077
1078void Render::TickDraw(float seconds)
1079{
1080    /* keyboard manager */
1081    if (Input::WasPressed(Key::F1))
1082    {
1083        g_setup = !g_setup;
1084        if (g_setup) setup_n = calc_item_length();
1085        sync_flag = true;
1086        sync_angle = main_angle;
1087        if (m_fps_debug)
1088        {
1089            Ticker::Unref(m_fps_debug);
1090            m_fps_debug = NULL;
1091        }
1092        if (g_setup)
1093        {
1094            m_fps_debug = new DebugFps(2, 2);
1095            Ticker::Ref(m_fps_debug);
1096        }
1097    }
1098    if (Input::WasPressed(Key::F2))
1099    {
1100        m_shader_remanence = !m_shader_remanence;
1101        m_shader_glow = !m_shader_glow;
1102        m_shader_blur = !m_shader_blur;
1103        m_shader_postfx = !m_shader_postfx;
1104        //m_shader_copper = !m_shader_copper;
1105        m_shader_color = !m_shader_color;
1106        m_shader_noise = !m_shader_noise;
1107        m_shader_mirror = !m_shader_mirror;
1108        m_shader_radial = !m_shader_radial;
1109    }
1110    if (Input::WasPressed(Key::F4))
1111    {
1112        theme_i--;
1113        if(theme_i < 0) theme_i = theme_n - 1;
1114        InitShaderVar();
1115        UpdateSize();
1116    }
1117    if (Input::WasPressed(Key::F5))
1118    {
1119        theme_i++;
1120        if(theme_i > theme_n - 1) theme_i = 0;
1121        InitShaderVar();
1122        UpdateSize();
1123    }
1124    if (Input::WasPressed(Key::Tab))
1125    {
1126        if (g_setup)
1127        {
1128            setup_switch = !setup_switch;
1129            setup_n = calc_item_length();
1130            setup_cursor = (!setup_switch?setup_option_i:setup_item_i) - (!setup_switch?setup_option_p:setup_item_p);
1131        }
1132    }
1133    if (Input::WasPressed(Key::Up))
1134    {
1135        if (g_setup)
1136        {
1137            if (!setup_switch)
1138            {
1139                if (setup_cursor > 0)
1140                {
1141                    setup_cursor--;
1142                }
1143                else
1144                {
1145                    if (setup_cursor == 0) setup_option_p--;
1146                }
1147                if (setup_option_i > 0)
1148                {
1149                    setup_option_i--;
1150                }
1151                else
1152                {
1153                    setup_option_i = setup_option_n - 1;
1154                    setup_option_p = setup_option_n - setup_h;
1155                    setup_cursor = setup_h - 1;
1156                }
1157                setup_item_i = 0;
1158                setup_item_p = 0;
1159            }
1160            else
1161            {
1162                if (setup_cursor > 0)
1163                {
1164                    setup_cursor--;
1165                }
1166                else
1167                {
1168                    if (setup_cursor == 0) setup_item_p--;
1169                }
1170                if (setup_item_i > 0)
1171                {
1172                    setup_item_i--;
1173                }
1174                else
1175                {
1176                    setup_item_i = setup_n;
1177                    setup_item_p = (setup_n < setup_h) ? 0 : setup_n - setup_h + 1;
1178                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
1179                }
1180            }
1181        }
1182    }
1183    if (Input::WasPressed(Key::Down))
1184    {
1185        if (g_setup)
1186        {
1187            if (!setup_switch)
1188            {
1189                if (setup_cursor < setup_h - 1)
1190                {
1191                    setup_cursor++;
1192                }
1193                else
1194                {
1195                    if (setup_cursor == setup_h - 1) setup_option_p++;
1196                }
1197                if (setup_option_i < setup_option_n - 1)
1198                {
1199                    setup_option_i++;
1200                }
1201                else
1202                {
1203                    setup_option_i = 0;
1204                    setup_option_p = 0;
1205                    setup_cursor = 0;
1206                }
1207                setup_item_i = 0;
1208                setup_item_p = 0;
1209            }
1210            else
1211            {
1212                if (setup_cursor < setup_h - 1)
1213                {
1214                    setup_cursor++;
1215                }
1216                else
1217                {
1218                    if (setup_cursor == setup_h - 1) setup_item_p++;
1219                }
1220                if (setup_item_i < setup_n)
1221                {
1222                    setup_item_i++;
1223                }
1224                else
1225                {
1226                    setup_item_i = 0;
1227                    setup_item_p = 0;
1228                    setup_cursor = 0;
1229                }
1230            }
1231        }
1232    }
1233    if (Input::WasPressed(Key::PageUp))
1234    {
1235        if (g_setup)
1236        {
1237            if (!setup_switch)
1238            {
1239                if (setup_cursor > 0)
1240                {
1241                    setup_option_i -= setup_cursor;
1242                    setup_cursor = 0;
1243                }
1244                else
1245                {
1246                    if (setup_option_i > setup_h)
1247                    {
1248                        setup_option_i -= setup_h;
1249                        setup_option_p -= setup_h;
1250                    }
1251                else
1252                    {
1253                        setup_option_i = 0;
1254                        setup_option_p = 0;
1255                    }
1256                }
1257            setup_item_i = 0;
1258            }
1259            else
1260            {
1261                if (setup_cursor > 0)
1262                {
1263                    setup_item_i -= setup_cursor;
1264                    setup_cursor = 0;
1265                }
1266                else
1267                {
1268                    if (setup_item_i > setup_h)
1269                    {
1270                        setup_item_i -= setup_h;
1271                        setup_item_p -= setup_h;
1272                    }
1273                else
1274                    {
1275                        setup_item_i = 0;
1276                        setup_item_p = 0;
1277                    }
1278                }
1279            }
1280        }
1281    }
1282    if (Input::WasPressed(Key::PageDown))
1283    {
1284        if (g_setup)
1285        {
1286            if (!setup_switch)
1287            {
1288                if (setup_cursor < setup_h - 1)
1289                {
1290                    setup_option_i += setup_h - setup_cursor - 1;
1291                    setup_cursor = setup_h - 1;
1292                    setup_item_i = 0;
1293                }
1294                else
1295                {
1296                    if (setup_option_i < setup_option_n - setup_h - 1)
1297                    {
1298                        setup_option_i += setup_h;
1299                        setup_option_p += setup_h;
1300                    }
1301                else
1302                    {
1303                        setup_option_i = setup_option_n - 1;
1304                        setup_option_p = setup_option_n - setup_h;
1305                    }
1306                }
1307            }
1308            else
1309            {
1310                if (setup_cursor < setup_h - 1)
1311                {
1312                    setup_item_i += (setup_n < setup_h) ? setup_n - setup_cursor : setup_h - setup_cursor - 1;
1313                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
1314                }
1315                else
1316                {
1317                    if (setup_item_i < setup_n - setup_h + 1)
1318                    {
1319                        setup_item_i += setup_h;
1320                        setup_item_p += setup_h;
1321                    }
1322                else
1323                    {
1324                        setup_item_i = setup_n;
1325                        setup_item_p = setup_n - setup_h + 1;
1326                    }
1327                }
1328            }
1329        }
1330    }
1331    if (Input::WasPressed(Key::Left))
1332    {
1333        if (g_setup && setup_switch)
1334        {
1335            theme_var[theme_var_key] -= setup_conf[setup_item_key].z;
1336            if (theme_var[theme_var_key] < setup_conf[setup_item_key].x) theme_var[theme_var_key] = setup_conf[setup_item_key].x;
1337            InitShaderVar();
1338            UpdateSize();
1339        }
1340    }
1341    if (Input::WasPressed(Key::Right))
1342    {
1343        if (g_setup && setup_switch)
1344        {
1345            theme_var[theme_var_key] += setup_conf[setup_item_key].z;
1346            if (theme_var[theme_var_key] > setup_conf[setup_item_key].y) theme_var[theme_var_key] = setup_conf[setup_item_key].y;
1347            InitShaderVar();
1348            UpdateSize();
1349        }
1350    }
1351    if (Input::WasPressed(Key::Home))
1352    {
1353        if (g_setup && setup_switch)
1354        {
1355            theme_var[theme_var_key] = setup_conf[setup_item_key].x;
1356            InitShaderVar();
1357            UpdateSize();
1358        }
1359    }
1360    if (Input::WasPressed(Key::End))
1361    {
1362        if (g_setup && setup_switch)
1363        {
1364            theme_var[theme_var_key] = setup_conf[setup_item_key].y;
1365            InitShaderVar();
1366            UpdateSize();
1367        }
1368    }
1369    if (Input::WasPressed(Key::Return))
1370    {
1371        beat_flag = true;
1372        beat_angle = main_angle;
1373        //flash_flag = true;
1374        //flash_angle = main_angle;
1375    }
1376
1377    Entity::TickDraw(seconds);
1378
1379    if (!m_ready)
1380    {
1381        CreateGLWindow();
1382        m_txt_screen->Init();
1383        m_txt_setup->Init();
1384        m_ready = true;
1385    }
1386
1387    // timer
1388    if (!m_pause)
1389    {
1390        timer += seconds;
1391        main_angle = timer * 100.0f * PID;
1392    }
1393    if (sync_flag)
1394    {
1395        angle = (main_angle - sync_angle) * sync_speed;
1396        sync_value = 1.0f - sinf(angle);
1397        if (angle > 90.0f * PID)
1398        {
1399            sync_value = 0;
1400            sync_flag = false;
1401        }
1402    }
1403    if (beat_flag)
1404    {
1405        angle = (main_angle - beat_angle) * beat_speed;
1406        beat_value = 1.0f - sinf(angle);
1407        if (angle > 90.0f * PID)
1408        {
1409            beat_value = 0;
1410            beat_flag = false;
1411        }
1412    }
1413    if (flash_flag)
1414    {
1415        angle = (main_angle - flash_angle) * flash_speed;
1416        flash_value = 1.0f - sinf(angle);
1417        if (angle > 90.0f * PID)
1418        {
1419            flash_value = 0;
1420            flash_flag = false;
1421        }
1422    }
1423    if (fade_flag)
1424    {
1425        angle = (main_angle - fade_angle) * fade_speed;
1426        fade_value = 1.0f - sinf(angle);
1427        if (angle > 90.0f * PID)
1428        {
1429            fade_value = 0;
1430            fade_flag = false;
1431        }
1432    }
1433
1434    Draw2D();
1435    Draw3D();
1436}
1437
1438void Render::Draw2D()
1439{
1440    /* Draw text in an offline buffer */
1441    m_txt_screen->Render();
1442
1443    if (g_setup)
1444        m_txt_setup->Render();
1445
1446    if (m_shader)
1447        fbo_back->Bind();
1448
1449    glViewport(0, 0, screen_size.x, screen_size.y);
1450
1451    /* Clear the back buffer */
1452
1453    RenderContext rc;
1454    rc.SetBlendFunc(BlendFunc::SrcColor, BlendFunc::DstAlpha);
1455    rc.SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
1456    rc.SetClearDepth(1.0f); // set depth buffer
1457
1458    glEnable(GL_TEXTURE_2D);
1459
1460    g_renderer->Clear(ClearMask::Color | ClearMask::Depth);
1461
1462    m_txt_screen->Blit(border, canvas_size);
1463    if (g_setup)
1464        m_txt_setup->Blit((screen_size - setup_canvas_size) / 2, setup_canvas_size);
1465
1466    glMatrixMode(GL_PROJECTION);
1467    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
1468    glLoadMatrixf(&m[0][0]);
1469    glMatrixMode(GL_MODELVIEW);
1470
1471    fx_angle = main_angle - part_angle;
1472}
1473
1474void Render::Draw3D()
1475{
1476    if (!m_shader)
1477        return;
1478
1479    RenderContext rc;
1480    rc.SetBlendFunc(BlendFunc::Disabled, BlendFunc::Disabled);
1481    rc.SetDepthFunc(DepthFunc::Disabled);
1482
1483    glEnableClientState(GL_VERTEX_ARRAY);
1484    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
1485
1486    if (m_shader_copper)
1487    {
1488        // shader copper
1489        fbo_tmp->Bind();
1490        shader_copper->Bind();
1491        shader_copper->SetUniform(shader_copper_texture, fbo_back->GetTexture(), 0);
1492        shader_copper->SetUniform(shader_copper_screen_size, (vec2)screen_size);
1493        shader_copper->SetUniform(shader_copper_time, fx_angle);
1494        shader_copper->SetUniform(shader_copper_copper, vec4(copper_copper.x, copper_copper.y, copper_copper.z * 16.0f, copper_copper.w * 16.0f));
1495        shader_copper->SetUniform(shader_copper_mask_color, copper_mask_color);
1496        TraceQuad();
1497        shader_color->Unbind();
1498        fbo_tmp->Unbind();
1499        // shader simple
1500        fbo_back->Bind();
1501        ShaderSimple(fbo_tmp, 0);
1502        fbo_back->Unbind();
1503    }
1504
1505    if (m_shader_remanence)
1506    {
1507        // shader remanence
1508        fbo_tmp->Bind();
1509        shader_remanence->Bind();
1510        shader_remanence->SetUniform(shader_remanence_source, fbo_back->GetTexture(), 0);
1511        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1512        shader_remanence->SetUniform(shader_remanence_mix, remanence);
1513        TraceQuad();
1514        shader_remanence->Unbind();
1515        fbo_tmp->Unbind();
1516        // shader simple
1517        fbo_back->Bind();
1518        ShaderSimple(fbo_tmp, 0);
1519        fbo_back->Unbind();
1520        // save previous fbo
1521        fbo_tmp->Bind();
1522        shader_remanence->Bind();
1523        shader_remanence->SetUniform(shader_remanence_source, fbo_screen->GetTexture(), 0);
1524        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1525        shader_remanence->SetUniform(shader_remanence_mix, buffer);
1526        TraceQuad();
1527        shader_remanence->Unbind();
1528        fbo_tmp->Unbind();
1529        // shader simple
1530        fbo_buffer->Bind();
1531        ShaderSimple(fbo_tmp, 0);
1532        fbo_buffer->Unbind();
1533    }
1534
1535    // shader glow
1536    if (m_shader_glow)
1537    {
1538        // shader blur horizontal
1539        fbo_blur_h->Bind();
1540        shader_blur_h->Bind();
1541        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_back->GetTexture(), 0);
1542        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / (float)screen_size.x);
1543        TraceQuad();
1544        shader_blur_h->Unbind();
1545        fbo_blur_h->Unbind();
1546        // shader blur vertical
1547        fbo_blur_v->Bind();
1548        shader_blur_v->Bind();
1549        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1550        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / (float)screen_size.y);
1551        TraceQuad();
1552        shader_blur_v->Unbind();
1553        fbo_blur_v->Unbind();
1554        // shader blur horizontal
1555        fbo_blur_h->Bind();
1556        shader_blur_h->Bind();
1557        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
1558        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / (float)screen_size.x);
1559        TraceQuad();
1560        shader_blur_h->Unbind();
1561        fbo_blur_h->Unbind();
1562        // shader blur vertical
1563        fbo_blur_v->Bind();
1564        shader_blur_v->Bind();
1565        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1566        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / (float)screen_size.y);
1567        TraceQuad();
1568        shader_blur_v->Unbind();
1569        fbo_blur_v->Unbind();
1570        // shader glow
1571        fbo_screen->Bind();
1572        shader_glow->Bind();
1573        shader_glow->SetUniform(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
1574        shader_glow->SetUniform(shader_glow_source, fbo_back->GetTexture(), 1);
1575        shader_glow->SetUniform(shader_glow_mix, glow_mix);
1576        TraceQuad();
1577        shader_glow->Unbind();
1578        fbo_screen->Unbind();
1579    }
1580    else
1581    {
1582        // shader simple
1583        fbo_screen->Bind();
1584        ShaderSimple(fbo_back, 0);
1585        fbo_screen->Unbind();
1586    }
1587
1588    if (m_shader_color)
1589    {
1590        // shader color
1591        fbo_tmp->Bind();
1592        shader_color->Bind();
1593        shader_color->SetUniform(shader_color_texture, fbo_screen->GetTexture(), 0);
1594        shader_color->SetUniform(shader_color_screen_size, (vec2)screen_size);
1595        shader_color->SetUniform(shader_color_filter, color_filter);
1596        shader_color->SetUniform(shader_color_color, color_color);
1597        shader_color->SetUniform(shader_color_flash, flash_value);
1598        TraceQuad();
1599        shader_color->Unbind();
1600        fbo_tmp->Unbind();
1601        // shader simple
1602        fbo_screen->Bind();
1603        ShaderSimple(fbo_tmp, 0);
1604        fbo_screen->Unbind();
1605    }
1606
1607    if (m_shader_noise)
1608    {
1609        // shader noise
1610        fbo_tmp->Bind();
1611        shader_noise->Bind();
1612        shader_noise->SetUniform(shader_noise_texture, fbo_screen->GetTexture(), 0);
1613        shader_noise->SetUniform(shader_noise_screen_size, (vec2)screen_size);
1614        shader_noise->SetUniform(shader_noise_time, fx_angle);
1615        shader_noise->SetUniform(shader_noise_offset, noise_offset);
1616        shader_noise->SetUniform(shader_noise_noise, noise_noise);
1617        shader_noise->SetUniform(shader_noise_retrace, noise_retrace);
1618        TraceQuad();
1619        shader_noise->Unbind();
1620        fbo_tmp->Unbind();
1621        // shader simple
1622        fbo_screen->Bind();
1623        ShaderSimple(fbo_tmp, 0);
1624        fbo_screen->Unbind();
1625    }
1626
1627    if (m_shader_blur)
1628    {
1629        // shader blur horizontal
1630        fbo_tmp->Bind();
1631        shader_blur_h->Bind();
1632        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_screen->GetTexture(), 0);
1633        shader_blur_h->SetUniform(shader_blur_h_radius, blur / (float)screen_size.x);
1634        TraceQuad();
1635        shader_blur_h->Unbind();
1636        fbo_tmp->Unbind();
1637        // shader blur vertical
1638        fbo_screen->Bind();
1639        shader_blur_v->Bind();
1640        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_tmp->GetTexture(), 0);
1641        shader_blur_v->SetUniform(shader_blur_v_radius, blur / (float)screen_size.y);
1642        TraceQuad();
1643        shader_blur_v->Unbind();
1644        fbo_screen->Unbind();
1645    }
1646
1647    if (m_shader_postfx)
1648    {
1649        // shader postfx
1650        fbo_front->Bind();
1651        shader_postfx->Bind();
1652        shader_postfx->SetUniform(shader_postfx_texture, fbo_screen->GetTexture(), 0);
1653        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
1654        shader_postfx->SetUniform(shader_postfx_ratio_2d, (vec2)ratio_2d * 0.5f);
1655        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
1656        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
1657        shader_postfx->SetUniform(shader_postfx_ghost1, vec4(postfx_ghost1.xyz * 0.01f, postfx_ghost1.w));
1658        shader_postfx->SetUniform(shader_postfx_ghost2, vec4(postfx_ghost2.xyz * 0.01f, postfx_ghost2.w));
1659        shader_postfx->SetUniform(shader_postfx_glass, vec4(postfx_glass.xy * 0.01f, postfx_glass.z * 0.1f, postfx_glass.w));
1660        shader_postfx->SetUniform(shader_postfx_gradient, postfx_gradient);
1661        shader_postfx->SetUniform(shader_postfx_gradient_color, postfx_gradient_color);
1662        shader_postfx->SetUniform(shader_postfx_vignetting, postfx_vignetting);
1663        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
1664        shader_postfx->SetUniform(shader_postfx_moire_h, vec4(postfx_moire_h.xyz, postfx_moire_h.w * (2 * F_PI)));
1665        shader_postfx->SetUniform(shader_postfx_moire_v, vec4(postfx_moire_v.xyz, postfx_moire_v.w * (2 * F_PI)));
1666        shader_postfx->SetUniform(shader_postfx_scanline_h, vec4(postfx_scanline_h.xyz, postfx_scanline_h.w * (2 * F_PI)));
1667        shader_postfx->SetUniform(shader_postfx_scanline_v, vec4(postfx_scanline_v.xyz, postfx_scanline_v.w * (2 * F_PI)));
1668        shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
1669        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(sync_value * cosf((main_angle - sync_angle) * 6.0f)));
1670        shader_postfx->SetUniform(shader_postfx_beat, (float)fabs(beat_value * cosf((main_angle - beat_angle) * 6.0f)));
1671        TraceQuad();
1672        shader_postfx->Unbind();
1673        fbo_front->Unbind();
1674    }
1675    else
1676    {
1677        // shader simple
1678        fbo_front->Bind();
1679        ShaderSimple(fbo_screen, 0);
1680        fbo_front->Unbind();
1681    }
1682
1683    if (m_shader_mirror)
1684    {
1685        // shader mirror
1686        fbo_tmp->Bind();
1687        shader_mirror->Bind();
1688        shader_mirror->SetUniform(shader_mirror_texture, fbo_front->GetTexture(), 0);
1689        shader_mirror->SetUniform(shader_mirror_screen_size, (vec2)screen_size);
1690        shader_mirror->SetUniform(shader_mirror_mirror, vec4(mirror.x * 0.1f, mirror.y * 0.1f, mirror.z, mirror.w));
1691        TraceQuad();
1692        shader_mirror->Unbind();
1693        fbo_tmp->Unbind();
1694        // shader simple
1695        fbo_front->Bind();
1696        ShaderSimple(fbo_tmp, 0);
1697        fbo_front->Unbind();
1698    }
1699
1700    if (m_shader_radial)
1701    {
1702        // shader radial blur
1703        fbo_tmp->Bind();
1704        shader_radial->Bind();
1705        shader_radial->SetUniform(shader_radial_texture, fbo_front->GetTexture(), 0);
1706        shader_radial->SetUniform(shader_radial_screen_size, (vec2)screen_size);
1707        shader_radial->SetUniform(shader_radial_radial, vec4(radial.x, radial.y, radial.z, radial.w * 0.1f));
1708        TraceQuad();
1709        shader_radial->Unbind();
1710        fbo_tmp->Unbind();
1711        // shader simple
1712        fbo_front->Bind();
1713        ShaderSimple(fbo_tmp, 0);
1714        fbo_front->Unbind();
1715    }
1716
1717    // shader simple
1718    ShaderSimple(fbo_front, 0);
1719
1720    glDisableClientState(GL_VERTEX_ARRAY);
1721}
1722
1723Render::~Render()
1724{
1725    if (m_fps_debug)
1726        Ticker::Unref(m_fps_debug);
1727}
Note: See TracBrowser for help on using the repository browser.