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

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

neercs: fixed scanline, added a new theme

File size: 56.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;               // [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 = 5;     // 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        "buffer new frame",
161        "buffer old frame",
162        "source mix",
163        "buffer mix",
164        "",
165        "",
166        "",
167        "",
168    "glow",
169        "source mix",
170        "glow mix",
171        "large center",
172        "large corner",
173        "small center",
174        "small corner",
175        "",
176        "",
177    "blur",
178        "blur center",
179        "blur corner",
180        "",
181        "",
182        "",
183        "",
184        "",
185        "",
186    "screen",
187        "deform ratio",
188        "zoom base",
189        "corner width",
190        "corner radius",
191        "corner blur",
192        "vignetting",
193        "",
194        "",
195    "copper",
196        "base",
197        "variable",
198        "repeat",
199        "color cycle",
200        "color r",
201        "color g",
202        "color b",
203        "",
204    "color",
205        "filter red",
206        "filter green",
207        "filter blue",
208        "brightness",
209        "contrast",
210        "level",
211        "grayscale",
212        "aberration",
213    "noise",
214        "offset h",
215        "offset v",
216        "noise",
217        "retrace strength",
218        "retrace length",
219        "retrace speed",
220        "",
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        "distance",
278        "fade ratio",
279        "iteration",
280        "strength",
281        "",
282        "",
283        "",
284        "",
285    ""
286    };
287
288vec4 setup_conf[]={ // setup variable [start,end,step,value]
289vec4(0), /* main */
290    vec4(1,  8, 1, 0), // ratio_2d.x
291    vec4(1,  8, 1, 0), // ratio_2d.y
292    vec4(0, 16, 1, 0), // border.x
293    vec4(0, 16, 1, 0), // border.y
294    vec4(0),
295    vec4(0),
296    vec4(0),
297    vec4(0),
298vec4(0), /* remanence */
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),
306    vec4(0),
307vec4(0), /* glow */
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),
315    vec4(0),
316vec4(0), /* blur */
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),
324    vec4(0),
325vec4(0), /* screen */
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),
333    vec4(0),
334vec4(0), /* copper */
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
342    vec4(0),
343vec4(0), /* color */
344    vec4( 0.0f, 1.0f, 0.05f, 0), // color_filter.x
345    vec4( 0.0f, 1.0f, 0.05f, 0), // color_filter.y
346    vec4( 0.0f, 1.0f, 0.05f, 0), // color_filter.z
347    vec4( 0.0f, 2.0f, 0.05f, 0), // color_color.x
348    vec4( 0.0f, 2.0f, 0.05f, 0), // color_color.y
349    vec4(-1.0f, 1.0f, 0.05f, 0), // color_color.z
350    vec4( 0.0f, 1.0f, 0.05f, 0), // color_color.w
351    vec4( 0.0f, 8.0f, 0.50f, 0), // postfx_aberration
352vec4(0), /* noise */
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),
360    vec4(0),
361vec4(0), /* ghost */
362    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost1.x
363    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost1.y
364    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost1.z
365    vec4(-1.0f, 1.0f, 0.05f, 0), // postfx_ghost1.w
366    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost2.x
367    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost2.y
368    vec4(-2.0f, 2.0f, 0.10f, 0), // postfx_ghost2.z
369    vec4(-1.0f, 1.0f, 0.05f, 0), // postfx_ghost2.w
370vec4(0), /* gradient */
371    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient.x
372    vec4( 0.0f, 0.5f, 0.05f, 0), // postfx_gradient.y
373    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_gradient.z
374    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient_color.x
375    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient_color.y
376    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_gradient_color.z
377    vec4(0),
378    vec4(0),
379vec4(0), /* glass */
380    vec4(0.0f, 16.0f, 0.50f, 0), // postfx_glass.x
381    vec4(0.0f,  1.0f, 0.05f, 0), // postfx_glass.y
382    vec4(0.0f,  2.0f, 0.05f, 0), // postfx_glass.z
383    vec4(0.0f,  1.0f, 0.05f, 0), // postfx_glass.w
384    vec4(0),
385    vec4(0),
386    vec4(0),
387    vec4(0),
388vec4(0), /* moire */
389    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_moire_h.x
390    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_moire_h.y
391    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_h.z
392    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_h.w
393    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_moire_v.x
394    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_moire_v.y
395    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_v.z
396    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_moire_v.w
397vec4(0), /* scanline */
398    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_scanline_h.x
399    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_scanline_h.y
400    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_h.z
401    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_h.w
402    vec4( 0.5f, 1.0f, 0.05f, 0), // postfx_scanline_v.x
403    vec4(-0.5f, 0.5f, 0.05f, 0), // postfx_scanline_v.y
404    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_v.z
405    vec4( 0.0f, 1.0f, 0.05f, 0), // postfx_scanline_v.w
406vec4(0), /* mirror */
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),
414    vec4(0),
415vec4(0), /* radial blur */
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),
423    vec4(0),
424vec4(0) /* ? */
425};
426
427float theme_var[]={
428/* default */
4290,
430    1,1,                      // ratio_2d
431    0,0,                      // border
432    0,0,0,0,
4330,
434    1.0f,0.8f,                // buffer
435    0.0f,0.0f,                // remanence
436    0,0,0,0,
4370,
438    0.5f,0.0f,                // glow_mix
439    0.0f,0.0f,                // glow_large
440    0.0f,0.0f,                // glow_small
441    0,0,
4420,
443    0.0f,0.0f,                // blur
444    0,0,0,0,0,0,
4450,
446    0.0f,0.5f,                // postfx_deform
447    0.0f,1.0f,1.0f,           // postfx_corner
448    0.0f,                     // postfx_vignetting
449    0,0,
4500,
451    0.75f,0.25f,0.42f,4.0f,   // copper_copper
452    4.0f,4.0f,4.0f,           // copper_mask_color
453    0,
4540,
455    1.0f,1.0f,1.0f,           // color_filter
456    1.0f,1.0f,0.0f,0.0f,      // color_color
457    0.0f,                     // postfx_aberration
4580,
459    0.0f,0.0f,                // noise_offset
460    0.0f,                     // noise_noise
461    0.0f,0.0f,0.0f,           // noise_retrace
462    0,0,
4630,
464    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost1
465    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost2
4660,
467    0.5f,0.0f,0.0f,           // postfx_gradient
468    0.0f,0.0f,0.0f,           // postfx_gradient_color
469    0,0,
4700,
471    8.0f,0.0f,0.0f,0.0f,      // postfx_glass
472    0,0,0,0,
4730,
474    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
475    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_v
4760,
477    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_h
478    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_v
4790,
480    0.0f,0.0f,0.0f,1.0f,      // mirror
481    0,0,0,0,
4820,
483    4.0f,0.9f,1,0.0f,         // radial
484    0,0,0,0,
485/* crt */
4860,
487    2,3,                      // ratio_2d
488    2,1,                      // border
489    0,0,0,0,
4900,
491    0.2f,0.8f,                // buffer
492    0.6f,0.4f,                // remanence
493    0,0,0,0,
4940,
495    0.7f,0.3f,                // glow_mix
496    3.0f,0.0f,                // glow_large
497    1.5f,0.0f,                // glow_small
498    0,0,
4990,
500    0.5f,0.0f,                // blur
501    0,0,0,0,0,0,
5020,
503    0.8f,0.48f,               // postfx_deform
504    0.0f,0.8f,0.96f,          // postfx_corner
505    0.5f,                     // postfx_vignetting
506    0,0,
5070,
508    0.75f,0.25f,0.42f,4.0f,   // copper_copper
509    4.0f,4.0f,4.0f,           // copper_mask_color
510    0,
5110,
512    0.9f,0.95f,0.85f,         // color_filter
513    1.0f,1.25f,0.1f,0.4f,     // color_color
514    4.0f,                     // postfx_aberration
5150,
516    1.0f,1.0f,                // noise_offset
517    0.15f,                    // noise_noise
518    1.0f,1.0f,0.5f,           // noise_retrace
519    0,0,
5200,
521    1.0f,0.0f,0.0f,-0.25f,    // postfx_ghost1
522    1.5f,0.0f,0.0f,0.25f,     // postfx_ghost2
5230,
524    0.5f,0.25f,0.05f,         // postfx_gradient
525    0.9f,0.8f,0.5f,           // postfx_gradient_color
526    0,0,
5270,
528    8.0f,0.25f,0.75f,0.2f,    // postfx_glass
529    0,0,0,0,
5300,
531    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
532    0.75f,-0.25f,0.25f,0.25f, // postfx_moire_v
5330,
534    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_h
535    0.75f,-0.25f,0.5f,0.0f,   // postfx_scanline_v
5360,
537    0.95f,0.9f,0.5f,4.0f,     // mirror
538    0,0,0,0,
5390,
540    4.0f,0.9f,16,0.25f,       // radial
541    0,0,0,0,
542/* amber screen */
5430,
544    2,4,                      // ratio_2d
545    1,0,                      // border
546    0,0,0,0,
5470,
548    0.2f,0.8f,                // buffer
549    0.6f,0.4f,                // remanence
550    0,0,0,0,
5510,
552    0.4f,0.6f,                // glow_mix
553    4.0f,0.0f,                // glow_large
554    2.0f,0.0f,                // glow_small
555    0,0,
5560,
557    0.5f,0.0f,                // blur
558    0,0,0,0,0,0,
5590,
560    0.7f,0.5f,                // postfx_deform
561    0.0f,0.85f,0.98f,         // postfx_corner
562    0.5f,                     // postfx_vignetting
563    0,0,
5640,
565    0.75f,0.25f,0.42f,4.0f,   // copper_copper
566    4.0f,4.0f,4.0f,           // copper_mask_color
567    0,
5680,
569    1.0f,0.7f,0.0f,           // color_filter
570    1.0f,1.25f,0.1f,1.0f,     // color_color
571    1.5f,                     // postfx_aberration
5720,
573    1.0f,0.0f,                // noise_offset
574    0.25f,                    // noise_noise
575    1.0f,2.0f,2.0f,           // noise_retrace
576    0,0,
5770,
578    1.0f,0.0f,0.0f,-0.25f,    // postfx_ghost1
579    1.5f,0.0f,0.0f,0.25f,     // postfx_ghost2
5800,
581    0.0f,0.25f,0.1f,          // postfx_gradient
582    0.25f,0.5f,0.5f,          // postfx_gradient_color
583    0,0,
5840,
585    8.0f,0.0f,0.0f,0.0f,      // postfx_glass
586    0,0,0,0,
5870,
588    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
589    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_v
5900,
591    0.6f,0.4f,1.0f,0.0f,      // postfx_scanline_h
592    0.9f,0.1f,0.75f,0.0f,     // postfx_scanline_v
5930,
594    0.6f,0.6f,0.5f,4.0f,      // mirror
595    0,0,0,0,
5960,
597    4.0f,0.84f,16,0.25f,      // radial
598    0,0,0,0,
599/* lcd */
6000,
601    2,2,                      // ratio_2d
602    1,1,                      // border
603    0,0,0,0,
6040,
605    0.7f,0.3f,                // buffer
606    0.5f,0.5f,                // remanence
607    0,0,0,0,
6080,
609    0.5f,0.5f,                // glow_mix
610    2.4f,0.0f,                // glow_large
611    1.2f,0.0f,                // glow_small
612    0,0,
6130,
614    0.25f,0.0f,               // blur
615    0,0,0,0,0,0,
6160,
617    0.0f,0.5f,                // postfx_deform
618    0.0f,1.0f,1.0f,           // postfx_corner
619    0.0f,                     // postfx_vignetting
620    0,0,
6210,
622    0.75f,0.25f,0.42f,4.0f,   // copper_copper
623    4.0f,4.0f,4.0f,           // copper_mask_color
624    0,
6250,
626    1.0f,1.0f,0.9f,           // color_filter
627    1.15f,1.25f,-0.1f,0.25f,  // color_color
628    3.0f,                     // postfx_aberration
6290,
630    0.0f,0.0f,                // noise_offset
631    0.15f,                    // noise_noise
632    0.0f,0.0f,0.0f,           // noise_retrace
633    0,0,
6340,
635    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost1
636    0.0f,0.0f,0.0f,0.0f,      // postfx_ghost2
6370,
638    0.25f,0.5f,0.1f ,         // postfx_gradient
639    0.7f,0.9f,1.0f,           // postfx_gradient_color
640    0,0,
6410,
642    8.0f,0.0f,0.0f,0.0f,      // postfx_glass
643    0,0,0,0,
6440,
645    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
646    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_v
6470,
648    0.75f,0.25f,0.7f,0.0f,    // postfx_scanline_h
649    0.75f,0.25f,0.7f,0.0f,    // postfx_scanline_v
6500,
651    0.0f,0.0f,0.0f,1.0f,      // mirror
652    0,0,0,0,
6530,
654    4.0f,0.9f,1,0.0f,         // radial
655    0,0,0,0,
656/* granpa tv */
6570,
658    2,2,                      // ratio_2d
659    2,2,                      // border
660    0,0,0,0,
6610,
662    0.2f,0.8f,                // buffer
663    0.6f,0.4f,                // remanence
664    0,0,0,0,
6650,
666    0.7f,0.3f,                // glow_mix
667    3.0f,0.0f,                // glow_large
668    1.5f,0.0f,                // glow_small
669    0,0,
6700,
671    0.5f,0.5f,                // blur
672    0,0,0,0,0,0,
6730,
674    1.0f,0.5f,                // postfx_deform
675    0.1f,0.7f,0.84f,          // postfx_corner
676    0.5f,                     // postfx_vignetting
677    0,0,
6780,
679    0.75f,0.25f,0.42f,4.0f,   // copper_copper
680    4.0f,4.0f,4.0f,           // copper_mask_color
681    0,
6820,
683    0.8f,0.85f,0.75f,         // color_filter
684    1.0f,1.1f,1.0f,0.0f,      // color_color
685    4.0f,                     // postfx_aberration
6860,
687    1.0f,1.0f,                // noise_offset
688    0.15f,                    // noise_noise
689    1.0f,1.0f,0.5f,           // noise_retrace
690    0,0,
6910,
692    1.0f,0.0f,0.0f,-0.25f,    // postfx_ghost1
693    1.5f,0.0f,0.0f,0.25f,     // postfx_ghost2
6940,
695    0.5f,0.25f,0.05f,         // postfx_gradient
696    0.9f,0.8f,0.5f,           // postfx_gradient_color
697    0,0,
6980,
699    8.0f,0.25f,0.75f,0.2f,    // postfx_glass
700    0,0,0,0,
7010,
702    1.0f,0.0f,0.0f,0.0f,      // postfx_moire_h
703    0.75f,-0.25f,0.25f,0.25f, // postfx_moire_v
7040,
705    1.0f,0.0f,0.0f,0.0f,      // postfx_scanline_h
706    0.75f,-0.25f,0.5f,0.0f,   // postfx_scanline_v
7070,
708    0.95f,0.9f,0.5f,4.0f,     // mirror
709    0,0,0,0,
7100,
711    4.0f,0.9f,16,0.25f,       // radial
712    0,0,0,0,
713/* intex system 4000 */
7140};
715
716void Render::InitShaderVar()
717{
718    int k = theme_i * setup_option_n * 9 + 1; /* main */
719    ratio_2d = vec2(theme_var[k], theme_var[k + 1]); k += 2;
720    border = vec2(theme_var[k], theme_var[k + 1]); k += 2;
721    k += 5; /* remanence */
722    buffer = vec2(theme_var[k], theme_var[k + 1]); k += 2;
723    remanence = vec2(theme_var[k], theme_var[k + 1]); k += 2;
724    k += 5; /* glow */
725    glow_mix = vec2(theme_var[k], theme_var[k + 1]); k += 2;
726    glow_large = vec2(theme_var[k], theme_var[k + 1]); k += 2;
727    glow_small = vec2(theme_var[k], theme_var[k + 1]); k += 2;
728    k += 3; /* blur */
729    blur = vec2(theme_var[k], theme_var[k + 1]); k += 2;
730    k += 7; /* screen */
731    postfx_deform = vec2(theme_var[k], theme_var[k + 1]); k += 2;
732    postfx_corner = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
733    postfx_vignetting = theme_var[k]; k++;
734    k += 3; /* copper */
735    copper_copper = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
736    copper_mask_color = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
737    k += 2; /* color */
738    color_filter = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
739    color_color = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
740    postfx_aberration = theme_var[k]; k++;
741    k += 1; /* noise */
742    noise_offset = vec2(theme_var[k], theme_var[k + 1]); k += 2;
743    noise_noise = theme_var[k]; k++;
744    noise_retrace = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
745    k += 3; /* ghost */
746    postfx_ghost1 = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
747    postfx_ghost2 = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
748    k += 1; /* gradient */
749    postfx_gradient = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
750    postfx_gradient_color = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
751    k += 3; /* glass */
752    postfx_glass = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
753    k += 5; /* moire */
754    postfx_moire_h = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
755    postfx_moire_v = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
756    k += 1; /* scanline */
757    postfx_scanline_h = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
758    postfx_scanline_v = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
759    k += 1; /* mirror */
760    mirror = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
761    k += 5; /* radial blur */
762    radial = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
763}
764
765void Render::UpdateSize()
766{
767    screen_size = Video::GetSize();
768    canvas_char = (screen_size - border * ratio_2d * font_size * 2) / (font_size * ratio_2d);
769    canvas_char = max(canvas_char, ivec2(1, 1));
770    canvas_size = canvas_char * font_size * ratio_2d;
771
772    border = (screen_size - canvas_size) / 2;
773
774    caca_set_canvas_size(m_cv_screen, canvas_char.x, canvas_char.y);
775    caca_set_canvas_size(m_cv_setup, setup_size.x + 1, setup_size.y + 1);
776}
777
778int calc_item_length()
779{
780    int n = !setup_switch ? setup_option_n : setup_item_n;
781    for (int i = 0; i < n; i++)
782    {
783        int k = !setup_switch ? (i * (setup_item_n + 1)) : (setup_option_i * (setup_item_n + 1) + 1 + i);
784        if (setup_text[k][0] == '\0') return i - 1;
785    }
786    return n - 1;
787}
788
789Shader *shader_simple;
790Shader *shader_blur_h, *shader_blur_v, *shader_glow;
791Shader *shader_remanence, *shader_copper, *shader_color;
792Shader *shader_noise, *shader_postfx, *shader_mirror, *shader_radial;
793// shader variables
794ShaderUniform shader_simple_texture;
795ShaderUniform shader_blur_h_texture,
796              shader_blur_h_radius,
797              shader_blur_v_texture,
798              shader_blur_v_radius;
799ShaderUniform shader_glow_glow,
800              shader_glow_source,
801              shader_glow_mix;
802ShaderUniform shader_remanence_source,
803              shader_remanence_buffer,
804              shader_remanence_mix;
805ShaderUniform shader_copper_texture,
806              shader_copper_screen_size,
807              shader_copper_time,
808              shader_copper_copper,
809              shader_copper_mask_color;
810ShaderUniform shader_color_texture,
811              shader_color_screen_size,
812              shader_color_filter,
813              shader_color_color,
814              shader_color_flash;
815ShaderUniform shader_noise_texture,
816              shader_noise_screen_size,
817              shader_noise_time,
818              shader_noise_offset,
819              shader_noise_noise,
820              shader_noise_retrace;
821ShaderUniform shader_postfx_texture,
822              shader_postfx_texture_2d,
823              shader_postfx_screen_size,
824              shader_postfx_ratio_2d,
825              shader_postfx_time,
826              shader_postfx_deform,
827              shader_postfx_ghost1,
828              shader_postfx_ghost2,
829              shader_postfx_glass,
830              shader_postfx_vignetting,
831              shader_postfx_gradient,
832              shader_postfx_gradient_color,
833              shader_postfx_aberration,
834              shader_postfx_moire_h,
835              shader_postfx_moire_v,
836              shader_postfx_scanline_h,
837              shader_postfx_scanline_v,
838              shader_postfx_corner,
839              shader_postfx_sync,
840              shader_postfx_beat;
841ShaderUniform shader_mirror_texture,
842              shader_mirror_screen_size,
843              shader_mirror_mirror;
844ShaderUniform shader_radial_texture,
845              shader_radial_screen_size,
846              shader_radial_radial;
847
848FrameBuffer *fbo_back, *fbo_front, *fbo_screen;
849FrameBuffer *fbo_blur_h, *fbo_blur_v;
850FrameBuffer *fbo_tmp, *fbo_buffer;
851
852void Render::TraceQuad()
853{
854    glLoadIdentity();
855    glDrawArrays(GL_QUADS, 0, 4);
856}
857
858void Render::ShaderSimple(FrameBuffer *fbo_output, int n)
859{
860    shader_simple->Bind();
861    shader_simple->SetUniform(shader_simple_texture, fbo_output->GetTexture(), n);
862    TraceQuad();
863    shader_simple->Unbind();
864}
865
866int Render::InitDraw(void)
867{
868    glDepthMask(GL_TRUE);     // do not write z-buffer
869    glEnable(GL_CULL_FACE);   // disable cull face
870    glCullFace(GL_BACK);      // don't draw front face
871    /* initialise framebuffer objects */
872    fbo_back = new FrameBuffer(screen_size);
873    fbo_screen = new FrameBuffer(screen_size);
874    fbo_front = new FrameBuffer(screen_size);
875    fbo_buffer = new FrameBuffer(screen_size);
876    fbo_blur_h = new FrameBuffer(screen_size);
877    fbo_blur_v = new FrameBuffer(screen_size);
878    fbo_tmp = new FrameBuffer(screen_size);
879    // shader simple
880    shader_simple = Shader::Create(lolfx_simple);
881    shader_simple_texture = shader_simple->GetUniformLocation("texture");
882    // shader glow
883    shader_glow = Shader::Create(lolfx_glow);
884    shader_glow_glow = shader_glow->GetUniformLocation("glow");
885    shader_glow_source = shader_glow->GetUniformLocation("source");
886    shader_glow_mix = shader_glow->GetUniformLocation("mix");
887    // shader blur horizontal
888    shader_blur_h = Shader::Create(lolfx_blurh);
889    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
890    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
891    // shader blur vertical
892    shader_blur_v = Shader::Create(lolfx_blurv);
893    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
894    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
895    // shader remanence
896    shader_remanence = Shader::Create(lolfx_remanence);
897    shader_remanence_source = shader_remanence->GetUniformLocation("source");
898    shader_remanence_buffer = shader_remanence->GetUniformLocation("buffer");
899    shader_remanence_mix = shader_remanence->GetUniformLocation("mix");
900    // shader copper
901    shader_copper = Shader::Create(lolfx_copper);
902    shader_copper_texture = shader_copper->GetUniformLocation("texture");
903    shader_copper_screen_size = shader_copper->GetUniformLocation("screen_size");
904    shader_copper_time = shader_copper->GetUniformLocation("time");
905    shader_copper_copper = shader_copper->GetUniformLocation("copper");
906    shader_copper_mask_color = shader_copper->GetUniformLocation("mask_color");
907    // shader color
908    shader_color = Shader::Create(lolfx_color);
909    shader_color_texture = shader_color->GetUniformLocation("texture");
910    shader_color_screen_size = shader_color->GetUniformLocation("screen_size");
911    shader_color_filter = shader_color->GetUniformLocation("filter");
912    shader_color_color = shader_color->GetUniformLocation("color");
913    shader_color_flash = shader_color->GetUniformLocation("flash");
914    // shader noise
915    shader_noise = Shader::Create(lolfx_noise);
916    shader_noise_texture = shader_noise->GetUniformLocation("texture");
917    shader_noise_screen_size = shader_noise->GetUniformLocation("screen_size");
918    shader_noise_time = shader_noise->GetUniformLocation("time");
919    shader_noise_offset = shader_noise->GetUniformLocation("offset");
920    shader_noise_noise = shader_noise->GetUniformLocation("noise");
921    shader_noise_retrace = shader_noise->GetUniformLocation("retrace");
922    // shader postfx
923    shader_postfx = Shader::Create(lolfx_postfx);
924    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
925    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
926    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
927    shader_postfx_ratio_2d = shader_postfx->GetUniformLocation("ratio_2d");
928    shader_postfx_time = shader_postfx->GetUniformLocation("time");
929    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
930    shader_postfx_ghost1 = shader_postfx->GetUniformLocation("ghost1");
931    shader_postfx_ghost2 = shader_postfx->GetUniformLocation("ghost2");
932    shader_postfx_glass = shader_postfx->GetUniformLocation("glass");
933    shader_postfx_gradient = shader_postfx->GetUniformLocation("gradient");
934    shader_postfx_gradient_color = shader_postfx->GetUniformLocation("gradient_color");
935    shader_postfx_vignetting = shader_postfx->GetUniformLocation("vignetting");
936    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
937    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
938    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
939    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
940    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
941    shader_postfx_corner = shader_postfx->GetUniformLocation("corner");
942    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
943    shader_postfx_beat = shader_postfx->GetUniformLocation("beat");
944    // shader mirror
945    shader_mirror = Shader::Create(lolfx_mirror);
946    shader_mirror_texture = shader_mirror->GetUniformLocation("texture");
947    shader_mirror_screen_size = shader_mirror->GetUniformLocation("screen_size");
948    shader_mirror_mirror = shader_mirror->GetUniformLocation("mirror");
949    // shader radial blur
950    shader_radial = Shader::Create(lolfx_radial);
951    shader_radial_texture = shader_radial->GetUniformLocation("texture");
952    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
953    shader_radial_radial = shader_radial->GetUniformLocation("radial");
954    // initialize setup
955    setup_n = calc_item_length();
956    return true;
957}
958
959int Render::CreateGLWindow()
960{
961    InitShaderVar();
962    UpdateSize();
963    InitDraw();
964    return true;
965}
966
967Render::Render(caca_canvas_t *caca)
968  : m_cv_screen(caca),
969    m_cv_setup(caca_create_canvas(1, 1)),
970    m_fps_debug(0),
971    m_ready(false),
972    m_pause(false),
973    m_shader(true),
974    m_shader_remanence(true),
975    m_shader_glow(true),
976    m_shader_blur(true),
977    m_shader_postfx(true),
978    m_shader_copper(true),
979    m_shader_color(true),
980    m_shader_noise(true),
981    m_shader_mirror(true),
982    m_shader_radial(true)
983{
984    m_txt_screen = new TextRender(m_cv_screen, font_size);
985    m_txt_setup = new TextRender(m_cv_setup, font_size);
986}
987
988void Render::TickGame(float seconds)
989{
990    Entity::TickGame(seconds);
991    /* draw setup */
992    if (g_setup)
993    {
994        /* background */
995        caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
996        caca_fill_box(m_cv_setup, 0, 0, setup_size.x + 1, setup_size.y,' ');
997        caca_draw_line(m_cv_setup, setup_size.z - 1, 1, setup_size.z - 1, setup_size.y - 1,'|');
998        /* title */
999        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
1000        caca_draw_line(m_cv_setup, 0, 0, setup_size.x, 0, ' ');
1001        caca_put_str(m_cv_setup, setup_size.x / 2 - 3, 0, "SETUP");
1002        /* informations */
1003        /*
1004        int w = caca_get_canvas_width(m_cv_screen);
1005        int h = caca_get_canvas_height(m_cv_screen);
1006        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
1007        caca_printf(m_cv_setup, 1, 0, "%i*%i", w, h);
1008        */
1009        /* display option */
1010        for (int i = 0; i < setup_h; i++)
1011        {
1012            int y = 1 + i;
1013            int k = (setup_option_p + i) * (setup_item_n + 1);
1014            if (setup_option_i != setup_option_p + i || setup_switch)
1015            {
1016                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
1017                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
1018            }
1019            else
1020            {
1021                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
1022                caca_draw_line(m_cv_setup, 0, y, setup_size.z - 2, y,' ');
1023                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
1024            }
1025        }
1026        /* display item */
1027        for (int i = 0; i < setup_h; i++)
1028        {
1029            int y = 1 + i;
1030            int k = setup_option_i * (setup_item_n + 1) + 1 + setup_item_p + i;
1031            if (setup_item_i != setup_item_p + i || !setup_switch)
1032            {
1033                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
1034                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
1035            }
1036            else
1037            {
1038                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
1039                caca_draw_line(m_cv_setup, setup_size.z, y, setup_size.x, y,' ');
1040                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
1041            }
1042        }
1043        /* display variable */
1044        int y = setup_size.y;
1045        setup_item_key = setup_option_i * (setup_item_n + 1) + 1 + setup_item_i;
1046        theme_var_key = theme_i * setup_option_n * 9 + setup_item_key;
1047        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
1048        caca_draw_line(m_cv_setup, 0, y, setup_size.x, y,' ');
1049        if (setup_switch)
1050        {
1051            int x = 1;
1052            int w = setup_size.x - 3 - 4;
1053            float bar_w = w / (setup_conf[setup_item_key].y - setup_conf[setup_item_key].x);
1054            int bar_x = bar_w * setup_conf[setup_item_key].x;
1055            if ((setup_conf[setup_item_key].y - setup_conf[setup_item_key].x) / setup_conf[setup_item_key].z > 1)
1056            {
1057                /* work around a bug in libcaca */
1058                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]);
1059                caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * setup_conf[setup_item_key].y), y,'.');
1060                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');
1061            }
1062            else
1063            {
1064                if (setup_conf[setup_item_key] != vec4(0))
1065                {
1066                    caca_put_str(m_cv_setup, setup_size.x - 3, y, (theme_var[theme_var_key] == setup_conf[setup_item_key].y)?"YES":" NO");
1067                }
1068            }
1069        }
1070        else
1071        {
1072            caca_printf(m_cv_setup, 1, y, "%d/%d", setup_option_i, setup_n);
1073        }
1074    }
1075
1076}
1077
1078void Render::Pause()
1079{
1080    m_pause=!m_pause;
1081}
1082
1083void Render::TickDraw(float seconds)
1084{
1085    /* keyboard manager */
1086    if (Input::WasPressed(Key::F1))
1087    {
1088        g_setup = !g_setup;
1089        if (g_setup) setup_n = calc_item_length();
1090        sync_flag = true;
1091        sync_angle = main_angle;
1092        if (m_fps_debug)
1093        {
1094            Ticker::Unref(m_fps_debug);
1095            m_fps_debug = NULL;
1096        }
1097        if (g_setup)
1098        {
1099            m_fps_debug = new DebugFps(2, 2);
1100            Ticker::Ref(m_fps_debug);
1101        }
1102    }
1103    if (Input::WasPressed(Key::F2))
1104    {
1105        m_shader_remanence = !m_shader_remanence;
1106        m_shader_glow = !m_shader_glow;
1107        m_shader_blur = !m_shader_blur;
1108        m_shader_postfx = !m_shader_postfx;
1109        //m_shader_copper = !m_shader_copper;
1110        m_shader_color = !m_shader_color;
1111        m_shader_noise = !m_shader_noise;
1112        m_shader_mirror = !m_shader_mirror;
1113        m_shader_radial = !m_shader_radial;
1114    }
1115    if (Input::WasPressed(Key::F4))
1116    {
1117        theme_i--;
1118        if(theme_i < 0) theme_i = theme_n - 1;
1119        InitShaderVar();
1120        UpdateSize();
1121    }
1122    if (Input::WasPressed(Key::F5))
1123    {
1124        theme_i++;
1125        if(theme_i > theme_n - 1) theme_i = 0;
1126        InitShaderVar();
1127        UpdateSize();
1128    }
1129    if (Input::WasPressed(Key::Tab))
1130    {
1131        if (g_setup)
1132        {
1133            setup_switch = !setup_switch;
1134            setup_n = calc_item_length();
1135            setup_cursor = (!setup_switch?setup_option_i:setup_item_i) - (!setup_switch?setup_option_p:setup_item_p);
1136        }
1137    }
1138    if (Input::WasPressed(Key::Up))
1139    {
1140        if (g_setup)
1141        {
1142            if (!setup_switch)
1143            {
1144                if (setup_cursor > 0)
1145                {
1146                    setup_cursor--;
1147                }
1148                else
1149                {
1150                    if (setup_cursor == 0) setup_option_p--;
1151                }
1152                if (setup_option_i > 0)
1153                {
1154                    setup_option_i--;
1155                }
1156                else
1157                {
1158                    setup_option_i = setup_option_n - 1;
1159                    setup_option_p = setup_option_n - setup_h;
1160                    setup_cursor = setup_h - 1;
1161                }
1162                setup_item_i = 0;
1163                setup_item_p = 0;
1164            }
1165            else
1166            {
1167                if (setup_cursor > 0)
1168                {
1169                    setup_cursor--;
1170                }
1171                else
1172                {
1173                    if (setup_cursor == 0) setup_item_p--;
1174                }
1175                if (setup_item_i > 0)
1176                {
1177                    setup_item_i--;
1178                }
1179                else
1180                {
1181                    setup_item_i = setup_n;
1182                    setup_item_p = (setup_n < setup_h) ? 0 : setup_n - setup_h + 1;
1183                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
1184                }
1185            }
1186        }
1187    }
1188    if (Input::WasPressed(Key::Down))
1189    {
1190        if (g_setup)
1191        {
1192            if (!setup_switch)
1193            {
1194                if (setup_cursor < setup_h - 1)
1195                {
1196                    setup_cursor++;
1197                }
1198                else
1199                {
1200                    if (setup_cursor == setup_h - 1) setup_option_p++;
1201                }
1202                if (setup_option_i < setup_option_n - 1)
1203                {
1204                    setup_option_i++;
1205                }
1206                else
1207                {
1208                    setup_option_i = 0;
1209                    setup_option_p = 0;
1210                    setup_cursor = 0;
1211                }
1212                setup_item_i = 0;
1213                setup_item_p = 0;
1214            }
1215            else
1216            {
1217                if (setup_cursor < setup_h - 1)
1218                {
1219                    setup_cursor++;
1220                }
1221                else
1222                {
1223                    if (setup_cursor == setup_h - 1) setup_item_p++;
1224                }
1225                if (setup_item_i < setup_n)
1226                {
1227                    setup_item_i++;
1228                }
1229                else
1230                {
1231                    setup_item_i = 0;
1232                    setup_item_p = 0;
1233                    setup_cursor = 0;
1234                }
1235            }
1236        }
1237    }
1238    if (Input::WasPressed(Key::PageUp))
1239    {
1240        if (g_setup)
1241        {
1242            if (!setup_switch)
1243            {
1244                if (setup_cursor > 0)
1245                {
1246                    setup_option_i -= setup_cursor;
1247                    setup_cursor = 0;
1248                }
1249                else
1250                {
1251                    if (setup_option_i > setup_h)
1252                    {
1253                        setup_option_i -= setup_h;
1254                        setup_option_p -= setup_h;
1255                    }
1256                else
1257                    {
1258                        setup_option_i = 0;
1259                        setup_option_p = 0;
1260                    }
1261                }
1262            setup_item_i = 0;
1263            }
1264            else
1265            {
1266                if (setup_cursor > 0)
1267                {
1268                    setup_item_i -= setup_cursor;
1269                    setup_cursor = 0;
1270                }
1271                else
1272                {
1273                    if (setup_item_i > setup_h)
1274                    {
1275                        setup_item_i -= setup_h;
1276                        setup_item_p -= setup_h;
1277                    }
1278                else
1279                    {
1280                        setup_item_i = 0;
1281                        setup_item_p = 0;
1282                    }
1283                }
1284            }
1285        }
1286    }
1287    if (Input::WasPressed(Key::PageDown))
1288    {
1289        if (g_setup)
1290        {
1291            if (!setup_switch)
1292            {
1293                if (setup_cursor < setup_h - 1)
1294                {
1295                    setup_option_i += setup_h - setup_cursor - 1;
1296                    setup_cursor = setup_h - 1;
1297                    setup_item_i = 0;
1298                }
1299                else
1300                {
1301                    if (setup_option_i < setup_option_n - setup_h - 1)
1302                    {
1303                        setup_option_i += setup_h;
1304                        setup_option_p += setup_h;
1305                    }
1306                else
1307                    {
1308                        setup_option_i = setup_option_n - 1;
1309                        setup_option_p = setup_option_n - setup_h;
1310                    }
1311                }
1312            }
1313            else
1314            {
1315                if (setup_cursor < setup_h - 1)
1316                {
1317                    setup_item_i += (setup_n < setup_h) ? setup_n - setup_cursor : setup_h - setup_cursor - 1;
1318                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
1319                }
1320                else
1321                {
1322                    if (setup_item_i < setup_n - setup_h + 1)
1323                    {
1324                        setup_item_i += setup_h;
1325                        setup_item_p += setup_h;
1326                    }
1327                else
1328                    {
1329                        setup_item_i = setup_n;
1330                        setup_item_p = setup_n - setup_h + 1;
1331                    }
1332                }
1333            }
1334        }
1335    }
1336    if (Input::WasPressed(Key::Left))
1337    {
1338        if (g_setup && setup_switch)
1339        {
1340            theme_var[theme_var_key] -= setup_conf[setup_item_key].z;
1341            if (theme_var[theme_var_key] < setup_conf[setup_item_key].x) theme_var[theme_var_key] = setup_conf[setup_item_key].x;
1342            InitShaderVar();
1343            UpdateSize();
1344        }
1345    }
1346    if (Input::WasPressed(Key::Right))
1347    {
1348        if (g_setup && setup_switch)
1349        {
1350            theme_var[theme_var_key] += setup_conf[setup_item_key].z;
1351            if (theme_var[theme_var_key] > setup_conf[setup_item_key].y) theme_var[theme_var_key] = setup_conf[setup_item_key].y;
1352            InitShaderVar();
1353            UpdateSize();
1354        }
1355    }
1356    if (Input::WasPressed(Key::Home))
1357    {
1358        if (g_setup && setup_switch)
1359        {
1360            theme_var[theme_var_key] = setup_conf[setup_item_key].x;
1361            InitShaderVar();
1362            UpdateSize();
1363        }
1364    }
1365    if (Input::WasPressed(Key::End))
1366    {
1367        if (g_setup && setup_switch)
1368        {
1369            theme_var[theme_var_key] = setup_conf[setup_item_key].y;
1370            InitShaderVar();
1371            UpdateSize();
1372        }
1373    }
1374    if (Input::WasPressed(Key::Return))
1375    {
1376        beat_flag = true;
1377        beat_angle = main_angle;
1378        //flash_flag = true;
1379        //flash_angle = main_angle;
1380    }
1381
1382    Entity::TickDraw(seconds);
1383
1384    if (!m_ready)
1385    {
1386        CreateGLWindow();
1387        m_txt_screen->Init();
1388        m_txt_setup->Init();
1389        m_ready = true;
1390    }
1391
1392    // timer
1393    if (!m_pause)
1394    {
1395        timer += seconds;
1396        main_angle = timer * 100.0f * PID;
1397    }
1398    if (sync_flag)
1399    {
1400        angle = (main_angle - sync_angle) * sync_speed;
1401        sync_value = 1.0f - sinf(angle);
1402        if (angle > 90.0f * PID)
1403        {
1404            sync_value = 0;
1405            sync_flag = false;
1406        }
1407    }
1408    if (beat_flag)
1409    {
1410        angle = (main_angle - beat_angle) * beat_speed;
1411        beat_value = 1.0f - sinf(angle);
1412        if (angle > 90.0f * PID)
1413        {
1414            beat_value = 0;
1415            beat_flag = false;
1416        }
1417    }
1418    if (flash_flag)
1419    {
1420        angle = (main_angle - flash_angle) * flash_speed;
1421        flash_value = 1.0f - sinf(angle);
1422        if (angle > 90.0f * PID)
1423        {
1424            flash_value = 0;
1425            flash_flag = false;
1426        }
1427    }
1428    if (fade_flag)
1429    {
1430        angle = (main_angle - fade_angle) * fade_speed;
1431        fade_value = 1.0f - sinf(angle);
1432        if (angle > 90.0f * PID)
1433        {
1434            fade_value = 0;
1435            fade_flag = false;
1436        }
1437    }
1438
1439    Draw2D();
1440    Draw3D();
1441}
1442
1443void Render::Draw2D()
1444{
1445    /* Draw text in an offline buffer */
1446    m_txt_screen->Render();
1447
1448    if (g_setup)
1449        m_txt_setup->Render();
1450
1451    if (m_shader)
1452        fbo_back->Bind();
1453
1454    glViewport(0, 0, screen_size.x, screen_size.y);
1455
1456    /* Clear the back buffer */
1457    glEnable(GL_TEXTURE_2D);
1458    glEnable(GL_BLEND);
1459    glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA);
1460
1461    Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
1462    Video::SetClearDepth(1.0f); // set depth buffer
1463    Video::Clear(ClearMask::Color | ClearMask::Depth);
1464
1465    m_txt_screen->Blit(border, canvas_size);
1466    if (g_setup)
1467        m_txt_setup->Blit((screen_size - setup_canvas_size) / 2, setup_canvas_size);
1468
1469    glMatrixMode(GL_PROJECTION);
1470    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
1471    glLoadMatrixf(&m[0][0]);
1472    glMatrixMode(GL_MODELVIEW);
1473
1474    fx_angle=main_angle-part_angle;
1475}
1476
1477void Render::Draw3D()
1478{
1479    if (!m_shader)
1480        return;
1481
1482    glDisable(GL_DEPTH_TEST);
1483    glDisable(GL_BLEND);
1484
1485    glEnableClientState(GL_VERTEX_ARRAY);
1486    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
1487
1488    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1489    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
1490
1491    if (m_shader_copper)
1492    {
1493        // shader copper
1494        fbo_tmp->Bind();
1495        shader_copper->Bind();
1496        shader_copper->SetUniform(shader_copper_texture, fbo_back->GetTexture(), 0);
1497        shader_copper->SetUniform(shader_copper_screen_size, (vec2)screen_size);
1498        shader_copper->SetUniform(shader_copper_time, fx_angle);
1499        shader_copper->SetUniform(shader_copper_copper, vec4(copper_copper.x, copper_copper.y, copper_copper.z * 16.0f, copper_copper.w * 16.0f));
1500        shader_copper->SetUniform(shader_copper_mask_color, copper_mask_color / 4.0f);
1501        TraceQuad();
1502        shader_color->Unbind();
1503        fbo_tmp->Unbind();
1504        // shader simple
1505        fbo_back->Bind();
1506        ShaderSimple(fbo_tmp, 0);
1507        fbo_back->Unbind();
1508    }
1509
1510    if (m_shader_remanence)
1511    {
1512        // shader remanence
1513        fbo_tmp->Bind();
1514        shader_remanence->Bind();
1515        shader_remanence->SetUniform(shader_remanence_source, fbo_back->GetTexture(), 0);
1516        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1517        shader_remanence->SetUniform(shader_remanence_mix, remanence);
1518        TraceQuad();
1519        shader_remanence->Unbind();
1520        fbo_tmp->Unbind();
1521        // shader simple
1522        fbo_back->Bind();
1523        ShaderSimple(fbo_tmp, 0);
1524        fbo_back->Unbind();
1525        // save previous fbo
1526        fbo_tmp->Bind();
1527        shader_remanence->Bind();
1528        shader_remanence->SetUniform(shader_remanence_source, fbo_screen->GetTexture(), 0);
1529        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1530        shader_remanence->SetUniform(shader_remanence_mix, buffer);
1531        TraceQuad();
1532        shader_remanence->Unbind();
1533        fbo_tmp->Unbind();
1534        // shader simple
1535        fbo_buffer->Bind();
1536        ShaderSimple(fbo_tmp, 0);
1537        fbo_buffer->Unbind();
1538    }
1539
1540    // shader glow
1541    if (m_shader_glow)
1542    {
1543        // shader blur horizontal
1544        fbo_blur_h->Bind();
1545        shader_blur_h->Bind();
1546        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_back->GetTexture(), 0);
1547        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
1548        TraceQuad();
1549        shader_blur_h->Unbind();
1550        fbo_blur_h->Unbind();
1551        // shader blur vertical
1552        fbo_blur_v->Bind();
1553        shader_blur_v->Bind();
1554        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1555        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
1556        TraceQuad();
1557        shader_blur_v->Unbind();
1558        fbo_blur_v->Unbind();
1559        // shader blur horizontal
1560        fbo_blur_h->Bind();
1561        shader_blur_h->Bind();
1562        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
1563        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
1564        TraceQuad();
1565        shader_blur_h->Unbind();
1566        fbo_blur_h->Unbind();
1567        // shader blur vertical
1568        fbo_blur_v->Bind();
1569        shader_blur_v->Bind();
1570        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1571        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
1572        TraceQuad();
1573        shader_blur_v->Unbind();
1574        fbo_blur_v->Unbind();
1575        // shader glow
1576        fbo_screen->Bind();
1577        shader_glow->Bind();
1578        shader_glow->SetUniform(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
1579        shader_glow->SetUniform(shader_glow_source, fbo_back->GetTexture(), 1);
1580        shader_glow->SetUniform(shader_glow_mix, glow_mix);
1581        TraceQuad();
1582        shader_glow->Unbind();
1583        fbo_screen->Unbind();
1584    }
1585    else
1586    {
1587        // shader simple
1588        fbo_screen->Bind();
1589        ShaderSimple(fbo_back, 0);
1590        fbo_screen->Unbind();
1591    }
1592
1593    if (m_shader_color)
1594    {
1595        // shader color
1596        fbo_tmp->Bind();
1597        shader_color->Bind();
1598        shader_color->SetUniform(shader_color_texture, fbo_screen->GetTexture(), 0);
1599        shader_color->SetUniform(shader_color_screen_size, (vec2)screen_size);
1600        shader_color->SetUniform(shader_color_filter, color_filter);
1601        shader_color->SetUniform(shader_color_color, color_color);
1602        shader_color->SetUniform(shader_color_flash, flash_value);
1603        TraceQuad();
1604        shader_color->Unbind();
1605        fbo_tmp->Unbind();
1606        // shader simple
1607        fbo_screen->Bind();
1608        ShaderSimple(fbo_tmp, 0);
1609        fbo_screen->Unbind();
1610    }
1611
1612    if (m_shader_noise)
1613    {
1614        // shader noise
1615        fbo_tmp->Bind();
1616        shader_noise->Bind();
1617        shader_noise->SetUniform(shader_noise_texture, fbo_screen->GetTexture(), 0);
1618        shader_noise->SetUniform(shader_noise_screen_size, (vec2)screen_size);
1619        shader_noise->SetUniform(shader_noise_time, fx_angle);
1620        shader_noise->SetUniform(shader_noise_offset, noise_offset);
1621        shader_noise->SetUniform(shader_noise_noise, noise_noise);
1622        shader_noise->SetUniform(shader_noise_retrace, noise_retrace);
1623        TraceQuad();
1624        shader_noise->Unbind();
1625        fbo_tmp->Unbind();
1626        // shader simple
1627        fbo_screen->Bind();
1628        ShaderSimple(fbo_tmp, 0);
1629        fbo_screen->Unbind();
1630    }
1631
1632    if (m_shader_blur)
1633    {
1634        // shader blur horizontal
1635        fbo_tmp->Bind();
1636        shader_blur_h->Bind();
1637        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_screen->GetTexture(), 0);
1638        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
1639        TraceQuad();
1640        shader_blur_h->Unbind();
1641        fbo_tmp->Unbind();
1642        // shader blur vertical
1643        fbo_screen->Bind();
1644        shader_blur_v->Bind();
1645        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_tmp->GetTexture(), 0);
1646        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
1647        TraceQuad();
1648        shader_blur_v->Unbind();
1649        fbo_screen->Unbind();
1650    }
1651
1652    if (m_shader_postfx)
1653    {
1654        // shader postfx
1655        fbo_front->Bind();
1656        shader_postfx->Bind();
1657        shader_postfx->SetUniform(shader_postfx_texture, fbo_screen->GetTexture(), 0);
1658        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
1659        shader_postfx->SetUniform(shader_postfx_ratio_2d, (vec2)ratio_2d / 2);
1660        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
1661        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
1662        shader_postfx->SetUniform(shader_postfx_ghost1, vec4(postfx_ghost1.xyz * 0.01, postfx_ghost1.w));
1663        shader_postfx->SetUniform(shader_postfx_ghost2, vec4(postfx_ghost2.xyz * 0.01, postfx_ghost2.w));
1664        shader_postfx->SetUniform(shader_postfx_glass, vec4(postfx_glass.xy * 0.01, postfx_glass.z * 0.1, postfx_glass.w));
1665        shader_postfx->SetUniform(shader_postfx_gradient, postfx_gradient);
1666        shader_postfx->SetUniform(shader_postfx_gradient_color, postfx_gradient_color);
1667        shader_postfx->SetUniform(shader_postfx_vignetting, postfx_vignetting);
1668        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
1669        shader_postfx->SetUniform(shader_postfx_moire_h, vec4(postfx_moire_h.xyz, postfx_moire_h.w * 2 * M_PI));
1670        shader_postfx->SetUniform(shader_postfx_moire_v, vec4(postfx_moire_v.xyz, postfx_moire_v.w * 2 * M_PI));
1671        shader_postfx->SetUniform(shader_postfx_scanline_h, vec4(postfx_scanline_h.xyz, postfx_scanline_h.w * 2 * M_PI));
1672        shader_postfx->SetUniform(shader_postfx_scanline_v, vec4(postfx_scanline_v.xyz, postfx_scanline_v.w * 2 * M_PI));
1673        shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
1674        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(sync_value * cosf((main_angle - sync_angle) * 6.0f)));
1675        shader_postfx->SetUniform(shader_postfx_beat, (float)fabs(beat_value * cosf((main_angle - beat_angle) * 6.0f)));
1676        TraceQuad();
1677        shader_postfx->Unbind();
1678        fbo_front->Unbind();
1679    }
1680    else
1681    {
1682        // shader simple
1683        fbo_front->Bind();
1684        ShaderSimple(fbo_screen, 0);
1685        fbo_front->Unbind();
1686    }
1687
1688    if (m_shader_mirror)
1689    {
1690        // shader mirror
1691        fbo_tmp->Bind();
1692        shader_mirror->Bind();
1693        shader_mirror->SetUniform(shader_mirror_texture, fbo_front->GetTexture(), 0);
1694        shader_mirror->SetUniform(shader_mirror_screen_size, (vec2)screen_size);
1695        shader_mirror->SetUniform(shader_mirror_mirror, vec4(mirror.x * 0.1f, mirror.y * 0.1f, mirror.z, mirror.w));
1696        TraceQuad();
1697        shader_mirror->Unbind();
1698        fbo_tmp->Unbind();
1699        // shader simple
1700        fbo_front->Bind();
1701        ShaderSimple(fbo_tmp, 0);
1702        fbo_front->Unbind();
1703    }
1704
1705    if (m_shader_radial)
1706    {
1707        // shader radial blur
1708        fbo_tmp->Bind();
1709        shader_radial->Bind();
1710        shader_radial->SetUniform(shader_radial_texture, fbo_front->GetTexture(), 0);
1711        shader_radial->SetUniform(shader_radial_screen_size, (vec2)screen_size);
1712        shader_radial->SetUniform(shader_radial_radial, vec4(radial.x, radial.y, radial.z, radial.w * 0.1f));
1713        TraceQuad();
1714        shader_radial->Unbind();
1715        fbo_tmp->Unbind();
1716        // shader simple
1717        fbo_front->Bind();
1718        ShaderSimple(fbo_tmp, 0);
1719        fbo_front->Unbind();
1720    }
1721
1722    // shader simple
1723    ShaderSimple(fbo_front, 0);
1724
1725    glDisableClientState(GL_VERTEX_ARRAY);
1726    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1727}
1728
1729Render::~Render()
1730{
1731    if (m_fps_debug)
1732        Ticker::Unref(m_fps_debug);
1733}
Note: See TracBrowser for help on using the repository browser.