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

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

neercs: removed flags from setup, butchered scanline postfx

File size: 55.0 KB
Line 
1//
2// Neercs
3//
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#if defined _XBOX
10#   define _USE_MATH_DEFINES /* for M_PI */
11#   include <xtl.h>
12#elif defined _WIN32
13#   define _USE_MATH_DEFINES /* for M_PI */
14#   define WIN32_LEAN_AND_MEAN
15#   include <windows.h>
16#endif
17
18#include <cmath>
19#include <cstdio>
20#include <cstdlib>
21#include <ctime>
22#include <string>
23
24#include "core.h"
25#include "lolgl.h"
26#include "loldebug.h"
27
28using namespace std;
29using namespace lol;
30
31#include "../neercs.h"
32#include "render.h"
33#include "text-render.h"
34
35extern char const *lolfx_simple;
36extern char const *lolfx_blurh;
37extern char const *lolfx_blurv;
38extern char const *lolfx_glow;
39extern char const *lolfx_remanence;
40extern char const *lolfx_copper;
41extern char const *lolfx_color;
42extern char const *lolfx_noise;
43extern char const *lolfx_postfx;
44extern char const *lolfx_mirror;
45extern char const *lolfx_radial;
46
47#define PID M_PI/180.0f    // pi ratio
48
49/*
50 * Global variable -- ugly (<rez> sam: c'est toi qui est ugly! \:D/)
51 */
52bool g_setup = false;
53
54/*
55 * Various variables
56 */
57
58int active = true;         // window active flag
59float nearplane = 0.1f;    // nearplane
60float farplane = 1000.0f;  // farplane
61/* timer variable */
62float timer = 0;           // timer
63/* window variable */
64ivec2 screen_size;         // screen size
65/* object variable */
66float main_angle = 0.0f;   // main angle
67float part_angle = 0.0f;   // part angle
68float fx_angle;            // current angle
69/* fs_quad variable */
70float fs_quad_vtx[] = {-1.0f, 1.0f, 0, 1.0f, -1.0f, -1.0f, 0, 1.0f, 1.0f, -1.0f, 0, 1.0f, 1.0f, 1.0f, 0, 1.0f};
71float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
72/* flash variable */
73bool flash_flag = false;   // flag
74float flash_angle = 0;     // angle
75float flash_value = 0;     // value
76float flash_speed = 2.0f;  // speed
77/* fade variable */
78bool fade_flag = false;    // flag
79float fade_angle = 0;      // angle
80float fade_value = 0;      // value
81float fade_speed = 0.2f;   // speed
82/* sync variable */
83bool sync_flag = false;    // flagsh
84float sync_angle = 0;      // angle
85float sync_value = 0;      // value
86float sync_speed = 1.0f;   // speed
87/* beat variable */
88bool beat_flag = false;    // flag
89float beat_angle = 0;      // angle
90float beat_value = 0;      // value
91float beat_speed = 2.0f;   // speed
92/* common variable */
93float value, angle, radius, scale, speed;
94/* text variable */
95ivec2 map_size(256,256);   // texture map size
96ivec2 canvas_char(0,0);    // canvas char number
97ivec2 canvas_size(0,0);    // caca size
98ivec2 font_size(8,8);      // font size
99ivec2 ratio_2d(1,1);       // 2d ratio
100ivec2 border(0,0);         // border width
101/* shader variable */
102vec2 buffer;               // [new frame mix,old frame mix]
103vec2 remanence;            // remanence [source mix,buffer mix]
104vec2 glow_mix;             // glow mix [source mix,glow mix]
105vec2 glow_large;           // large glow radius [center,corner]
106vec2 glow_small;           // small glow radius [center,corner]
107vec2 blur;                 // blur radius [center,corner]
108vec4 copper_copper;        // copper [base,variable,repeat,color cycle]
109vec3 copper_mask_color;    // color [red,green,blue]
110vec3 color_filter;         // color filter [red,green,blue]
111vec4 color_color;          // color modifier [brightness,contrast,level,grayscale]
112vec2 noise_offset;         // random line [horizontal,vertical]
113float noise_noise;         // noise
114vec3 noise_retrace;        // retrace [strength,length,speed]
115vec2 postfx_deform;        // deformation [ratio,zoom]
116float postfx_vignetting;   // vignetting strength
117float postfx_aberration;   // chromatic aberration
118vec4 postfx_ghost1;        // ghost picture 1 [position x,position y,position z,strength]
119vec4 postfx_ghost2;        // ghost picture 2 [position x,position y,position z,strength]
120vec3 postfx_gradient;      // gradient [position y,height,strength]
121vec3 postfx_gradient_color;// gradient color [red,green,blue]
122vec4 postfx_glass;         // glass [depth,thickness,strength,deform ratio]
123vec4 postfx_moire_h;       // vertical moire [base,variable,repeat,shift]
124vec4 postfx_moire_v;       // horizontal moire [base,variable,repeat,shift]
125vec4 postfx_scanline_h;    // vertical scanline [base,variable,repeat,shift]
126vec4 postfx_scanline_v;    // horizontal scanline [base,variable,repeat,shift]
127vec3 postfx_corner;        // corner [width,radius,blur]
128vec4 mirror;               // mirror [width,height,strength,ratio]
129vec4 radial;               // radial [distance,fade ratio,iteration,strength]
130/* theme variable */
131int theme_i = 0;           // current theme
132const int theme_n = 4;     // theme number
133int theme_var_key = 0;     // theme array key
134/* setup variable */
135bool setup_switch = false;      // switch [option/item]
136int setup_n = 0;                // item/option number
137int setup_h = 8;                // height
138int setup_cursor = 0;           // cursor position
139int setup_option_i = 0;         // selected option
140const int setup_option_n = 15;  // option number
141int setup_option_p = 0;         // option position
142int setup_item_i = 0;           // selected item
143int setup_item_n = 8;           // item number
144int setup_item_p = 0;           // item position
145int setup_item_key = 0;         // item array key
146ivec3 setup_size(29, 9, 12);    // size [w,h,split]
147ivec2 setup_canvas_size(ivec2(setup_size.x + 1, setup_size.y + 1) * font_size * ivec2(2,4));
148ivec2 setup_color(0xaaa, 0x222);// color [foreground,background] 0x678,0x234
149char const *setup_text[]={
150    "main",
151        "2d ratio w",
152        "2d ratio h",
153        "border w",
154        "border h",
155        "",
156        "",
157        "",
158        "",
159    "remanence",
160        "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    0.75f,0.0f,0.0f,0.0f,     // postfx_moire_h
532    0.75f,-0.25f,0.25f,0.5f,  // 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.75f,0.0f,          // color_filter
570    1.0f,1.25f,0.2f,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.5f,0.15f,0.05f,         // postfx_gradient
582    0.8f,0.8f,0.8f,           // 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.4f,0.6f,                // buffer
606    0.4f,0.6f,                // 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.0f,1.15f,0.1f,0.25f,    // color_color
628    2.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.5f,0.0f,0.0f ,          // postfx_gradient
639    0.0f,0.0f,0.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.80f,0.2f,0.75f,0.0f,    // postfx_scanline_h
649    0.80f,0.2f,0.75f,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 */
657/* intex system 4000 */
6580};
659
660void Render::InitShaderVar()
661{
662    int k = theme_i * setup_option_n * 9 + 1; /* main */
663    ratio_2d = vec2(theme_var[k], theme_var[k + 1]); k += 2;
664    border = vec2(theme_var[k], theme_var[k + 1]); k += 2;
665    k += 5; /* remanence */
666    buffer = vec2(theme_var[k], theme_var[k + 1]); k += 2;
667    remanence = vec2(theme_var[k], theme_var[k + 1]); k += 2;
668    k += 5; /* glow */
669    glow_mix = vec2(theme_var[k], theme_var[k + 1]); k += 2;
670    glow_large = vec2(theme_var[k], theme_var[k + 1]); k += 2;
671    glow_small = vec2(theme_var[k], theme_var[k + 1]); k += 2;
672    k += 3; /* blur */
673    blur = vec2(theme_var[k], theme_var[k + 1]); k += 2;
674    k += 7; /* screen */
675    postfx_deform = vec2(theme_var[k], theme_var[k + 1]); k += 2;
676    postfx_corner = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
677    postfx_vignetting = theme_var[k]; k++;
678    k += 3; /* copper */
679    copper_copper = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
680    copper_mask_color = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
681    k += 2; /* color */
682    color_filter = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
683    color_color = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
684    postfx_aberration = theme_var[k]; k++;
685    k += 1; /* noise */
686    noise_offset = vec2(theme_var[k], theme_var[k + 1]); k += 2;
687    noise_noise = theme_var[k]; k++;
688    noise_retrace = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
689    k += 3; /* ghost */
690    postfx_ghost1 = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
691    postfx_ghost2 = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
692    k += 1; /* gradient */
693    postfx_gradient = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
694    postfx_gradient_color = vec3(theme_var[k], theme_var[k + 1], theme_var[k + 2]); k += 3;
695    k += 3; /* glass */
696    postfx_glass = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
697    k += 5; /* moire */
698    postfx_moire_h = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
699    postfx_moire_v = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
700    k += 1; /* scanline */
701    postfx_scanline_h = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
702    postfx_scanline_v = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
703    k += 1; /* mirror */
704    mirror = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
705    k += 5; /* radial blur */
706    radial = vec4(theme_var[k], theme_var[k + 1], theme_var[k + 2], theme_var[k + 3]); k += 4;
707}
708
709void Render::UpdateSize()
710{
711    screen_size = Video::GetSize();
712    canvas_char = (screen_size - border * ratio_2d * font_size * 2) / (font_size * ratio_2d);
713    canvas_char = max(canvas_char, ivec2(1, 1));
714    canvas_size = canvas_char * font_size * ratio_2d;
715
716    border = (screen_size - canvas_size) / 2;
717
718    caca_set_canvas_size(m_cv_screen, canvas_char.x, canvas_char.y);
719    caca_set_canvas_size(m_cv_setup, setup_size.x + 1, setup_size.y + 1);
720}
721
722int calc_item_length()
723{
724    int n = !setup_switch ? setup_option_n : setup_item_n;
725    for (int i = 0; i < n; i++)
726    {
727        int k = !setup_switch ? (i * (setup_item_n + 1)) : (setup_option_i * (setup_item_n + 1) + 1 + i);
728        if (setup_text[k][0] == '\0') return i - 1;
729    }
730    return n - 1;
731}
732
733Shader *shader_simple;
734Shader *shader_blur_h, *shader_blur_v, *shader_glow;
735Shader *shader_remanence, *shader_copper, *shader_color;
736Shader *shader_noise, *shader_postfx, *shader_mirror, *shader_radial;
737// shader variables
738ShaderUniform shader_simple_texture;
739ShaderUniform shader_blur_h_texture,
740              shader_blur_h_radius,
741              shader_blur_v_texture,
742              shader_blur_v_radius;
743ShaderUniform shader_glow_glow,
744              shader_glow_source,
745              shader_glow_mix;
746ShaderUniform shader_remanence_source,
747              shader_remanence_buffer,
748              shader_remanence_mix;
749ShaderUniform shader_copper_texture,
750              shader_copper_screen_size,
751              shader_copper_time,
752              shader_copper_copper,
753              shader_copper_mask_color;
754ShaderUniform shader_color_texture,
755              shader_color_screen_size,
756              shader_color_filter,
757              shader_color_color,
758              shader_color_flash;
759ShaderUniform shader_noise_texture,
760              shader_noise_screen_size,
761              shader_noise_time,
762              shader_noise_offset,
763              shader_noise_noise,
764              shader_noise_retrace;
765ShaderUniform shader_postfx_texture,
766              shader_postfx_texture_2d,
767              shader_postfx_screen_size,
768              shader_postfx_ratio_2d,
769              shader_postfx_time,
770              shader_postfx_deform,
771              shader_postfx_ghost1,
772              shader_postfx_ghost2,
773              shader_postfx_glass,
774              shader_postfx_vignetting,
775              shader_postfx_gradient,
776              shader_postfx_gradient_color,
777              shader_postfx_aberration,
778              shader_postfx_moire_h,
779              shader_postfx_moire_v,
780              shader_postfx_scanline_h,
781              shader_postfx_scanline_v,
782              shader_postfx_corner,
783              shader_postfx_sync,
784              shader_postfx_beat;
785ShaderUniform shader_mirror_texture,
786              shader_mirror_screen_size,
787              shader_mirror_mirror;
788ShaderUniform shader_radial_texture,
789              shader_radial_screen_size,
790              shader_radial_radial;
791
792FrameBuffer *fbo_back, *fbo_front, *fbo_screen;
793FrameBuffer *fbo_blur_h, *fbo_blur_v;
794FrameBuffer *fbo_tmp, *fbo_buffer;
795
796void Render::TraceQuad()
797{
798    glLoadIdentity();
799    glDrawArrays(GL_QUADS, 0, 4);
800}
801
802void Render::ShaderSimple(FrameBuffer *fbo_output, int n)
803{
804    shader_simple->Bind();
805    shader_simple->SetUniform(shader_simple_texture, fbo_output->GetTexture(), n);
806    TraceQuad();
807    shader_simple->Unbind();
808}
809
810int Render::InitDraw(void)
811{
812    glDepthMask(GL_TRUE);     // do not write z-buffer
813    glEnable(GL_CULL_FACE);   // disable cull face
814    glCullFace(GL_BACK);      // don't draw front face
815    /* initialise framebuffer objects */
816    fbo_back = new FrameBuffer(screen_size);
817    fbo_screen = new FrameBuffer(screen_size);
818    fbo_front = new FrameBuffer(screen_size);
819    fbo_buffer = new FrameBuffer(screen_size);
820    fbo_blur_h = new FrameBuffer(screen_size);
821    fbo_blur_v = new FrameBuffer(screen_size);
822    fbo_tmp = new FrameBuffer(screen_size);
823    // shader simple
824    shader_simple = Shader::Create(lolfx_simple);
825    shader_simple_texture = shader_simple->GetUniformLocation("texture");
826    // shader glow
827    shader_glow = Shader::Create(lolfx_glow);
828    shader_glow_glow = shader_glow->GetUniformLocation("glow");
829    shader_glow_source = shader_glow->GetUniformLocation("source");
830    shader_glow_mix = shader_glow->GetUniformLocation("mix");
831    // shader blur horizontal
832    shader_blur_h = Shader::Create(lolfx_blurh);
833    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
834    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
835    // shader blur vertical
836    shader_blur_v = Shader::Create(lolfx_blurv);
837    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
838    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
839    // shader remanence
840    shader_remanence = Shader::Create(lolfx_remanence);
841    shader_remanence_source = shader_remanence->GetUniformLocation("source");
842    shader_remanence_buffer = shader_remanence->GetUniformLocation("buffer");
843    shader_remanence_mix = shader_remanence->GetUniformLocation("mix");
844    // shader copper
845    shader_copper = Shader::Create(lolfx_copper);
846    shader_copper_texture = shader_copper->GetUniformLocation("texture");
847    shader_copper_screen_size = shader_copper->GetUniformLocation("screen_size");
848    shader_copper_time = shader_copper->GetUniformLocation("time");
849    shader_copper_copper = shader_copper->GetUniformLocation("copper");
850    shader_copper_mask_color = shader_copper->GetUniformLocation("mask_color");
851    // shader color
852    shader_color = Shader::Create(lolfx_color);
853    shader_color_texture = shader_color->GetUniformLocation("texture");
854    shader_color_screen_size = shader_color->GetUniformLocation("screen_size");
855    shader_color_filter = shader_color->GetUniformLocation("filter");
856    shader_color_color = shader_color->GetUniformLocation("color");
857    shader_color_flash = shader_color->GetUniformLocation("flash");
858    // shader noise
859    shader_noise = Shader::Create(lolfx_noise);
860    shader_noise_texture = shader_noise->GetUniformLocation("texture");
861    shader_noise_screen_size = shader_noise->GetUniformLocation("screen_size");
862    shader_noise_time = shader_noise->GetUniformLocation("time");
863    shader_noise_offset = shader_noise->GetUniformLocation("offset");
864    shader_noise_noise = shader_noise->GetUniformLocation("noise");
865    shader_noise_retrace = shader_noise->GetUniformLocation("retrace");
866    // shader postfx
867    shader_postfx = Shader::Create(lolfx_postfx);
868    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
869    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
870    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
871    shader_postfx_ratio_2d = shader_postfx->GetUniformLocation("ratio_2d");
872    shader_postfx_time = shader_postfx->GetUniformLocation("time");
873    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
874    shader_postfx_ghost1 = shader_postfx->GetUniformLocation("ghost1");
875    shader_postfx_ghost2 = shader_postfx->GetUniformLocation("ghost2");
876    shader_postfx_glass = shader_postfx->GetUniformLocation("glass");
877    shader_postfx_gradient = shader_postfx->GetUniformLocation("gradient");
878    shader_postfx_gradient_color = shader_postfx->GetUniformLocation("gradient_color");
879    shader_postfx_vignetting = shader_postfx->GetUniformLocation("vignetting");
880    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
881    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
882    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
883    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
884    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
885    shader_postfx_corner = shader_postfx->GetUniformLocation("corner");
886    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
887    shader_postfx_beat = shader_postfx->GetUniformLocation("beat");
888    // shader mirror
889    shader_mirror = Shader::Create(lolfx_mirror);
890    shader_mirror_texture = shader_mirror->GetUniformLocation("texture");
891    shader_mirror_screen_size = shader_mirror->GetUniformLocation("screen_size");
892    shader_mirror_mirror = shader_mirror->GetUniformLocation("mirror");
893    // shader radial blur
894    shader_radial = Shader::Create(lolfx_radial);
895    shader_radial_texture = shader_radial->GetUniformLocation("texture");
896    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
897    shader_radial_radial = shader_radial->GetUniformLocation("radial");
898    // initialize setup
899    setup_n = calc_item_length();
900    return true;
901}
902
903int Render::CreateGLWindow()
904{
905    InitShaderVar();
906    UpdateSize();
907    InitDraw();
908    return true;
909}
910
911Render::Render(caca_canvas_t *caca)
912  : m_cv_screen(caca),
913    m_cv_setup(caca_create_canvas(1, 1)),
914    m_fps_debug(0),
915    m_ready(false),
916    m_pause(false),
917    m_shader(true),
918    m_shader_remanence(true),
919    m_shader_glow(true),
920    m_shader_blur(true),
921    m_shader_postfx(true),
922    m_shader_copper(true),
923    m_shader_color(true),
924    m_shader_noise(true),
925    m_shader_mirror(true),
926    m_shader_radial(true)
927{
928    m_txt_screen = new TextRender(m_cv_screen, font_size);
929    m_txt_setup = new TextRender(m_cv_setup, font_size);
930}
931
932void Render::TickGame(float seconds)
933{
934    Entity::TickGame(seconds);
935    /* draw setup */
936    if (g_setup)
937    {
938        /* background */
939        caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
940        caca_fill_box(m_cv_setup, 0, 0, setup_size.x + 1, setup_size.y,' ');
941        caca_draw_line(m_cv_setup, setup_size.z - 1, 1, setup_size.z - 1, setup_size.y - 1,'|');
942        /* title */
943        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
944        caca_draw_line(m_cv_setup, 0, 0, setup_size.x, 0, ' ');
945        caca_put_str(m_cv_setup, setup_size.x / 2 - 3, 0, "SETUP");
946        /* informations */
947        /*
948        int w = caca_get_canvas_width(m_cv_screen);
949        int h = caca_get_canvas_height(m_cv_screen);
950        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
951        caca_printf(m_cv_setup, 1, 0, "%i*%i", w, h);
952        */
953        /* display option */
954        for (int i = 0; i < setup_h; i++)
955        {
956            int y = 1 + i;
957            int k = (setup_option_p + i) * (setup_item_n + 1);
958            if (setup_option_i != setup_option_p + i || setup_switch)
959            {
960                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
961                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
962            }
963            else
964            {
965                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
966                caca_draw_line(m_cv_setup, 0, y, setup_size.z - 2, y,' ');
967                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
968            }
969        }
970        /* display item */
971        for (int i = 0; i < setup_h; i++)
972        {
973            int y = 1 + i;
974            int k = setup_option_i * (setup_item_n + 1) + 1 + setup_item_p + i;
975            if (setup_item_i != setup_item_p + i || !setup_switch)
976            {
977                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
978                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
979            }
980            else
981            {
982                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
983                caca_draw_line(m_cv_setup, setup_size.z, y, setup_size.x, y,' ');
984                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
985            }
986        }
987        /* display variable */
988        int y = setup_size.y;
989        setup_item_key = setup_option_i * (setup_item_n + 1) + 1 + setup_item_i;
990        theme_var_key = theme_i * setup_option_n * 9 + setup_item_key;
991        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
992        caca_draw_line(m_cv_setup, 0, y, setup_size.x, y,' ');
993        if (setup_switch)
994        {
995            int x = 1;
996            int w = setup_size.x - 3 - 4;
997            float bar_w = w / (setup_conf[setup_item_key].y - setup_conf[setup_item_key].x);
998            int bar_x = bar_w * setup_conf[setup_item_key].x;
999            if ((setup_conf[setup_item_key].y - setup_conf[setup_item_key].x) / setup_conf[setup_item_key].z > 1)
1000            {
1001                /* work around a bug in libcaca */
1002                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]);
1003                caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * setup_conf[setup_item_key].y), y,'.');
1004                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');
1005            }
1006            else
1007            {
1008                if (setup_conf[setup_item_key] != vec4(0))
1009                {
1010                    caca_put_str(m_cv_setup, setup_size.x - 3, y, (theme_var[theme_var_key] == setup_conf[setup_item_key].y)?"YES":" NO");
1011                }
1012            }
1013        }
1014        else
1015        {
1016            caca_printf(m_cv_setup, 1, y, "%d/%d", setup_option_i, setup_n);
1017        }
1018    }
1019
1020}
1021
1022void Render::Pause()
1023{
1024    m_pause=!m_pause;
1025}
1026
1027void Render::TickDraw(float seconds)
1028{
1029    /* keyboard manager */
1030    if (Input::WasPressed(Key::F1))
1031    {
1032        g_setup = !g_setup;
1033        if (g_setup) setup_n = calc_item_length();
1034        sync_flag = true;
1035        sync_angle = main_angle;
1036        if (m_fps_debug)
1037        {
1038            Ticker::Unref(m_fps_debug);
1039            m_fps_debug = NULL;
1040        }
1041        if (g_setup)
1042        {
1043            m_fps_debug = new DebugFps(2, 2);
1044            Ticker::Ref(m_fps_debug);
1045        }
1046    }
1047    if (Input::WasPressed(Key::F2))
1048    {
1049        m_shader_remanence = !m_shader_remanence;
1050        m_shader_glow = !m_shader_glow;
1051        m_shader_blur = !m_shader_blur;
1052        m_shader_postfx = !m_shader_postfx;
1053        //m_shader_copper = !m_shader_copper;
1054        m_shader_color = !m_shader_color;
1055        m_shader_noise = !m_shader_noise;
1056        m_shader_mirror = !m_shader_mirror;
1057        m_shader_radial = !m_shader_radial;
1058    }
1059    if (Input::WasPressed(Key::F4))
1060    {
1061        theme_i--;
1062        if(theme_i < 0) theme_i = theme_n - 1;
1063        InitShaderVar();
1064        UpdateSize();
1065    }
1066    if (Input::WasPressed(Key::F5))
1067    {
1068        theme_i++;
1069        if(theme_i > theme_n - 1) theme_i = 0;
1070        InitShaderVar();
1071        UpdateSize();
1072    }
1073    if (Input::WasPressed(Key::Tab))
1074    {
1075        if (g_setup)
1076        {
1077            setup_switch = !setup_switch;
1078            setup_n = calc_item_length();
1079            setup_cursor = (!setup_switch?setup_option_i:setup_item_i) - (!setup_switch?setup_option_p:setup_item_p);
1080        }
1081    }
1082    if (Input::WasPressed(Key::Up))
1083    {
1084        if (g_setup)
1085        {
1086            if (!setup_switch)
1087            {
1088                if (setup_cursor > 0)
1089                {
1090                    setup_cursor--;
1091                }
1092                else
1093                {
1094                    if (setup_cursor == 0) setup_option_p--;
1095                }
1096                if (setup_option_i > 0)
1097                {
1098                    setup_option_i--;
1099                }
1100                else
1101                {
1102                    setup_option_i = setup_option_n - 1;
1103                    setup_option_p = setup_option_n - setup_h;
1104                    setup_cursor = setup_h - 1;
1105                }
1106                setup_item_i = 0;
1107                setup_item_p = 0;
1108            }
1109            else
1110            {
1111                if (setup_cursor > 0)
1112                {
1113                    setup_cursor--;
1114                }
1115                else
1116                {
1117                    if (setup_cursor == 0) setup_item_p--;
1118                }
1119                if (setup_item_i > 0)
1120                {
1121                    setup_item_i--;
1122                }
1123                else
1124                {
1125                    setup_item_i = setup_n;
1126                    setup_item_p = (setup_n < setup_h) ? 0 : setup_n - setup_h + 1;
1127                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
1128                }
1129            }
1130        }
1131    }
1132    if (Input::WasPressed(Key::Down))
1133    {
1134        if (g_setup)
1135        {
1136            if (!setup_switch)
1137            {
1138                if (setup_cursor < setup_h - 1)
1139                {
1140                    setup_cursor++;
1141                }
1142                else
1143                {
1144                    if (setup_cursor == setup_h - 1) setup_option_p++;
1145                }
1146                if (setup_option_i < setup_option_n - 1)
1147                {
1148                    setup_option_i++;
1149                }
1150                else
1151                {
1152                    setup_option_i = 0;
1153                    setup_option_p = 0;
1154                    setup_cursor = 0;
1155                }
1156                setup_item_i = 0;
1157                setup_item_p = 0;
1158            }
1159            else
1160            {
1161                if (setup_cursor < setup_h - 1)
1162                {
1163                    setup_cursor++;
1164                }
1165                else
1166                {
1167                    if (setup_cursor == setup_h - 1) setup_item_p++;
1168                }
1169                if (setup_item_i < setup_n)
1170                {
1171                    setup_item_i++;
1172                }
1173                else
1174                {
1175                    setup_item_i = 0;
1176                    setup_item_p = 0;
1177                    setup_cursor = 0;
1178                }
1179            }
1180        }
1181    }
1182    if (Input::WasPressed(Key::PageUp))
1183    {
1184        if (g_setup)
1185        {
1186            if (!setup_switch)
1187            {
1188                if (setup_cursor > 0)
1189                {
1190                    setup_option_i -= setup_cursor;
1191                    setup_cursor = 0;
1192                }
1193                else
1194                {
1195                    if (setup_option_i > setup_h)
1196                    {
1197                        setup_option_i -= setup_h;
1198                        setup_option_p -= setup_h;
1199                    }
1200                else
1201                    {
1202                        setup_option_i = 0;
1203                        setup_option_p = 0;
1204                    }
1205                }
1206            setup_item_i = 0;
1207            }
1208            else
1209            {
1210                if (setup_cursor > 0)
1211                {
1212                    setup_item_i -= setup_cursor;
1213                    setup_cursor = 0;
1214                }
1215                else
1216                {
1217                    if (setup_item_i > setup_h)
1218                    {
1219                        setup_item_i -= setup_h;
1220                        setup_item_p -= setup_h;
1221                    }
1222                else
1223                    {
1224                        setup_item_i = 0;
1225                        setup_item_p = 0;
1226                    }
1227                }
1228            }
1229        }
1230    }
1231    if (Input::WasPressed(Key::PageDown))
1232    {
1233        if (g_setup)
1234        {
1235            if (!setup_switch)
1236            {
1237                if (setup_cursor < setup_h - 1)
1238                {
1239                    setup_option_i += setup_h - setup_cursor - 1;
1240                    setup_cursor = setup_h - 1;
1241                    setup_item_i = 0;
1242                }
1243                else
1244                {
1245                    if (setup_option_i < setup_option_n - setup_h - 1)
1246                    {
1247                        setup_option_i += setup_h;
1248                        setup_option_p += setup_h;
1249                    }
1250                else
1251                    {
1252                        setup_option_i = setup_option_n - 1;
1253                        setup_option_p = setup_option_n - setup_h;
1254                    }
1255                }
1256            }
1257            else
1258            {
1259                if (setup_cursor < setup_h - 1)
1260                {
1261                    setup_item_i += (setup_n < setup_h) ? setup_n - setup_cursor : setup_h - setup_cursor - 1;
1262                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
1263                }
1264                else
1265                {
1266                    if (setup_item_i < setup_n - setup_h + 1)
1267                    {
1268                        setup_item_i += setup_h;
1269                        setup_item_p += setup_h;
1270                    }
1271                else
1272                    {
1273                        setup_item_i = setup_n;
1274                        setup_item_p = setup_n - setup_h + 1;
1275                    }
1276                }
1277            }
1278        }
1279    }
1280    if (Input::WasPressed(Key::Left))
1281    {
1282        if (g_setup && setup_switch)
1283        {
1284            theme_var[theme_var_key] -= setup_conf[setup_item_key].z;
1285            if (theme_var[theme_var_key] < setup_conf[setup_item_key].x) theme_var[theme_var_key] = setup_conf[setup_item_key].x;
1286            InitShaderVar();
1287            UpdateSize();
1288        }
1289    }
1290    if (Input::WasPressed(Key::Right))
1291    {
1292        if (g_setup && setup_switch)
1293        {
1294            theme_var[theme_var_key] += setup_conf[setup_item_key].z;
1295            if (theme_var[theme_var_key] > setup_conf[setup_item_key].y) theme_var[theme_var_key] = setup_conf[setup_item_key].y;
1296            InitShaderVar();
1297            UpdateSize();
1298        }
1299    }
1300    if (Input::WasPressed(Key::Home))
1301    {
1302        if (g_setup && setup_switch)
1303        {
1304            theme_var[theme_var_key] = setup_conf[setup_item_key].x;
1305            InitShaderVar();
1306            UpdateSize();
1307        }
1308    }
1309    if (Input::WasPressed(Key::End))
1310    {
1311        if (g_setup && setup_switch)
1312        {
1313            theme_var[theme_var_key] = setup_conf[setup_item_key].y;
1314            InitShaderVar();
1315            UpdateSize();
1316        }
1317    }
1318    if (Input::WasPressed(Key::Return))
1319    {
1320        beat_flag = true;
1321        beat_angle = main_angle;
1322        //flash_flag = true;
1323        //flash_angle = main_angle;
1324    }
1325
1326    Entity::TickDraw(seconds);
1327
1328    if (!m_ready)
1329    {
1330        CreateGLWindow();
1331        m_txt_screen->Init();
1332        m_txt_setup->Init();
1333        m_ready = true;
1334    }
1335
1336    // timer
1337    if (!m_pause)
1338    {
1339        timer += seconds;
1340        main_angle = timer * 100.0f * PID;
1341    }
1342    if (sync_flag)
1343    {
1344        angle = (main_angle - sync_angle) * sync_speed;
1345        sync_value = 1.0f - sinf(angle);
1346        if (angle > 90.0f * PID)
1347        {
1348            sync_value = 0;
1349            sync_flag = false;
1350        }
1351    }
1352    if (beat_flag)
1353    {
1354        angle = (main_angle - beat_angle) * beat_speed;
1355        beat_value = 1.0f - sinf(angle);
1356        if (angle > 90.0f * PID)
1357        {
1358            beat_value = 0;
1359            beat_flag = false;
1360        }
1361    }
1362    if (flash_flag)
1363    {
1364        angle = (main_angle - flash_angle) * flash_speed;
1365        flash_value = 1.0f - sinf(angle);
1366        if (angle > 90.0f * PID)
1367        {
1368            flash_value = 0;
1369            flash_flag = false;
1370        }
1371    }
1372    if (fade_flag)
1373    {
1374        angle = (main_angle - fade_angle) * fade_speed;
1375        fade_value = 1.0f - sinf(angle);
1376        if (angle > 90.0f * PID)
1377        {
1378            fade_value = 0;
1379            fade_flag = false;
1380        }
1381    }
1382
1383    Draw2D();
1384    Draw3D();
1385}
1386
1387void Render::Draw2D()
1388{
1389    /* Draw text in an offline buffer */
1390    m_txt_screen->Render();
1391
1392    if (g_setup)
1393        m_txt_setup->Render();
1394
1395    if (m_shader)
1396        fbo_back->Bind();
1397
1398    glViewport(0, 0, screen_size.x, screen_size.y);
1399
1400    /* Clear the back buffer */
1401    glEnable(GL_TEXTURE_2D);
1402    glEnable(GL_BLEND);
1403    glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA);
1404
1405    Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
1406    Video::SetClearDepth(1.0f); // set depth buffer
1407    Video::Clear(ClearMask::Color | ClearMask::Depth);
1408
1409    m_txt_screen->Blit(border, canvas_size);
1410    if (g_setup)
1411        m_txt_setup->Blit((screen_size - setup_canvas_size) / 2, setup_canvas_size);
1412
1413    glMatrixMode(GL_PROJECTION);
1414    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
1415    glLoadMatrixf(&m[0][0]);
1416    glMatrixMode(GL_MODELVIEW);
1417
1418    fx_angle=main_angle-part_angle;
1419}
1420
1421void Render::Draw3D()
1422{
1423    if (!m_shader)
1424        return;
1425
1426    glDisable(GL_DEPTH_TEST);
1427    glDisable(GL_BLEND);
1428
1429    glEnableClientState(GL_VERTEX_ARRAY);
1430    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
1431
1432    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1433    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
1434
1435    if (m_shader_copper)
1436    {
1437        // shader copper
1438        fbo_tmp->Bind();
1439        shader_copper->Bind();
1440        shader_copper->SetUniform(shader_copper_texture, fbo_back->GetTexture(), 0);
1441        shader_copper->SetUniform(shader_copper_screen_size, (vec2)screen_size);
1442        shader_copper->SetUniform(shader_copper_time, fx_angle);
1443        shader_copper->SetUniform(shader_copper_copper, vec4(copper_copper.x, copper_copper.y, copper_copper.z * 16.0f, copper_copper.w * 16.0f));
1444        shader_copper->SetUniform(shader_copper_mask_color, copper_mask_color / 4.0f);
1445        TraceQuad();
1446        shader_color->Unbind();
1447        fbo_tmp->Unbind();
1448        // shader simple
1449        fbo_back->Bind();
1450        ShaderSimple(fbo_tmp, 0);
1451        fbo_back->Unbind();
1452    }
1453
1454    if (m_shader_remanence)
1455    {
1456        // shader remanence
1457        fbo_tmp->Bind();
1458        shader_remanence->Bind();
1459        shader_remanence->SetUniform(shader_remanence_source, fbo_back->GetTexture(), 0);
1460        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1461        shader_remanence->SetUniform(shader_remanence_mix, remanence);
1462        TraceQuad();
1463        shader_remanence->Unbind();
1464        fbo_tmp->Unbind();
1465        // shader simple
1466        fbo_back->Bind();
1467        ShaderSimple(fbo_tmp, 0);
1468        fbo_back->Unbind();
1469        // save previous fbo
1470        fbo_tmp->Bind();
1471        shader_remanence->Bind();
1472        shader_remanence->SetUniform(shader_remanence_source, fbo_screen->GetTexture(), 0);
1473        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1474        shader_remanence->SetUniform(shader_remanence_mix, buffer);
1475        TraceQuad();
1476        shader_remanence->Unbind();
1477        fbo_tmp->Unbind();
1478        // shader simple
1479        fbo_buffer->Bind();
1480        ShaderSimple(fbo_tmp, 0);
1481        fbo_buffer->Unbind();
1482    }
1483
1484    // shader glow
1485    if (m_shader_glow)
1486    {
1487        // shader blur horizontal
1488        fbo_blur_h->Bind();
1489        shader_blur_h->Bind();
1490        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_back->GetTexture(), 0);
1491        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
1492        TraceQuad();
1493        shader_blur_h->Unbind();
1494        fbo_blur_h->Unbind();
1495        // shader blur vertical
1496        fbo_blur_v->Bind();
1497        shader_blur_v->Bind();
1498        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1499        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
1500        TraceQuad();
1501        shader_blur_v->Unbind();
1502        fbo_blur_v->Unbind();
1503        // shader blur horizontal
1504        fbo_blur_h->Bind();
1505        shader_blur_h->Bind();
1506        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
1507        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
1508        TraceQuad();
1509        shader_blur_h->Unbind();
1510        fbo_blur_h->Unbind();
1511        // shader blur vertical
1512        fbo_blur_v->Bind();
1513        shader_blur_v->Bind();
1514        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1515        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
1516        TraceQuad();
1517        shader_blur_v->Unbind();
1518        fbo_blur_v->Unbind();
1519        // shader glow
1520        fbo_screen->Bind();
1521        shader_glow->Bind();
1522        shader_glow->SetUniform(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
1523        shader_glow->SetUniform(shader_glow_source, fbo_back->GetTexture(), 1);
1524        shader_glow->SetUniform(shader_glow_mix, glow_mix);
1525        TraceQuad();
1526        shader_glow->Unbind();
1527        fbo_screen->Unbind();
1528    }
1529    else
1530    {
1531        // shader simple
1532        fbo_screen->Bind();
1533        ShaderSimple(fbo_back, 0);
1534        fbo_screen->Unbind();
1535    }
1536
1537    if (m_shader_color)
1538    {
1539        // shader color
1540        fbo_tmp->Bind();
1541        shader_color->Bind();
1542        shader_color->SetUniform(shader_color_texture, fbo_screen->GetTexture(), 0);
1543        shader_color->SetUniform(shader_color_screen_size, (vec2)screen_size);
1544        shader_color->SetUniform(shader_color_filter, color_filter);
1545        shader_color->SetUniform(shader_color_color, color_color);
1546        shader_color->SetUniform(shader_color_flash, flash_value);
1547        TraceQuad();
1548        shader_color->Unbind();
1549        fbo_tmp->Unbind();
1550        // shader simple
1551        fbo_screen->Bind();
1552        ShaderSimple(fbo_tmp, 0);
1553        fbo_screen->Unbind();
1554    }
1555
1556    if (m_shader_noise)
1557    {
1558        // shader noise
1559        fbo_tmp->Bind();
1560        shader_noise->Bind();
1561        shader_noise->SetUniform(shader_noise_texture, fbo_screen->GetTexture(), 0);
1562        shader_noise->SetUniform(shader_noise_screen_size, (vec2)screen_size);
1563        shader_noise->SetUniform(shader_noise_time, fx_angle);
1564        shader_noise->SetUniform(shader_noise_offset, noise_offset);
1565        shader_noise->SetUniform(shader_noise_noise, noise_noise);
1566        shader_noise->SetUniform(shader_noise_retrace, noise_retrace);
1567        TraceQuad();
1568        shader_noise->Unbind();
1569        fbo_tmp->Unbind();
1570        // shader simple
1571        fbo_screen->Bind();
1572        ShaderSimple(fbo_tmp, 0);
1573        fbo_screen->Unbind();
1574    }
1575
1576    if (m_shader_blur)
1577    {
1578        // shader blur horizontal
1579        fbo_tmp->Bind();
1580        shader_blur_h->Bind();
1581        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_screen->GetTexture(), 0);
1582        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
1583        TraceQuad();
1584        shader_blur_h->Unbind();
1585        fbo_tmp->Unbind();
1586        // shader blur vertical
1587        fbo_screen->Bind();
1588        shader_blur_v->Bind();
1589        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_tmp->GetTexture(), 0);
1590        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
1591        TraceQuad();
1592        shader_blur_v->Unbind();
1593        fbo_screen->Unbind();
1594    }
1595
1596    if (m_shader_postfx)
1597    {
1598        // shader postfx
1599        fbo_front->Bind();
1600        shader_postfx->Bind();
1601        shader_postfx->SetUniform(shader_postfx_texture, fbo_screen->GetTexture(), 0);
1602        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
1603        shader_postfx->SetUniform(shader_postfx_ratio_2d, (vec2)ratio_2d / 2);
1604        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
1605        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
1606        shader_postfx->SetUniform(shader_postfx_ghost1, vec4(postfx_ghost1.xyz * 0.01, postfx_ghost1.w));
1607        shader_postfx->SetUniform(shader_postfx_ghost2, vec4(postfx_ghost2.xyz * 0.01, postfx_ghost2.w));
1608        shader_postfx->SetUniform(shader_postfx_glass, vec4(postfx_glass.xy * 0.01, postfx_glass.z * 0.1, postfx_glass.w));
1609        shader_postfx->SetUniform(shader_postfx_gradient, postfx_gradient);
1610        shader_postfx->SetUniform(shader_postfx_gradient_color, postfx_gradient_color);
1611        shader_postfx->SetUniform(shader_postfx_vignetting, postfx_vignetting);
1612        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
1613        shader_postfx->SetUniform(shader_postfx_moire_h, vec4(postfx_moire_h.xyz, postfx_moire_h.w * 2 * M_PI));
1614        shader_postfx->SetUniform(shader_postfx_moire_v, vec4(postfx_moire_v.xyz, postfx_moire_v.w * 2 * M_PI));
1615        shader_postfx->SetUniform(shader_postfx_scanline_h, vec4(postfx_scanline_h.xyz, postfx_scanline_h.w * 2 * M_PI));
1616        shader_postfx->SetUniform(shader_postfx_scanline_v, vec4(postfx_scanline_v.xyz, postfx_scanline_v.w * 2 * M_PI));
1617        shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
1618        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(sync_value * cosf((main_angle - sync_angle) * 6.0f)));
1619        shader_postfx->SetUniform(shader_postfx_beat, (float)fabs(beat_value * cosf((main_angle - beat_angle) * 6.0f)));
1620        TraceQuad();
1621        shader_postfx->Unbind();
1622        fbo_front->Unbind();
1623    }
1624    else
1625    {
1626        // shader simple
1627        fbo_front->Bind();
1628        ShaderSimple(fbo_screen, 0);
1629        fbo_front->Unbind();
1630    }
1631
1632    if (m_shader_mirror)
1633    {
1634        // shader mirror
1635        fbo_tmp->Bind();
1636        shader_mirror->Bind();
1637        shader_mirror->SetUniform(shader_mirror_texture, fbo_front->GetTexture(), 0);
1638        shader_mirror->SetUniform(shader_mirror_screen_size, (vec2)screen_size);
1639        shader_mirror->SetUniform(shader_mirror_mirror, vec4(mirror.x * 0.1f, mirror.y * 0.1f, mirror.z, mirror.w));
1640        TraceQuad();
1641        shader_mirror->Unbind();
1642        fbo_tmp->Unbind();
1643        // shader simple
1644        fbo_front->Bind();
1645        ShaderSimple(fbo_tmp, 0);
1646        fbo_front->Unbind();
1647    }
1648
1649    if (m_shader_radial)
1650    {
1651        // shader radial blur
1652        fbo_tmp->Bind();
1653        shader_radial->Bind();
1654        shader_radial->SetUniform(shader_radial_texture, fbo_front->GetTexture(), 0);
1655        shader_radial->SetUniform(shader_radial_screen_size, (vec2)screen_size);
1656        shader_radial->SetUniform(shader_radial_radial, vec4(radial.x, radial.y, radial.z, radial.w * 0.1f));
1657        TraceQuad();
1658        shader_radial->Unbind();
1659        fbo_tmp->Unbind();
1660        // shader simple
1661        fbo_front->Bind();
1662        ShaderSimple(fbo_tmp, 0);
1663        fbo_front->Unbind();
1664    }
1665
1666    // shader simple
1667    ShaderSimple(fbo_front, 0);
1668
1669    glDisableClientState(GL_VERTEX_ARRAY);
1670    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1671}
1672
1673Render::~Render()
1674{
1675    if (m_fps_debug)
1676        Ticker::Unref(m_fps_debug);
1677}
Note: See TracBrowser for help on using the repository browser.