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

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

neercs: added theme support + 2 new themes [F4/F5 to switch]

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