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

Last change on this file since 2045 was 2045, checked in by rez, 10 years ago

neercs: theme support again (not really working yet)

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