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

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

setup menu improved, now you can change (some) variable

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