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

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

setup menu: added a lot of parameters and reorganized some

File size: 29.7 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_blurh;
35extern char const *lolfx_blurv;
36extern char const *lolfx_remanency;
37extern char const *lolfx_glow;
38extern char const *lolfx_postfx;
39extern char const *lolfx_radial;
40extern char const *lolfx_simple;
41
42#define PID M_PI/180.0f    // pi ratio
43#define CR 1.0f/256.0f     // color ratio
44
45/*
46 * Various variables
47 */
48
49int active = true;         // window active flag
50float nearplane = 0.1f;    // nearplane
51float farplane = 1000.0f;  // farplane
52int polygon_fillmode = GL_FILL; // fill mode
53/* timer variable */
54float timer = 0;           // timer
55float timer_key = 0;       // key timer
56float timer_key_repeat = 0.25f;// key repeat delay
57/* window variable */
58ivec2 screen_size;         // screen size
59vec3 screen_color = CR * vec3(32, 32, 32); // screen color
60/* object variable */
61float main_angle = 0.0f;   // main angle
62float part_angle = 0.0f;   // part angle
63float fx_angle;            // current angle
64/* fs_quad variable */
65float 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};
66float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
67/* flash variable */
68bool flash_flag = false;   // flag
69float flash_angle = 0;     // angle
70float flash_value = 0;     // value
71float flash_speed = 1.5f;  // speed
72/* fade variable */
73bool fade_flag = false;    // flag
74float fade_angle = 0;      // angle
75float fade_value = 0;      // value
76float fade_speed = 0.2f;   // speed
77/* sync variable */
78bool sync_flag = false;    // flagsh
79float sync_angle = 0;      // angle
80float sync_value = 1.0f;   // value
81float sync_speed = 1.0f;   // speed
82/* beat variable */
83bool beat_flag = false;    // flag
84float beat_angle = 0;      // angle
85float beat_value = 0;      // value
86float beat_speed = 2.0f;   // speed
87/* window variable */
88ivec2 border;              // border width
89/* text variable */
90ivec2 ratio_2d(2,4);       // 2d ratio
91ivec2 map_size(256,256);   // texture map size
92ivec2 font_size(8,8);      // font size
93ivec2 canvas_char(0,0);    // canvas char number
94ivec2 canvas_size(0,0);    // caca size
95/* setup variable */
96bool setup_switch=false;        // switch [option/item]
97int setup_option=0;             // selected option
98int setup_option_n=7;           // option number
99int setup_item=0;               // selected item
100int setup_item_n=8;             // item number
101int setup_item_key=0;           // item array key
102ivec2 setup_p(1,1);             // position [x,y]
103ivec3 setup_size(30,0,12);      // size [w,h,split]
104ivec2 setup_color(0x678,0x234); // size [w,h]
105char const *setup_text[] = {
106    "remanency",
107        "enable",
108        "buffer new frame",
109        "buffer old frame",
110        "source mix",
111        "buffer mix",
112        "",
113        "",
114        "",
115    "glow",
116        "enable",
117        "source mix",
118        "glow mix",
119        "large center",
120        "large corner",
121        "small center",
122        "small corner",
123        "",
124    "blur",
125        "enable",
126        "blur center",
127        "blur corner",
128        "",
129        "",
130        "",
131        "",
132        "",
133    "color",
134        "postfx enable",
135        "filter red",
136        "filter green",
137        "filter blue",
138        "brightness",
139        "contrast",
140        "grayscale",
141        "",
142    "modifier",
143        "deform ratio",
144        "retrace strength",
145        "retrace length",
146        "retrace speed",
147        "",
148        "",
149        "",
150        "",
151    "noise",
152        "offset h",
153        "offset v",
154        "noise",
155        "aberration",
156        "",
157        "",
158        "",
159        "",
160    "moire",
161        "h base",
162        "h variable",
163        "h repeat x",
164        "h repeat y",
165        "v base",
166        "v variable",
167        "v repeat x",
168        "v repeat y",
169    "scanline",
170        "h base",
171        "h variable",
172        "h repeat x",
173        "h repeat y",
174        "v base",
175        "v variable",
176        "v repeat x",
177        "v repeat y"
178    };
179/* common variable */
180float value, angle, radius, scale, speed;
181/* shader variable */
182vec2 buffer(0.7f,0.3f);         // [new frame mix,old frame mix]
183vec2 remanency(0.3f,0.7f);      // remanency [source mix,buffer mix]
184vec2 glow_mix(0.5f,0.5f);       // glow mix [source mix,glow mix]
185vec2 glow_large(2.0f,2.0f);     // large glow radius [center,corner]
186vec2 glow_small(1.0f,1.0f);     // small glow radius [center,corner]
187vec2 blur(0.25f,0.5f);          // glow radius [center,corner]
188//vec3 radial(2.0f,0.8f,0);     // radial [mix,strength,color mode]
189//------------------------------// [IDEAS] http://www.youtube.com/watch?v=d1qEP2vMe-I
190float postfx_deform = 0.7f;     // deformation ratio
191vec3 postfx_filter(0.8f,0.9f,0.4f);// color filter [red,green,blue]
192vec3 postfx_color(1.8f,1.8f,0.5f);    // color modifier [brightness,contrast,grayscale]
193vec3 postfx_retrace(0.05f,2.0f,4.0f); // retrace [strength,length,speed]
194vec2 postfx_offset(3.0f,3.0f);  // random line [horizontal,vertical]
195float postfx_noise = 0.15f;     // noise
196float postfx_aberration = 3.0f; // chromatic aberration
197bool postfx_moire = true;       // moire
198vec4 postfx_moire_h(0.75f,-0.25f,0.0f,1.0f);
199vec4 postfx_moire_v(0.75f,-0.25f,1.0f,1.5f);
200bool postfx_scanline = true;    // scanline
201vec4 postfx_scanline_h(0.75f, 0.25f,0.0f,2.0f);// vertical scanline [base,variable,repeat x,repeat y]
202vec4 postfx_scanline_v(0.75f,-0.25f,2.0f,0.0f);// horizontal scanline [base,variable,repeat x,repeat y]
203//------------------------------//
204vec4 setup_var[]={
205    vec4(0), /* remanency */
206        vec4(0, 1, 1, 1),
207        vec4(0.0f, 1.0f, 0.1f, buffer.x),
208        vec4(0.0f, 1.0f, 0.1f, buffer.y),
209        vec4(0.0f, 1.0f, 0.1f, remanency.x),
210        vec4(0.0f, 1.0f, 0.1f, remanency.y),
211        vec4(0),
212        vec4(0),
213        vec4(0),
214    vec4(0), /* glow */
215        vec4(0, 1, 1, 0),
216        vec4(0.0f, 1.0f, 0.1f, glow_mix.x),
217        vec4(0.0f, 1.0f, 0.1f, glow_mix.y),
218        vec4(0.0f, 4.0f, 0.1f, glow_large.x),
219        vec4(0.0f, 4.0f, 0.1f, glow_large.y),
220        vec4(0.0f, 2.0f, 0.1f, glow_small.x),
221        vec4(0.0f, 2.0f, 0.1f, glow_small.y),
222        vec4(0),
223    vec4(0), /* blur */
224        vec4(0, 1, 1, 0),
225        vec4(0.0f, 2.0f, 0.1f, blur.x),
226        vec4(0.0f, 2.0f, 0.1f, blur.y),
227        vec4(0),
228        vec4(0),
229        vec4(0),
230        vec4(0),
231        vec4(0),
232    vec4(0), /* color */
233        vec4(0, 1, 1, 0),
234        vec4(0.0f, 1.0f, 0.1f, postfx_filter.x),
235        vec4(0.0f, 1.0f, 0.1f, postfx_filter.y),
236        vec4(0.0f, 1.0f, 0.1f, postfx_filter.z),
237        vec4(0.0f, 4.0f, 0.1f, postfx_color.x),
238        vec4(0.0f, 4.0f, 0.1f, postfx_color.y),
239        vec4(0.0f, 1.5f, 0.1f, postfx_color.z),
240        vec4(0),
241    vec4(0), /* modifier */
242        vec4(0.0f, 1.0f, 0.05f, postfx_deform),
243        vec4(0.0f, 1.0f, 0.05f, postfx_retrace.x),
244        vec4(0.0f, 8.0f, 1.0f, postfx_retrace.y),
245        vec4(0.0f, 8.0f, 1.0f, postfx_retrace.z),
246        vec4(0),
247        vec4(0),
248        vec4(0),
249        vec4(0),
250    vec4(0), /* noise */
251        vec4(0.0f, 4.0f, 0.5f, postfx_offset.x),
252        vec4(0.0f, 4.0f, 0.5f, postfx_offset.y),
253        vec4(0.0f, 1.0f, 0.05f, postfx_noise),
254        vec4(0.0f, 5.0f, 0.5f, postfx_aberration),
255        vec4(0),
256        vec4(0),
257        vec4(0),
258        vec4(0),
259    vec4(0)
260    };
261
262void Render::UpdateVar()
263{
264    int k = 1;
265    m_shader_remanency = (setup_var[k].w == 1) ? true : false; k++;
266    buffer = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
267    remanency = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
268    k += 4;
269    m_shader_glow = (setup_var[k].w == 1) ? true : false; k++;
270    glow_mix = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
271    glow_large = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
272    glow_small = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
273    k += 2;
274    m_shader_blur = (setup_var[k].w == 1) ? true : false; k++;
275    blur = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
276    k += 6;
277    m_shader_postfx = (setup_var[k].w == 1) ? true : false; k++;
278    postfx_filter = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
279    postfx_color = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
280    k += 2;
281    postfx_deform = setup_var[k].w; k++;
282    postfx_retrace = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
283    k += 5;
284    postfx_offset = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
285    postfx_noise = setup_var[k].w; k++;
286    postfx_aberration = setup_var[k].w; k++;
287    k += 5;
288}
289
290Shader *shader_simple;
291Shader *shader_blur_h, *shader_blur_v;
292Shader *shader_remanency, *shader_glow, *shader_radial, *shader_postfx;
293// shader variables
294ShaderUniform shader_simple_texture;
295ShaderUniform shader_remanency_source,
296              shader_remanency_buffer,
297              shader_remanency_mix;
298ShaderUniform shader_glow_glow,
299              shader_glow_source,
300              shader_glow_mix;
301ShaderUniform shader_blur_h_texture,
302              shader_blur_h_radius,
303              shader_blur_v_texture,
304              shader_blur_v_radius;
305ShaderUniform shader_radial_texture,
306              shader_radial_screen_size,
307              shader_radial_time,
308              shader_radial_value1,
309              shader_radial_value2,
310              shader_radial_color;
311ShaderUniform shader_postfx_texture,
312              shader_postfx_texture_2d,
313              shader_postfx_screen_size,
314              shader_postfx_time,
315              shader_postfx_deform,
316              shader_postfx_filter,
317              shader_postfx_color,
318              shader_postfx_retrace,
319              shader_postfx_offset,
320              shader_postfx_noise,
321              shader_postfx_aberration,
322              shader_postfx_moire,
323              shader_postfx_moire_h,
324              shader_postfx_moire_v,
325              shader_postfx_scanline,
326              shader_postfx_scanline_h,
327              shader_postfx_scanline_v,
328              shader_postfx_flash,
329              shader_postfx_sync;
330
331FrameBuffer *fbo_back, *fbo_front, *fbo_buffer;
332FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
333
334TextRender *text_render;
335
336void fs_quad()
337{
338    glLoadIdentity();
339    glDrawArrays(GL_QUADS, 0, 4);
340}
341
342void draw_shader_simple(FrameBuffer *fbo_output, int n)
343{
344    shader_simple->Bind();
345    shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n);
346    fs_quad();
347    shader_simple->Unbind();
348}
349
350void rectangle(int x, int y, int w, int h)
351{
352    glLoadIdentity();
353    glBegin(GL_QUADS);
354        glVertex2i(x+w, y  );
355        glVertex2i(x  , y  );
356        glVertex2i(x  , y+h);
357        glVertex2i(x+w, y+h);
358    glEnd();
359}
360
361int Render::InitDraw(void)
362{
363    glDepthMask(GL_TRUE);     // do not write z-buffer
364    glEnable(GL_CULL_FACE);   // disable cull face
365    glCullFace(GL_BACK);      // don't draw front face
366
367    /* Initialise framebuffer objects */
368    fbo_back = new FrameBuffer(screen_size);
369    fbo_front = new FrameBuffer(screen_size);
370    fbo_buffer = new FrameBuffer(screen_size);
371    fbo_blur_h = new FrameBuffer(screen_size);
372    fbo_blur_v = new FrameBuffer(screen_size);
373    fbo_ping = new FrameBuffer(screen_size);
374    fbo_pong = new FrameBuffer(screen_size);
375    // shader simple
376    shader_simple = Shader::Create(lolfx_simple);
377    shader_simple_texture = shader_simple->GetUniformLocation("texture");
378    // shader remanency
379    shader_remanency = Shader::Create(lolfx_remanency);
380    shader_remanency_source = shader_remanency->GetUniformLocation("source");
381    shader_remanency_buffer = shader_remanency->GetUniformLocation("buffer");
382    shader_remanency_mix = shader_remanency->GetUniformLocation("mix");
383    // shader glow
384    shader_glow = Shader::Create(lolfx_glow);
385    shader_glow_glow = shader_glow->GetUniformLocation("glow");
386    shader_glow_source = shader_glow->GetUniformLocation("source");
387    shader_glow_mix = shader_glow->GetUniformLocation("mix");
388    // shader blur horizontal
389    shader_blur_h = Shader::Create(lolfx_blurh);
390    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
391    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
392    // shader blur vertical
393    shader_blur_v = Shader::Create(lolfx_blurv);
394    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
395    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
396    // shader radial
397    shader_radial = Shader::Create(lolfx_radial);
398    shader_radial_texture = shader_radial->GetUniformLocation("texture");
399    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
400    shader_radial_time = shader_radial->GetUniformLocation("time");
401    shader_radial_value1 = shader_radial->GetUniformLocation("value1");
402    shader_radial_value2 = shader_radial->GetUniformLocation("value2");
403    shader_radial_color = shader_radial->GetUniformLocation("color");
404    // shader postfx
405    shader_postfx = Shader::Create(lolfx_postfx);
406    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
407    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
408    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
409    shader_postfx_time = shader_postfx->GetUniformLocation("time");
410    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
411    shader_postfx_filter = shader_postfx->GetUniformLocation("filter");
412    shader_postfx_color = shader_postfx->GetUniformLocation("color");
413    shader_postfx_retrace = shader_postfx->GetUniformLocation("retrace");
414    shader_postfx_offset = shader_postfx->GetUniformLocation("offset");
415    shader_postfx_noise = shader_postfx->GetUniformLocation("noise");
416    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
417    shader_postfx_moire = shader_postfx->GetUniformLocation("moire");
418    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
419    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
420    shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline");
421    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
422    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
423    shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
424    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
425
426    return true;
427}
428
429int Render::CreateGLWindow()
430{
431    screen_size = Video::GetSize();
432    border = 18 * ratio_2d;
433    border.y = border.x; // enabled to get same border everywhere
434    canvas_char = (screen_size - border * 2) / (font_size * ratio_2d);
435    canvas_size = canvas_char * font_size * ratio_2d;
436
437    border = (screen_size - canvas_size) / 2;
438
439    caca_set_canvas_size(m_caca, canvas_char.x, canvas_char.y);
440
441    setup_size.y = ((setup_option_n > setup_item_n) ? setup_option_n : setup_item_n) + 1;
442    setup_p = (canvas_char - setup_size.xy) / 2;
443
444    InitDraw();
445    return true;
446}
447
448Render::Render(caca_canvas_t *caca)
449  : m_caca(caca),
450    m_ready(false),
451    m_pause(false),
452    m_polygon(true),
453    m_setup(true),
454    m_shader(true),
455    m_shader_remanency(true),
456    m_shader_glow(false),
457    m_shader_blur(false),
458    m_shader_postfx(false),
459    m_border(false)
460{
461    text_render = new TextRender(m_caca, font_size);
462}
463
464void Render::TickGame(float seconds)
465{
466    Entity::TickGame(seconds);
467}
468
469void Render::Pause()
470{
471    m_pause=!m_pause;
472}
473
474void Render::TickDraw(float seconds)
475{
476    /* keyboard manager */
477    if (Input::GetButtonState(27/*SDLK_ESCAPE*/))
478        Ticker::Shutdown();
479    if (Input::GetButtonState(282/*SDLK_F1*/) && (timer - timer_key > timer_key_repeat))
480    {
481        m_setup = !m_setup;
482        timer_key = timer;
483    }
484    if (Input::GetButtonState(283/*SDLK_F2*/) && (timer - timer_key > timer_key_repeat))
485    {
486        m_polygon = !m_polygon;
487        polygon_fillmode = (m_polygon)?GL_FILL:GL_LINE;
488        glPolygonMode(GL_FRONT, polygon_fillmode);
489        timer_key = timer;
490    }
491    if (Input::GetButtonState(284/*SDLK_F3*/) && (timer - timer_key > timer_key_repeat))
492    {
493        m_shader_glow = !m_shader_glow;
494        m_shader_blur = !m_shader_blur;
495        timer_key = timer;
496    }
497    if (Input::GetButtonState(285/*SDLK_F4*/)&&(timer-timer_key>timer_key_repeat))
498    {
499        m_shader_postfx = !m_shader_postfx;
500        timer_key = timer;
501    }
502    if (Input::GetButtonState(286/*SDLK_F5*/))
503    {
504        Pause();
505    }
506   if (Input::GetButtonState(9/*SDLK_TAB*/)&&(timer-timer_key>timer_key_repeat))
507    {
508        if (m_setup)
509        {
510            setup_switch = !setup_switch;
511        }
512        timer_key = timer;
513    }
514    if (Input::GetButtonState(273/*SDLK_UP*/)&&(timer-timer_key>timer_key_repeat))
515    {
516        if (m_setup)
517        {
518            if (!setup_switch)
519            {
520                setup_option--;
521                if (setup_option < 0) setup_option = setup_option_n - 1;
522                setup_item = 0;
523            }
524            else
525            {
526                setup_item--;
527                if (setup_item < 0) setup_item = setup_item_n - 1;
528            }
529        }
530        timer_key = timer;
531    }
532    if (Input::GetButtonState(274/*SDLK_DOWN*/)&&(timer-timer_key>timer_key_repeat))
533    {
534        if (m_setup)
535        {
536            if (!setup_switch)
537            {
538                setup_option++;
539                if (setup_option > setup_option_n - 1) setup_option = 0;
540                setup_item = 0;
541            }
542            else
543            {
544                setup_item++;
545                if (setup_item > setup_item_n - 1) setup_item = 0;
546            }
547        }
548        timer_key = timer;
549    }
550    if (Input::GetButtonState(276/*SDLK_LEFT*/)&&(timer-timer_key>timer_key_repeat))
551    {
552        if (m_setup && setup_switch)
553        {
554            setup_var[setup_item_key].w -= setup_var[setup_item_key].z;
555            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;
556            Render::UpdateVar();
557        }
558        timer_key = timer;
559    }
560    if (Input::GetButtonState(275/*SDLK_RIGHT*/)&&(timer-timer_key>timer_key_repeat))
561    {
562        if (m_setup && setup_switch)
563        {
564            setup_var[setup_item_key].w += setup_var[setup_item_key].z;
565            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;
566            Render::UpdateVar();
567        }
568        timer_key = timer;
569    }
570    if (Input::GetButtonState(13/*SDLK_RETURN*/)&&(timer-timer_key>timer_key_repeat))
571    {
572        timer_key = timer;
573    }
574
575    Entity::TickDraw(seconds);
576
577    if (!m_ready)
578    {
579        CreateGLWindow();
580        text_render->Init();
581        m_ready = true;
582    }
583
584    // timer
585    if (!m_pause)
586    {
587        timer += seconds;
588        main_angle = timer * 100.0f * PID;
589    }
590    if (sync_flag)
591    {
592        angle=(main_angle-sync_angle)*sync_speed;
593        sync_value=1.0f-sinf(angle);
594        if (angle>90.0f*PID)
595        {
596            sync_value=0;
597            sync_flag=false;
598        }
599    }
600    if (beat_flag)
601    {
602        angle=(main_angle-beat_angle)*beat_speed;
603        beat_value=1.0f-sinf(angle);
604        if (angle>90.0f*PID)
605        {
606            beat_value=0;
607            beat_flag=false;
608        }
609    }
610    if (flash_flag)
611    {
612        angle=(main_angle-flash_angle)*flash_speed;
613        flash_value=1.0f-sinf(angle);
614        if (angle>90.0f*PID)
615        {
616            flash_value=0;
617            flash_flag=false;
618        }
619    }
620    if (fade_flag)
621    {
622        angle=(main_angle-fade_angle)*fade_speed;
623        fade_value=1.0f-sinf(angle);
624        if (angle>90.0f*PID)
625        {
626            fade_value=0;
627            fade_flag=false;
628        }
629    }
630    /* draw setup */
631    if (m_setup)
632    {
633        /* background */
634        caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
635        caca_fill_box(m_caca, setup_p.x, setup_p.y, setup_size.x + 1, setup_size.y,' ');
636        caca_draw_line(m_caca, setup_p.x + setup_size.z - 1, setup_p.y + 1, setup_p.x + setup_size.z - 1, setup_p.y + setup_size.y - 1,'|');
637        /* title */
638        caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
639        caca_draw_line(m_caca, setup_p.x, setup_p.y, setup_p.x + setup_size.x, setup_p.y,' ');
640        caca_put_str(m_caca, setup_p.x + setup_size.x / 2 - 3, setup_p.y, "SETUP");
641        /* display option */
642        for (int i = 0; i < setup_option_n; i++)
643        {
644            int y = setup_p.y + 1 + i;
645            int k = i * (setup_item_n + 1);
646            if (setup_option != i || setup_switch)
647            {
648                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
649                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
650            }
651            else
652            {
653                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
654                caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.z - 2, y,' ');
655                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
656            }
657        }
658        /* display item */
659        for (int i = 0; i < setup_item_n; i++)
660        {
661            int y = setup_p.y + 1 + i;
662            int k = setup_option * (setup_item_n + 1) + 1;
663            if (setup_item != i || !setup_switch)
664            {
665                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
666                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
667            }
668            else
669            {
670                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
671                caca_draw_line(m_caca, setup_p.x + setup_size.z, y, setup_p.x + setup_size.x, y,' ');
672                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
673            }
674        }
675        /* display variable */
676        int y = setup_p.y + setup_size.y;
677        caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
678        caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.x, y,' ');
679        if (setup_switch)
680        {
681            setup_item_key = setup_option * (setup_item_n + 1) + 1 + setup_item;
682            int w = setup_size.x - 3 - 4;
683            caca_printf(m_caca, setup_p.x + setup_size.x - 4, y, "%4.2f", setup_var[setup_item_key].w);
684            caca_draw_line(m_caca, setup_p.x + 1, y, setup_p.x + 1 + w, y,'.');
685            if(setup_var[setup_item_key].w > setup_var[setup_item_key].x) caca_draw_line(m_caca, setup_p.x + 1, y, setup_p.x + 1 + int(w / (setup_var[setup_item_key].y - setup_var[setup_item_key].x) * setup_var[setup_item_key].w), y,'x');
686        }
687    }
688
689    Draw2D();
690    Draw3D();
691
692}
693
694void Render::Draw2D()
695{
696    /* Draw text in an offline buffer */
697    text_render->Render();
698
699    if (m_shader)
700    {
701        fbo_back->Bind();
702    }
703
704    glViewport(0, 0, screen_size.x, screen_size.y);
705
706    /* Clear the back buffer */
707    glEnable(GL_BLEND);
708    glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
709    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
710    glClearDepth(1.0f); // set depth buffer
711    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
712
713    text_render->Blit(border, canvas_size);
714
715    //if (m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
716    glLineWidth((m_polygon)?2.0f:1.0f);
717    fx_angle=main_angle-part_angle;
718    if (m_polygon)
719        glEnable(GL_TEXTURE_2D);
720
721    glMatrixMode(GL_PROJECTION);
722    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
723    glLoadMatrixf(&m[0][0]);
724    glMatrixMode(GL_MODELVIEW);
725    // draw border
726    if (m_border)
727    {
728        glDisable(GL_TEXTURE_2D);
729        glDisable(GL_BLEND);
730        glColor3f(1.0f, 1.0f, 1.0f);
731        rectangle(border.x - ratio_2d.x, border.y - ratio_2d.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
732        rectangle(border.x - ratio_2d.x, border.y, ratio_2d.x, canvas_size.y);
733        rectangle(border.x + canvas_size.x, border.y, ratio_2d.x, canvas_size.y);
734        rectangle(border.x - ratio_2d.x, border.y + canvas_size.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
735        glEnable(GL_BLEND);
736    }
737}
738
739void Render::Draw3D()
740{
741    if (!m_shader)
742        return;
743
744    glDisable(GL_DEPTH_TEST);
745    glDisable(GL_BLEND);
746
747    glEnableClientState(GL_VERTEX_ARRAY);
748    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
749
750    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
751    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
752
753    if (m_shader_remanency)
754    {
755        // shader remanency
756        fbo_ping->Bind();
757        shader_remanency->Bind();
758        shader_remanency->SetTexture(shader_remanency_source, fbo_back->GetTexture(), 0);
759        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
760        shader_remanency->SetUniform(shader_remanency_mix, remanency);
761        fs_quad();
762        shader_remanency->Unbind();
763        fbo_ping->Unbind();
764        // shader simple
765        fbo_back->Bind();
766        draw_shader_simple(fbo_ping, 0);
767        fbo_back->Unbind();
768        // save previous fbo
769        fbo_ping->Bind();
770        shader_remanency->Bind();
771        shader_remanency->SetTexture(shader_remanency_source, fbo_front->GetTexture(), 0);
772        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
773        shader_remanency->SetUniform(shader_remanency_mix, buffer);
774        fs_quad();
775        shader_remanency->Unbind();
776        fbo_ping->Unbind();
777        // shader simple
778        fbo_buffer->Bind();
779        draw_shader_simple(fbo_ping, 0);
780        fbo_buffer->Unbind();
781    }
782
783    // shader glow
784    if (m_shader_glow)
785    {
786        // shader blur horizontal
787        fbo_blur_h->Bind();
788        shader_blur_h->Bind();
789        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
790        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
791        fs_quad();
792        shader_blur_h->Unbind();
793        fbo_blur_h->Unbind();
794        // shader blur vertical
795        fbo_blur_v->Bind();
796        shader_blur_v->Bind();
797        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
798        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
799        fs_quad();
800        shader_blur_v->Unbind();
801        fbo_blur_v->Unbind();
802        // shader blur horizontal
803        fbo_blur_h->Bind();
804        shader_blur_h->Bind();
805        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
806        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
807        fs_quad();
808        shader_blur_h->Unbind();
809        fbo_blur_h->Unbind();
810        // shader blur vertical
811        fbo_blur_v->Bind();
812        shader_blur_v->Bind();
813        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
814        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
815        fs_quad();
816        shader_blur_v->Unbind();
817        fbo_blur_v->Unbind();
818        // shader glow
819        fbo_front->Bind();
820        shader_glow->Bind();
821        shader_glow->SetTexture(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
822        shader_glow->SetTexture(shader_glow_source, fbo_back->GetTexture(), 1);
823        shader_glow->SetUniform(shader_glow_mix, glow_mix);
824        fs_quad();
825        shader_glow->Unbind();
826        fbo_front->Unbind();
827    }
828    else
829    {
830        // shader simple
831        fbo_front->Bind();
832        draw_shader_simple(fbo_back, 0);
833        fbo_front->Unbind();
834    }
835
836    if (m_shader_blur)
837    {
838        // shader blur horizontal
839        fbo_ping->Bind();
840        shader_blur_h->Bind();
841        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_front->GetTexture(), 0);
842        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
843        fs_quad();
844        shader_blur_h->Unbind();
845        fbo_ping->Unbind();
846        // shader blur vertical
847        fbo_front->Bind();
848        shader_blur_v->Bind();
849        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
850        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
851        fs_quad();
852        shader_blur_v->Unbind();
853        fbo_front->Unbind();
854    }
855
856    if (m_shader_postfx)
857    {
858        // shader postfx
859        shader_postfx->Bind();
860        shader_postfx->SetTexture(shader_postfx_texture, fbo_front->GetTexture(), 0);
861        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
862        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
863        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
864        shader_postfx->SetUniform(shader_postfx_filter, postfx_filter);
865        shader_postfx->SetUniform(shader_postfx_color, postfx_color);
866        shader_postfx->SetUniform(shader_postfx_retrace, postfx_retrace);
867        shader_postfx->SetUniform(shader_postfx_offset, postfx_offset);
868        shader_postfx->SetUniform(shader_postfx_noise, postfx_noise);
869        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
870        shader_postfx->SetUniform(shader_postfx_moire, postfx_moire);
871        shader_postfx->SetUniform(shader_postfx_moire_h, postfx_moire_h);
872        shader_postfx->SetUniform(shader_postfx_moire_v, postfx_moire_v);
873        shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline);
874        shader_postfx->SetUniform(shader_postfx_scanline_h, postfx_scanline_h);
875        shader_postfx->SetUniform(shader_postfx_scanline_v, postfx_scanline_v);
876        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
877        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
878        fs_quad();
879        shader_postfx->Unbind();
880    }
881    else
882    {
883        // shader simple
884        draw_shader_simple(fbo_front, 0);
885    }
886
887    glDisableClientState(GL_VERTEX_ARRAY);
888    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
889}
890
891Render::~Render()
892{
893}
Note: See TracBrowser for help on using the repository browser.