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

Last change on this file since 2092 was 2092, checked in by sam, 8 years ago

neercs: do not pass the texture coordinates from the application to
the GL server; instead, simply deduce them from the vertex coordinates
and interpolate them in the fragment shader.

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