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

Last change on this file since 2047 was 2047, checked in by rez, 8 years ago

neercs: fixed theme_var[] values

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