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

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

setup menu - added Render::UpdateVar(int key) function

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