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

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

neercs - adding mirror sides (left ok, right no yet)

File size: 45.9 KB
Line 
1//
2// Neercs
3//
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#if defined _XBOX
10#   define _USE_MATH_DEFINES /* for M_PI */
11#   include <xtl.h>
12#elif defined _WIN32
13#   define _USE_MATH_DEFINES /* for M_PI */
14#   define WIN32_LEAN_AND_MEAN
15#   include <windows.h>
16#endif
17
18#include <cmath>
19#include <cstdio>
20#include <cstdlib>
21#include <ctime>
22#include <string>
23
24#include "core.h"
25#include "lolgl.h"
26
27using namespace std;
28using namespace lol;
29
30#include "../neercs.h"
31#include "render.h"
32#include "text-render.h"
33
34extern char const *lolfx_simple;
35extern char const *lolfx_blurh;
36extern char const *lolfx_blurv;
37extern char const *lolfx_glow;
38extern char const *lolfx_remanence;
39extern char const *lolfx_copper;
40extern char const *lolfx_color;
41extern char const *lolfx_noise;
42extern char const *lolfx_postfx;
43extern char const *lolfx_mirror;
44
45#define PID M_PI/180.0f    // pi ratio
46
47/*
48 * Global variable -- ugly
49 */
50bool g_setup = true;
51
52/*
53 * Various variables
54 */
55
56int active = true;         // window active flag
57float nearplane = 0.1f;    // nearplane
58float farplane = 1000.0f;  // farplane
59int polygon_fillmode = GL_FILL; // fill mode
60/* timer variable */
61float timer = 0;           // timer
62/* window variable */
63ivec2 screen_size;         // screen size
64vec3 screen_color = vec3(0.125f, 0.125f, 0.125f); // screen color
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/* shader variable */
95vec2 buffer(0.7f,0.3f);         // [new frame mix,old frame mix]
96vec2 remanence(0.6f,0.4f);      // remanence [source mix,buffer mix]
97vec2 glow_mix(0.7f,0.3f);       // glow mix [source mix,glow mix]
98vec2 glow_large(3.0f,0.0f);     // large glow radius [center,corner]
99vec2 glow_small(1.5f,0.0f);     // small glow radius [center,corner]
100vec2 blur(0.5f,0.0f);           // blur radius [center,corner]
101vec4 copper_copper(0.75f,0.25f,0.42f,4.0f);     // copper [base,variable,repeat,color cycle]
102vec3 copper_mask_color(4.0f,4.0f,4.0f);         // color [red,green,blue]
103vec3 color_filter(0.9f,0.95f,0.85f);            // color filter [red,green,blue]
104vec4 color_color(1.5f,1.2f,0.1f,0.35f);         // color modifier [brightness,contrast,level,grayscale]
105vec2 noise_offset(2.0f,2.0f);                   // random line [horizontal,vertical]
106float noise_noise = 0.25f;                      // noise
107vec3 noise_retrace(1.0f,1.0f,0.5f);             // retrace [strength,length,speed]
108vec2 postfx_deform(0.8f,0.52f);                 // deformation [ratio,zoom]
109float postfx_vignetting = 0.5f;                 // vignetting strength
110float postfx_aberration = 4.0f;                 // chromatic aberration
111vec4 postfx_ghost1(1.0f,0.0f,0.0f,-0.25f);      // ghost picture 1 [position x,position y,position z,strength]
112vec4 postfx_ghost2(1.5f,0.0f,0.0f,0.25f);       // ghost picture 2 [position x,position y,position z,strength]
113vec4 postfx_moire_h(0.75f,-0.25f,0.0f,1.0f);    // vertical moire [base,variable,repeat,shift]
114vec4 postfx_moire_v(0.75f,-0.25f,1.0f,1.5f);    // horizontal moire [base,variable,repeat,shift]
115vec4 postfx_scanline_h(0.75f,0.0f,0.0f,0.0f);   // vertical scanline [base,variable,repeat,shift]
116vec4 postfx_scanline_v(0.75f,-0.25f,2.0f,0.0f); // horizontal scanline [base,variable,repeat,shift]
117vec3 postfx_corner(0.0f,0.75f,0.95f);           // corner [width,radius,blur]
118vec4 mirror(0.7f,0.7f,0.5f,4.0f);               // mirror [width,height,strength,ratio]
119/* text variable */
120ivec2 ratio_2d(2,3);            // 2d ratio
121ivec2 map_size(256,256);        // texture map size
122ivec2 font_size(8,8);           // font size
123ivec2 canvas_char(0,0);         // canvas char number
124ivec2 canvas_size(0,0);         // caca size
125/* window variable */
126ivec2 border = vec2(2,1) * ratio_2d * font_size; // border width
127/* setup variable */
128bool setup_switch = false;      // switch [option/item]
129int setup_n = 0;                // item/option number
130int setup_h = 8;                // height
131int setup_cursor = 0;           // cursor position
132int setup_option_i = 0;         // selected option
133int setup_option_n = 12;        // option number
134int setup_option_p = 0;         // option position
135int setup_item_i = 0;           // selected item
136int setup_item_n = 8;           // item number
137int setup_item_p = 0;           // item position
138int setup_item_key = 0;         // item array key
139ivec3 setup_size(29,9,12);      // size [w,h,split]
140ivec2 setup_canvas_size(ivec2(setup_size.x + 1, setup_size.y + 1) * font_size * ivec2(2,4));
141ivec2 setup_color(0xaaa,0x222); // color [foreground,background] 0x678,0x234
142char const *setup_text[] = {
143    "main",
144        "2d ratio w",
145        "2d ratio h",
146        "border w",
147        "border h",
148        "",
149        "",
150        "",
151        "",
152    "remanence",
153        "enable",
154        "buffer new frame",
155        "buffer old frame",
156        "source mix",
157        "buffer mix",
158        "",
159        "",
160        "",
161    "glow",
162        "enable",
163        "source mix",
164        "glow mix",
165        "large center",
166        "large corner",
167        "small center",
168        "small corner",
169        "",
170    "blur",
171        "enable",
172        "blur center",
173        "blur corner",
174        "",
175        "",
176        "",
177        "",
178        "",
179    "screen",
180        "enable",
181        "deform ratio",
182        "zoom base",
183        "corner width",
184        "corner radius",
185        "corner blur",
186        "vignetting",
187        "",
188    "copper",
189        "enable",
190        "base",
191        "variable",
192        "repeat",
193        "color cycle",
194        "color r",
195        "color g",
196        "color b",
197    "color",
198        "filter red",
199        "filter green",
200        "filter blue",
201        "brightness",
202        "contrast",
203        "level",
204        "grayscale",
205        "aberration",
206    "noise",
207        "enable",
208        "offset h",
209        "offset v",
210        "noise",
211        "retrace strength",
212        "retrace length",
213        "retrace speed",
214        "",
215    "ghost",
216        "back x",
217        "back y",
218        "back z",
219        "back strength",
220        "front x",
221        "front y",
222        "front z",
223        "front strength",
224    "moire",
225        "h base",
226        "h variable",
227        "h repeat",
228        "h shift",
229        "v base",
230        "v variable",
231        "v repeat",
232        "v shift",
233    "scanline",
234        "h base",
235        "h variable",
236        "h repeat",
237        "h shift",
238        "v base",
239        "v variable",
240        "v repeat",
241        "v shift",
242    "mirror",
243        "enable",
244        "width",
245        "height",
246        "strength",
247        "ratio",
248        "",
249        "",
250        ""
251    };
252
253vec4 setup_var[]={ // setup variable [start,end,step,value]
254    vec4(0), /* main */
255        vec4(1,  8, 1, ratio_2d.x),
256        vec4(1,  8, 1, ratio_2d.y),
257        vec4(0, 16, 1, border.x / ratio_2d.x / font_size.x),
258        vec4(0, 16, 1, border.y / ratio_2d.y / font_size.y),
259        vec4(0),
260        vec4(0),
261        vec4(0),
262        vec4(0),
263    vec4(0), /* remanence */
264        vec4(0, 1, 1, 1),
265        vec4(0.0f, 1.0f, 0.1f, buffer.x),
266        vec4(0.0f, 1.0f, 0.1f, buffer.y),
267        vec4(0.0f, 1.0f, 0.1f, remanence.x),
268        vec4(0.0f, 1.0f, 0.1f, remanence.y),
269        vec4(0),
270        vec4(0),
271        vec4(0),
272    vec4(0), /* glow */
273        vec4(0, 1, 1, 1),
274        vec4(0.0f, 1.0f, 0.1f, glow_mix.x),
275        vec4(0.0f, 1.0f, 0.1f, glow_mix.y),
276        vec4(0.0f, 4.0f, 0.1f, glow_large.x),
277        vec4(0.0f, 4.0f, 0.1f, glow_large.y),
278        vec4(0.0f, 2.0f, 0.1f, glow_small.x),
279        vec4(0.0f, 2.0f, 0.1f, glow_small.y),
280        vec4(0),
281    vec4(0), /* blur */
282        vec4(0, 1, 1, 1),
283        vec4(0, 2, 0.05f, blur.x),
284        vec4(0, 2, 0.05f, blur.y),
285        vec4(0),
286        vec4(0),
287        vec4(0),
288        vec4(0),
289        vec4(0),
290    vec4(0), /* screen */
291        vec4(0, 1, 1, 1),
292        vec4(0.0f, 1.0f, 0.05f, postfx_deform.x),
293        vec4(0.5f, 0.7f, 0.01f, postfx_deform.y),
294        vec4(0.0f, 4.0f, 0.10f, postfx_corner.x),
295        vec4(0.0f, 1.0f, 0.05f, postfx_corner.y),
296        vec4(0.0f, 1.0f, 0.05f, postfx_corner.z),
297        vec4(0.0f, 1.0f, 0.10f, postfx_vignetting),
298        vec4(0),
299    vec4(0), /* copper */
300        vec4(0, 1, 1, 1),
301        vec4(0.0f, 1.0f, 0.05f, copper_copper.x),
302        vec4(0.0f, 1.0f, 0.05f, copper_copper.y),
303        vec4(0.0f, 1.0f, 0.02f, copper_copper.z),
304        vec4(1.0f, 8.0f, 0.25f, copper_copper.w),
305        vec4(0.0f, 4.0f, 0.25f, copper_mask_color.x),
306        vec4(0.0f, 4.0f, 0.25f, copper_mask_color.y),
307        vec4(0.0f, 4.0f, 0.25f, copper_mask_color.z),
308    vec4(0), /* color */
309        vec4( 0.0f, 1.0f, 0.05f, color_filter.x),
310        vec4( 0.0f, 1.0f, 0.05f, color_filter.y),
311        vec4( 0.0f, 1.0f, 0.05f, color_filter.z),
312        vec4( 0.0f, 2.0f, 0.05f, color_color.x),
313        vec4( 0.0f, 2.0f, 0.05f, color_color.y),
314        vec4(-1.0f, 1.0f, 0.05f, color_color.z),
315        vec4( 0.0f, 1.0f, 0.05f, color_color.w),
316        vec4( 0.0f, 8.0f, 0.50f, postfx_aberration),
317    vec4(0), /* noise */
318        vec4(0, 1, 1, 1),
319        vec4(0.0f, 4.0f, 0.50f, noise_offset.x),
320        vec4(0.0f, 4.0f, 0.50f, noise_offset.y),
321        vec4(0.0f, 0.5f, 0.05f, noise_noise),
322        vec4(0.0f, 4.0f, 0.25f, noise_retrace.x),
323        vec4(0.0f, 8.0f, 0.50f, noise_retrace.y),
324        vec4(0.0f, 4.0f, 0.25f, noise_retrace.z),
325        vec4(0),
326    vec4(0), /* ghost */
327        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost1.x),
328        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost1.y),
329        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost1.z),
330        vec4(-1.0f, 1.0f, 0.05f, postfx_ghost1.w),
331        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost2.x),
332        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost2.y),
333        vec4(-2.0f, 2.0f, 0.10f, postfx_ghost2.z),
334        vec4(-1.0f, 1.0f, 0.05f, postfx_ghost2.w),
335    vec4(0), /* moire */
336        vec4( 0.5f, 1.0f, 0.05f, postfx_moire_h.x),
337        vec4(-0.5f, 0.5f, 0.05f, postfx_moire_h.y),
338        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_h.z),
339        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_h.w),
340        vec4( 0.5f, 1.0f, 0.05f, postfx_moire_v.x),
341        vec4(-0.5f, 0.5f, 0.05f, postfx_moire_v.y),
342        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_v.z),
343        vec4( 0.0f, 4.0f, 0.50f, postfx_moire_v.w),
344    vec4(0), /* scanline */
345        vec4( 0.5f, 1.0f, 0.05f, postfx_scanline_h.x),
346        vec4(-0.5f, 0.5f, 0.05f, postfx_scanline_h.y),
347        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_h.z),
348        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_h.w),
349        vec4( 0.5f, 1.0f, 0.05f, postfx_scanline_v.x),
350        vec4(-0.5f, 0.5f, 0.05f, postfx_scanline_v.y),
351        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_v.z),
352        vec4( 0.0f, 4.0f, 0.50f, postfx_scanline_v.w),
353    vec4(0), /* mirror */
354        vec4(0, 1, 1, 1),
355        vec4(0.0f, 2.0f, 0.05f, mirror.x),
356        vec4(0.0f, 2.0f, 0.05f, mirror.y),
357        vec4(0.0f, 1.0f, 0.05f, mirror.z),
358        vec4(1.0f, 4.0f, 0.25f, mirror.w),
359        vec4(0),
360        vec4(0),
361        vec4(0),
362    vec4(0) /* ? */
363    };
364
365void Render::UpdateVar()
366{
367    int k = 1; /* main */
368    ratio_2d = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
369    border = vec2(setup_var[k].w, setup_var[k + 1].w) * ratio_2d * font_size; k += 2;
370    k += 5; /* remanence */
371    m_shader_remanence = (setup_var[k].w == 1) ? true : false; k++;
372    buffer = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
373    remanence = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
374    k += 4; /* glow */
375    m_shader_glow = (setup_var[k].w == 1) ? true : false; k++;
376    glow_mix = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
377    glow_large = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
378    glow_small = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
379    k += 2; /* blur */
380    m_shader_blur = (setup_var[k].w == 1) ? true : false; k++;
381    blur = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
382    k += 6; /* screen */
383    m_shader_postfx = (setup_var[k].w == 1) ? true : false; k++;
384    postfx_deform = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
385    postfx_corner = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
386    postfx_vignetting = setup_var[k].w; k++;
387    k += 2; /* copper */
388    m_shader_copper = (setup_var[k].w == 1) ? true : false; k++;
389    copper_copper = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
390    copper_mask_color = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
391    k += 1; /* color */
392    color_filter = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
393    color_color = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
394    postfx_aberration = setup_var[k].w; k++;
395    k += 1; /* noise */
396    m_shader_noise = (setup_var[k].w == 1) ? true : false; k++;
397    noise_offset = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
398    noise_noise = setup_var[k].w; k++;
399    noise_retrace = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
400    k += 2; /* ghost */
401    postfx_ghost1 = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
402    postfx_ghost2 = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
403    k += 1; /* moire */
404    postfx_moire_h = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
405    postfx_moire_v = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
406    k += 1; /* scanline */
407    postfx_scanline_h = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
408    postfx_scanline_v = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
409    k += 1; /* mirror */
410    m_shader_mirror = (setup_var[k].w == 1) ? true : false; k++;
411    mirror = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
412    UpdateSize();
413}
414
415void Render::UpdateSize()
416{
417    screen_size = Video::GetSize();
418    canvas_char = (screen_size - border * 2) / (font_size * ratio_2d);
419    canvas_char = max(canvas_char, ivec2(1, 1));
420    canvas_size = canvas_char * font_size * ratio_2d;
421
422    border = (screen_size - canvas_size) / 2;
423
424    caca_set_canvas_size(m_cv_screen, canvas_char.x, canvas_char.y);
425    caca_set_canvas_size(m_cv_setup, setup_size.x + 1, setup_size.y + 1);
426}
427
428int calc_item_length()
429{
430    int n = !setup_switch ? setup_option_n : setup_item_n;
431    for (int i = 0; i < n; i++)
432    {
433        int k = !setup_switch ? (i * (setup_item_n + 1)) : (setup_option_i * (setup_item_n + 1) + 1 + i);
434        if (setup_text[k][0] == '\0') return i - 1;
435    }
436    return n - 1;
437}
438
439Shader *shader_simple;
440Shader *shader_blur_h, *shader_blur_v, *shader_glow;
441Shader *shader_remanence, *shader_copper, *shader_color;
442Shader *shader_noise, *shader_postfx, *shader_mirror;
443// shader variables
444ShaderUniform shader_simple_texture;
445ShaderUniform shader_blur_h_texture,
446              shader_blur_h_radius,
447              shader_blur_v_texture,
448              shader_blur_v_radius;
449ShaderUniform shader_glow_glow,
450              shader_glow_source,
451              shader_glow_mix;
452ShaderUniform shader_remanence_source,
453              shader_remanence_buffer,
454              shader_remanence_mix;
455ShaderUniform shader_copper_texture,
456              shader_copper_screen_size,
457              shader_copper_time,
458              shader_copper_copper,
459              shader_copper_mask_color;
460ShaderUniform shader_color_texture,
461              shader_color_screen_size,
462              shader_color_filter,
463              shader_color_color,
464              shader_color_flash;
465ShaderUniform shader_noise_texture,
466              shader_noise_screen_size,
467              shader_noise_time,
468              shader_noise_offset,
469              shader_noise_noise,
470              shader_noise_retrace;
471ShaderUniform shader_postfx_texture,
472              shader_postfx_texture_2d,
473              shader_postfx_screen_size,
474              shader_postfx_time,
475              shader_postfx_deform,
476              shader_postfx_ghost1,
477              shader_postfx_ghost2,
478              shader_postfx_vignetting,
479              shader_postfx_aberration,
480              shader_postfx_moire_h,
481              shader_postfx_moire_v,
482              shader_postfx_scanline_h,
483              shader_postfx_scanline_v,
484              shader_postfx_corner,
485              shader_postfx_sync,
486              shader_postfx_beat;
487ShaderUniform shader_mirror_texture,
488              shader_mirror_screen_size,
489              shader_mirror_mirror;
490
491FrameBuffer *fbo_back, *fbo_front, *fbo_screen;
492FrameBuffer *fbo_blur_h, *fbo_blur_v;
493FrameBuffer *fbo_tmp, *fbo_buffer;
494
495void Render::TraceQuad()
496{
497    glLoadIdentity();
498    glDrawArrays(GL_QUADS, 0, 4);
499}
500
501void Render::ShaderSimple(FrameBuffer *fbo_output, int n)
502{
503    shader_simple->Bind();
504    shader_simple->SetUniform(shader_simple_texture, fbo_output->GetTexture(), n);
505    TraceQuad();
506    shader_simple->Unbind();
507}
508
509int Render::InitDraw(void)
510{
511    glDepthMask(GL_TRUE);     // do not write z-buffer
512    glEnable(GL_CULL_FACE);   // disable cull face
513    glCullFace(GL_BACK);      // don't draw front face
514
515    /* initialise framebuffer objects */
516    fbo_back = new FrameBuffer(screen_size);
517    fbo_screen = new FrameBuffer(screen_size);
518    fbo_front = new FrameBuffer(screen_size);
519    fbo_buffer = new FrameBuffer(screen_size);
520    fbo_blur_h = new FrameBuffer(screen_size);
521    fbo_blur_v = new FrameBuffer(screen_size);
522    fbo_tmp = new FrameBuffer(screen_size);
523    // shader simple
524    shader_simple = Shader::Create(lolfx_simple);
525    shader_simple_texture = shader_simple->GetUniformLocation("texture");
526    // shader glow
527    shader_glow = Shader::Create(lolfx_glow);
528    shader_glow_glow = shader_glow->GetUniformLocation("glow");
529    shader_glow_source = shader_glow->GetUniformLocation("source");
530    shader_glow_mix = shader_glow->GetUniformLocation("mix");
531    // shader blur horizontal
532    shader_blur_h = Shader::Create(lolfx_blurh);
533    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
534    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
535    // shader blur vertical
536    shader_blur_v = Shader::Create(lolfx_blurv);
537    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
538    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
539    // shader remanence
540    shader_remanence = Shader::Create(lolfx_remanence);
541    shader_remanence_source = shader_remanence->GetUniformLocation("source");
542    shader_remanence_buffer = shader_remanence->GetUniformLocation("buffer");
543    shader_remanence_mix = shader_remanence->GetUniformLocation("mix");
544    // shader copper
545    shader_copper = Shader::Create(lolfx_copper);
546    shader_copper_texture = shader_copper->GetUniformLocation("texture");
547    shader_copper_screen_size = shader_copper->GetUniformLocation("screen_size");
548    shader_copper_time = shader_copper->GetUniformLocation("time");
549    shader_copper_copper = shader_copper->GetUniformLocation("copper");
550    shader_copper_mask_color = shader_copper->GetUniformLocation("mask_color");
551    // shader color
552    shader_color = Shader::Create(lolfx_color);
553    shader_color_texture = shader_color->GetUniformLocation("texture");
554    shader_color_screen_size = shader_color->GetUniformLocation("screen_size");
555    shader_color_filter = shader_color->GetUniformLocation("filter");
556    shader_color_color = shader_color->GetUniformLocation("color");
557    shader_color_flash = shader_color->GetUniformLocation("flash");
558    // shader noise
559    shader_noise = Shader::Create(lolfx_noise);
560    shader_noise_texture = shader_noise->GetUniformLocation("texture");
561    shader_noise_screen_size = shader_noise->GetUniformLocation("screen_size");
562    shader_noise_time = shader_noise->GetUniformLocation("time");
563    shader_noise_offset = shader_noise->GetUniformLocation("offset");
564    shader_noise_noise = shader_noise->GetUniformLocation("noise");
565    shader_noise_retrace = shader_noise->GetUniformLocation("retrace");
566    // shader postfx
567    shader_postfx = Shader::Create(lolfx_postfx);
568    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
569    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
570    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
571    shader_postfx_time = shader_postfx->GetUniformLocation("time");
572    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
573    shader_postfx_ghost1 = shader_postfx->GetUniformLocation("ghost1");
574    shader_postfx_ghost2 = shader_postfx->GetUniformLocation("ghost2");
575    shader_postfx_vignetting = shader_postfx->GetUniformLocation("vignetting");
576    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
577    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
578    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
579    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
580    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
581    shader_postfx_corner = shader_postfx->GetUniformLocation("corner");
582    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
583    shader_postfx_beat = shader_postfx->GetUniformLocation("beat");
584    // shader mirror
585    shader_mirror = Shader::Create(lolfx_mirror);
586    shader_mirror_texture = shader_mirror->GetUniformLocation("texture");
587    shader_mirror_screen_size = shader_mirror->GetUniformLocation("screen_size");
588    shader_mirror_mirror = shader_mirror->GetUniformLocation("mirror");
589    // initialize setup
590    setup_n = calc_item_length();
591    return true;
592}
593
594int Render::CreateGLWindow()
595{
596    UpdateSize();
597    InitDraw();
598    return true;
599}
600
601Render::Render(caca_canvas_t *caca)
602  : m_cv_screen(caca),
603    m_cv_setup(caca_create_canvas(1, 1)),
604    m_ready(false),
605    m_pause(false),
606    m_polygon(true),
607    m_shader(true),
608    m_shader_glow(true),
609    m_shader_blur(true),
610    m_shader_remanence(true),
611    m_shader_copper(true),
612    m_shader_color(true),
613    m_shader_noise(true),
614    m_shader_postfx(true),
615    m_shader_mirror(true)
616{
617    m_txt_screen = new TextRender(m_cv_screen, font_size);
618    m_txt_setup = new TextRender(m_cv_setup, font_size);
619}
620
621void Render::TickGame(float seconds)
622{
623    Entity::TickGame(seconds);
624
625    /* draw LOLCUBE */
626    /*
627    caca_set_color_argb(m_cv_screen, 0xfff, 0x000);
628    caca_put_str(m_cv_screen, canvas_char.x -  8, canvas_char.y - 6, "_______");
629    caca_put_str(m_cv_screen, canvas_char.x -  9, canvas_char.y - 5, "/      /|");
630    caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 4, "/______/ |");
631    caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 3, "|      | |");
632    caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 2, "|  :D  | /");
633    caca_put_str(m_cv_screen, canvas_char.x - 10, canvas_char.y - 1, "|______|/");
634    */
635
636    /* draw setup */
637    if (g_setup)
638    {
639        /* background */
640        caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
641        caca_fill_box(m_cv_setup, 0, 0, setup_size.x + 1, setup_size.y,' ');
642        caca_draw_line(m_cv_setup, setup_size.z - 1, 1, setup_size.z - 1, setup_size.y - 1,'|');
643        /* title */
644        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
645        caca_draw_line(m_cv_setup, 0, 0, setup_size.x, 0, ' ');
646        caca_put_str(m_cv_setup, setup_size.x / 2 - 3, 0, "SETUP");
647        /* informations */
648        int w = caca_get_canvas_width(m_cv_screen);
649        int h = caca_get_canvas_height(m_cv_screen);
650        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
651        caca_printf(m_cv_setup, 1, 0, "%i*%i", w, h);
652        /* display option */
653        for (int i = 0; i < setup_h; i++)
654        {
655            int y = 1 + i;
656            int k = (setup_option_p + i) * (setup_item_n + 1);
657            if (setup_option_i != setup_option_p + i || setup_switch)
658            {
659                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
660                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
661            }
662            else
663            {
664                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
665                caca_draw_line(m_cv_setup, 0, y, setup_size.z - 2, y,' ');
666                caca_put_str(m_cv_setup, 1, y, setup_text[k]);
667            }
668        }
669        /* display item */
670        for (int i = 0; i < setup_h; i++)
671        {
672            int y = 1 + i;
673            int k = setup_option_i * (setup_item_n + 1) + 1 + setup_item_p + i;
674            if (setup_item_i != setup_item_p + i || !setup_switch)
675            {
676                caca_set_color_argb(m_cv_setup, setup_color.x, setup_color.y);
677                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
678            }
679            else
680            {
681                caca_set_color_argb(m_cv_setup, setup_color.y, 0xfff);//setup_color.x);
682                caca_draw_line(m_cv_setup, setup_size.z, y, setup_size.x, y,' ');
683                caca_put_str(m_cv_setup, setup_size.z + 1, y, setup_text[k]);
684            }
685        }
686        /* display variable */
687        int y = setup_size.y;
688        setup_item_key = setup_option_i * (setup_item_n + 1) + 1 + setup_item_i;
689        caca_set_color_argb(m_cv_setup, setup_color.y, setup_color.x);
690        caca_draw_line(m_cv_setup, 0, y, setup_size.x, y,' ');
691        if (setup_switch)
692        {
693            int x = 1;
694            int w = setup_size.x - 3 - 4;
695            float bar_w = w / (setup_var[setup_item_key].y - setup_var[setup_item_key].x);
696            int bar_x = bar_w * setup_var[setup_item_key].x;
697            if ((setup_var[setup_item_key].y - setup_var[setup_item_key].x) / setup_var[setup_item_key].z > 1)
698            {
699                /* Work around a bug in libcaca */
700                if (setup_size.x - 4 < caca_get_canvas_width(m_cv_setup)) caca_printf(m_cv_setup, setup_size.x - 4, y, "%4.2f", setup_var[setup_item_key].w);
701                caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * setup_var[setup_item_key].y), y,'.');
702                if (setup_var[setup_item_key].w != setup_var[setup_item_key].x) caca_draw_line(m_cv_setup, x, y, x - bar_x + int(bar_w * setup_var[setup_item_key].w), y, 'x');
703            }
704            else
705            {
706                if (setup_var[setup_item_key] != vec4(0))
707                {
708                    caca_put_str(m_cv_setup, setup_size.x - 3, y, (setup_var[setup_item_key].w == setup_var[setup_item_key].y)?"YES":" NO");
709                }
710            }
711        }
712        else
713        {
714            caca_printf(m_cv_setup, 1, y, "%d/%d", setup_option_i, setup_n);
715        }
716    }
717
718}
719
720void Render::Pause()
721{
722    m_pause=!m_pause;
723}
724
725void Render::TickDraw(float seconds)
726{
727    /* keyboard manager */
728    if (Input::WasReleased(Key::Escape))
729    {
730        Ticker::Shutdown();
731    }
732    if (Input::WasPressed(Key::F1))
733    {
734        g_setup = !g_setup;
735        if (g_setup) setup_n = calc_item_length();
736        sync_flag = true;
737        sync_angle = main_angle;
738    }
739    if (Input::WasPressed(Key::F2))
740    {
741        m_shader_glow = !m_shader_glow;
742        m_shader_blur = !m_shader_blur;
743        m_shader_remanence = !m_shader_remanence;
744        //m_shader_copper = !m_shader_copper;
745        m_shader_color = !m_shader_color;
746        m_shader_noise = !m_shader_noise;
747        m_shader_postfx = !m_shader_postfx;
748        m_shader_mirror = !m_shader_mirror;
749        //m_polygon = !m_polygon;
750        //polygon_fillmode = (m_polygon)?GL_FILL:GL_LINE;
751        //glPolygonMode(GL_FRONT, polygon_fillmode);
752    }
753   if (Input::WasPressed(Key::Tab))
754    {
755        if (g_setup)
756        {
757            setup_switch = !setup_switch;
758            setup_n = calc_item_length();
759            setup_cursor = (!setup_switch?setup_option_i:setup_item_i) - (!setup_switch?setup_option_p:setup_item_p);
760        }
761    }
762    if (Input::WasPressed(Key::Up))
763    {
764        if (g_setup)
765        {
766            if (!setup_switch)
767            {
768                if (setup_cursor > 0)
769                {
770                    setup_cursor--;
771                }
772                else
773                {
774                    if (setup_cursor == 0) setup_option_p--;
775                }
776                if (setup_option_i > 0)
777                {
778                    setup_option_i--;
779                }
780                else
781                {
782                    setup_option_i = setup_option_n - 1;
783                    setup_option_p = setup_option_n - setup_h;
784                    setup_cursor = setup_h - 1;
785                }
786                setup_item_i = 0;
787                setup_item_p = 0;
788            }
789            else
790            {
791                if (setup_cursor > 0)
792                {
793                    setup_cursor--;
794                }
795                else
796                {
797                    if (setup_cursor == 0) setup_item_p--;
798                }
799                if (setup_item_i > 0)
800                {
801                    setup_item_i--;
802                }
803                else
804                {
805                    setup_item_i = setup_n;
806                    setup_item_p = (setup_n < setup_h) ? 0 : setup_n - setup_h + 1;
807                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
808                }
809            }
810        }
811    }
812    if (Input::WasPressed(Key::Down))
813    {
814        if (g_setup)
815        {
816            if (!setup_switch)
817            {
818                if (setup_cursor < setup_h - 1)
819                {
820                    setup_cursor++;
821                }
822                else
823                {
824                    if (setup_cursor == setup_h - 1) setup_option_p++;
825                }
826                if (setup_option_i < setup_option_n - 1)
827                {
828                    setup_option_i++;
829                }
830                else
831                {
832                    setup_option_i = 0;
833                    setup_option_p = 0;
834                    setup_cursor = 0;
835                }
836                setup_item_i = 0;
837                setup_item_p = 0;
838            }
839            else
840            {
841                if (setup_cursor < setup_h - 1)
842                {
843                    setup_cursor++;
844                }
845                else
846                {
847                    if (setup_cursor == setup_h - 1) setup_item_p++;
848                }
849                if (setup_item_i < setup_n)
850                {
851                    setup_item_i++;
852                }
853                else
854                {
855                    setup_item_i = 0;
856                    setup_item_p = 0;
857                    setup_cursor = 0;
858                }
859            }
860        }
861    }
862    if (Input::WasPressed(Key::PageUp))
863    {
864        if (g_setup)
865        {
866            if (!setup_switch)
867            {
868                if (setup_cursor > 0)
869                {
870                    setup_option_i -= setup_cursor;
871                    setup_cursor = 0;
872                }
873                else
874                {
875                    if (setup_option_i > setup_h)
876                    {
877                        setup_option_i -= setup_h;
878                        setup_option_p -= setup_h;
879                    }
880                else
881                    {
882                        setup_option_i = 0;
883                        setup_option_p = 0;
884                    }
885                }
886            setup_item_i = 0;
887            }
888            else
889            {
890                if (setup_cursor > 0)
891                {
892                    setup_item_i -= setup_cursor;
893                    setup_cursor = 0;
894                }
895                else
896                {
897                    if (setup_item_i > setup_h)
898                    {
899                        setup_item_i -= setup_h;
900                        setup_item_p -= setup_h;
901                    }
902                else
903                    {
904                        setup_item_i = 0;
905                        setup_item_p = 0;
906                    }
907                }
908            }
909        }
910    }
911    if (Input::WasPressed(Key::PageDown))
912    {
913        if (g_setup)
914        {
915            if (!setup_switch)
916            {
917                if (setup_cursor < setup_h - 1)
918                {
919                    setup_option_i += setup_h - setup_cursor - 1;
920                    setup_cursor = setup_h - 1;
921                    setup_item_i = 0;
922                }
923                else
924                {
925                    if (setup_option_i < setup_option_n - setup_h - 1)
926                    {
927                        setup_option_i += setup_h;
928                        setup_option_p += setup_h;
929                    }
930                else
931                    {
932                        setup_option_i = setup_option_n - 1;
933                        setup_option_p = setup_option_n - setup_h;
934                    }
935                }
936            }
937            else
938            {
939                if (setup_cursor < setup_h - 1)
940                {
941                    setup_item_i += (setup_n < setup_h) ? setup_n - setup_cursor : setup_h - setup_cursor - 1;
942                    setup_cursor = (setup_n < setup_h) ? setup_n : setup_h - 1;
943                }
944                else
945                {
946                    if (setup_item_i < setup_n - setup_h + 1)
947                    {
948                        setup_item_i += setup_h;
949                        setup_item_p += setup_h;
950                    }
951                else
952                    {
953                        setup_item_i = setup_n;
954                        setup_item_p = setup_n - setup_h + 1;
955                    }
956                }
957            }
958        }
959    }
960    if (Input::WasPressed(Key::Left))
961    {
962        if (g_setup && setup_switch)
963        {
964            setup_var[setup_item_key].w -= setup_var[setup_item_key].z;
965            if (setup_var[setup_item_key].w < setup_var[setup_item_key].x) setup_var[setup_item_key].w = setup_var[setup_item_key].x;
966            UpdateVar();
967        }
968    }
969    if (Input::WasPressed(Key::Right))
970    {
971        if (g_setup && setup_switch)
972        {
973            setup_var[setup_item_key].w += setup_var[setup_item_key].z;
974            if (setup_var[setup_item_key].w > setup_var[setup_item_key].y) setup_var[setup_item_key].w = setup_var[setup_item_key].y;
975            UpdateVar();
976        }
977    }
978    if (Input::WasPressed(Key::Home))
979    {
980        if (g_setup && setup_switch)
981        {
982            setup_var[setup_item_key].w = setup_var[setup_item_key].x;
983            UpdateVar();
984        }
985    }
986    if (Input::WasPressed(Key::End))
987    {
988        if (g_setup && setup_switch)
989        {
990            setup_var[setup_item_key].w = setup_var[setup_item_key].y;
991            UpdateVar();
992        }
993    }
994    if (Input::WasPressed(Key::Return))
995    {
996        beat_flag = true;
997        beat_angle = main_angle;
998        //flash_flag = true;
999        //flash_angle = main_angle;
1000    }
1001
1002    Entity::TickDraw(seconds);
1003
1004    if (!m_ready)
1005    {
1006        CreateGLWindow();
1007        m_txt_screen->Init();
1008        m_txt_setup->Init();
1009        m_ready = true;
1010    }
1011
1012    // timer
1013    if (!m_pause)
1014    {
1015        timer += seconds;
1016        main_angle = timer * 100.0f * PID;
1017    }
1018    if (sync_flag)
1019    {
1020        angle = (main_angle - sync_angle) * sync_speed;
1021        sync_value = 1.0f - sinf(angle);
1022        if (angle > 90.0f * PID)
1023        {
1024            sync_value = 0;
1025            sync_flag = false;
1026        }
1027    }
1028    if (beat_flag)
1029    {
1030        angle = (main_angle - beat_angle) * beat_speed;
1031        beat_value = 1.0f - sinf(angle);
1032        if (angle > 90.0f * PID)
1033        {
1034            beat_value = 0;
1035            beat_flag = false;
1036        }
1037    }
1038    if (flash_flag)
1039    {
1040        angle = (main_angle - flash_angle) * flash_speed;
1041        flash_value = 1.0f - sinf(angle);
1042        if (angle > 90.0f * PID)
1043        {
1044            flash_value = 0;
1045            flash_flag = false;
1046        }
1047    }
1048    if (fade_flag)
1049    {
1050        angle = (main_angle - fade_angle) * fade_speed;
1051        fade_value = 1.0f - sinf(angle);
1052        if (angle > 90.0f * PID)
1053        {
1054            fade_value = 0;
1055            fade_flag = false;
1056        }
1057    }
1058
1059    Draw2D();
1060    Draw3D();
1061}
1062
1063void Render::Draw2D()
1064{
1065    /* Draw text in an offline buffer */
1066    m_txt_screen->Render();
1067
1068    if (g_setup)
1069        m_txt_setup->Render();
1070
1071    if (m_shader)
1072        fbo_back->Bind();
1073
1074    glViewport(0, 0, screen_size.x, screen_size.y);
1075
1076    /* Clear the back buffer */
1077    glEnable(GL_BLEND);
1078    glBlendFunc(GL_SRC_COLOR, GL_DST_ALPHA);
1079
1080    Video::SetClearColor(vec4(screen_color, 1.f));
1081    Video::SetClearDepth(1.0f); // set depth buffer
1082    Video::Clear(ClearMask::Color | ClearMask::Depth);
1083
1084    m_txt_screen->Blit(border, canvas_size);
1085    if (g_setup)
1086        m_txt_setup->Blit((screen_size - setup_canvas_size) / 2, setup_canvas_size);
1087
1088    //if (m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
1089    glLineWidth((m_polygon)?2.0f:1.0f);
1090    fx_angle=main_angle-part_angle;
1091    if (m_polygon)
1092        glEnable(GL_TEXTURE_2D);
1093
1094    glMatrixMode(GL_PROJECTION);
1095    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
1096    glLoadMatrixf(&m[0][0]);
1097    glMatrixMode(GL_MODELVIEW);
1098}
1099
1100void Render::Draw3D()
1101{
1102    if (!m_shader)
1103        return;
1104
1105    glDisable(GL_DEPTH_TEST);
1106    glDisable(GL_BLEND);
1107
1108    glEnableClientState(GL_VERTEX_ARRAY);
1109    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
1110
1111    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1112    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
1113
1114    if (m_shader_copper)
1115    {
1116        // shader copper
1117        fbo_tmp->Bind();
1118        shader_copper->Bind();
1119        shader_copper->SetUniform(shader_copper_texture, fbo_back->GetTexture(), 0);
1120        shader_copper->SetUniform(shader_copper_screen_size, (vec2)screen_size);
1121        shader_copper->SetUniform(shader_copper_time, fx_angle);
1122        shader_copper->SetUniform(shader_copper_copper, vec4(copper_copper.x, copper_copper.y, copper_copper.z * 16.0f, copper_copper.w * 16.0f));
1123        shader_copper->SetUniform(shader_copper_mask_color, copper_mask_color / 4.0f);
1124        TraceQuad();
1125        shader_color->Unbind();
1126        fbo_tmp->Unbind();
1127        // shader simple
1128        fbo_back->Bind();
1129        ShaderSimple(fbo_tmp, 0);
1130        fbo_back->Unbind();
1131    }
1132
1133    if (m_shader_remanence)
1134    {
1135        // shader remanence
1136        fbo_tmp->Bind();
1137        shader_remanence->Bind();
1138        shader_remanence->SetUniform(shader_remanence_source, fbo_back->GetTexture(), 0);
1139        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1140        shader_remanence->SetUniform(shader_remanence_mix, remanence);
1141        TraceQuad();
1142        shader_remanence->Unbind();
1143        fbo_tmp->Unbind();
1144        // shader simple
1145        fbo_back->Bind();
1146        ShaderSimple(fbo_tmp, 0);
1147        fbo_back->Unbind();
1148        // save previous fbo
1149        fbo_tmp->Bind();
1150        shader_remanence->Bind();
1151        shader_remanence->SetUniform(shader_remanence_source, fbo_screen->GetTexture(), 0);
1152        shader_remanence->SetUniform(shader_remanence_buffer, fbo_buffer->GetTexture(), 1);
1153        shader_remanence->SetUniform(shader_remanence_mix, buffer);
1154        TraceQuad();
1155        shader_remanence->Unbind();
1156        fbo_tmp->Unbind();
1157        // shader simple
1158        fbo_buffer->Bind();
1159        ShaderSimple(fbo_tmp, 0);
1160        fbo_buffer->Unbind();
1161    }
1162
1163    // shader glow
1164    if (m_shader_glow)
1165    {
1166        // shader blur horizontal
1167        fbo_blur_h->Bind();
1168        shader_blur_h->Bind();
1169        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_back->GetTexture(), 0);
1170        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
1171        TraceQuad();
1172        shader_blur_h->Unbind();
1173        fbo_blur_h->Unbind();
1174        // shader blur vertical
1175        fbo_blur_v->Bind();
1176        shader_blur_v->Bind();
1177        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1178        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
1179        TraceQuad();
1180        shader_blur_v->Unbind();
1181        fbo_blur_v->Unbind();
1182        // shader blur horizontal
1183        fbo_blur_h->Bind();
1184        shader_blur_h->Bind();
1185        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
1186        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
1187        TraceQuad();
1188        shader_blur_h->Unbind();
1189        fbo_blur_h->Unbind();
1190        // shader blur vertical
1191        fbo_blur_v->Bind();
1192        shader_blur_v->Bind();
1193        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
1194        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
1195        TraceQuad();
1196        shader_blur_v->Unbind();
1197        fbo_blur_v->Unbind();
1198        // shader glow
1199        fbo_screen->Bind();
1200        shader_glow->Bind();
1201        shader_glow->SetUniform(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
1202        shader_glow->SetUniform(shader_glow_source, fbo_back->GetTexture(), 1);
1203        shader_glow->SetUniform(shader_glow_mix, glow_mix);
1204        TraceQuad();
1205        shader_glow->Unbind();
1206        fbo_screen->Unbind();
1207    }
1208    else
1209    {
1210        // shader simple
1211        fbo_screen->Bind();
1212        ShaderSimple(fbo_back, 0);
1213        fbo_screen->Unbind();
1214    }
1215
1216    if (m_shader_color)
1217    {
1218        // shader color
1219        fbo_tmp->Bind();
1220        shader_color->Bind();
1221        shader_color->SetUniform(shader_color_texture, fbo_screen->GetTexture(), 0);
1222        shader_color->SetUniform(shader_color_screen_size, (vec2)screen_size);
1223        shader_color->SetUniform(shader_color_filter, color_filter);
1224        shader_color->SetUniform(shader_color_color, color_color);
1225        shader_color->SetUniform(shader_color_flash, flash_value);
1226        TraceQuad();
1227        shader_color->Unbind();
1228        fbo_tmp->Unbind();
1229        // shader simple
1230        fbo_screen->Bind();
1231        ShaderSimple(fbo_tmp, 0);
1232        fbo_screen->Unbind();
1233    }
1234
1235    if (m_shader_noise)
1236    {
1237        // shader noise
1238        fbo_tmp->Bind();
1239        shader_noise->Bind();
1240        shader_noise->SetUniform(shader_noise_texture, fbo_screen->GetTexture(), 0);
1241        shader_noise->SetUniform(shader_noise_screen_size, (vec2)screen_size);
1242        shader_noise->SetUniform(shader_noise_time, fx_angle);
1243        shader_noise->SetUniform(shader_noise_offset, noise_offset);
1244        shader_noise->SetUniform(shader_noise_noise, noise_noise);
1245        shader_noise->SetUniform(shader_noise_retrace, noise_retrace);
1246        TraceQuad();
1247        shader_noise->Unbind();
1248        fbo_tmp->Unbind();
1249        // shader simple
1250        fbo_screen->Bind();
1251        ShaderSimple(fbo_tmp, 0);
1252        fbo_screen->Unbind();
1253    }
1254
1255    if (m_shader_blur)
1256    {
1257        // shader blur horizontal
1258        fbo_tmp->Bind();
1259        shader_blur_h->Bind();
1260        shader_blur_h->SetUniform(shader_blur_h_texture, fbo_screen->GetTexture(), 0);
1261        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
1262        TraceQuad();
1263        shader_blur_h->Unbind();
1264        fbo_tmp->Unbind();
1265        // shader blur vertical
1266        fbo_screen->Bind();
1267        shader_blur_v->Bind();
1268        shader_blur_v->SetUniform(shader_blur_v_texture, fbo_tmp->GetTexture(), 0);
1269        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
1270        TraceQuad();
1271        shader_blur_v->Unbind();
1272        fbo_screen->Unbind();
1273    }
1274
1275    if (m_shader_postfx)
1276    {
1277        // shader postfx
1278        fbo_front->Bind();
1279        shader_postfx->Bind();
1280        shader_postfx->SetUniform(shader_postfx_texture, fbo_screen->GetTexture(), 0);
1281        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
1282        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
1283        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
1284        shader_postfx->SetUniform(shader_postfx_ghost1, postfx_ghost1);
1285        shader_postfx->SetUniform(shader_postfx_ghost2, postfx_ghost2);
1286        shader_postfx->SetUniform(shader_postfx_vignetting, postfx_vignetting);
1287        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
1288        shader_postfx->SetUniform(shader_postfx_moire_h, postfx_moire_h);
1289        shader_postfx->SetUniform(shader_postfx_moire_v, postfx_moire_v);
1290        shader_postfx->SetUniform(shader_postfx_scanline_h, postfx_scanline_h);
1291        shader_postfx->SetUniform(shader_postfx_scanline_v, postfx_scanline_v);
1292        shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
1293        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(sync_value * cosf((main_angle - sync_angle) * 6.0f)));
1294        shader_postfx->SetUniform(shader_postfx_beat, (float)fabs(beat_value * cosf((main_angle - beat_angle) * 6.0f)));
1295        TraceQuad();
1296        shader_postfx->Unbind();
1297        fbo_front->Unbind();
1298    }
1299    else
1300    {
1301        // shader simple
1302        fbo_front->Bind();
1303        ShaderSimple(fbo_screen, 0);
1304        fbo_front->Unbind();
1305    }
1306
1307    if (m_shader_mirror)
1308    {
1309        // shader mirror
1310        fbo_tmp->Bind();
1311        shader_mirror->Bind();
1312        shader_mirror->SetUniform(shader_mirror_texture, fbo_front->GetTexture(), 0);
1313        shader_mirror->SetUniform(shader_mirror_screen_size, (vec2)screen_size);
1314        shader_mirror->SetUniform(shader_mirror_mirror, vec4(mirror.x * 0.1f, mirror.y * 0.1f, mirror.z, mirror.w));
1315        TraceQuad();
1316        shader_mirror->Unbind();
1317        fbo_tmp->Unbind();
1318        // shader simple
1319        fbo_front->Bind();
1320        ShaderSimple(fbo_tmp, 0);
1321        fbo_front->Unbind();
1322    }
1323
1324    // shader simple
1325    ShaderSimple(fbo_front, 0);
1326
1327    glDisableClientState(GL_VERTEX_ARRAY);
1328    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1329}
1330
1331Render::~Render()
1332{
1333}
Note: See TracBrowser for help on using the repository browser.