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

Last change on this file since 1588 was 1588, checked in by rez, 10 years ago

debug shortcuts added

File size: 22.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_glow;
37extern char const *lolfx_postfx;
38extern char const *lolfx_radial;
39extern char const *lolfx_simple;
40
41#define DEBUG 1            // debug flag //#if defined(_DEBUG)
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
53bool key_state = 0;      // key state
54/* window variable */
55ivec2 screen_size;         // screen size
56vec3 screen_color = CR * vec3(48, 56, 64); // screen color
57/* object variable */
58float main_angle = 0.0f;   // main angle
59float part_angle = 0.0f;   // part angle
60float fx_angle;            // current angle
61/* fs_quad variable */
62float 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};
63float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
64/* flash variable */
65bool flash_flag = false;   // flag
66float flash_angle = 0;     // angle
67float flash_value = 0;     // value
68float flash_speed = 1.5f;  // speed
69/* fade variable */
70bool fade_flag = false;    // flag
71float fade_angle = 0;      // angle
72float fade_value = 0;      // value
73float fade_speed = 0.2f;   // speed
74/* sync variable */
75bool sync_flag = false;    // flag
76float sync_angle = 0;      // angle
77float sync_value = 1.0f;   // value
78float sync_speed = 1.0f;   // speed
79/* beat variable */
80bool beat_flag = false;    // flag
81float beat_angle = 0;      // angle
82float beat_value = 0;      // value
83float beat_speed = 2.0f;   // speed
84/* corner variable */
85const int corner_n = 10;   // m_polygon number
86int corner_w = 24;         // radius
87int corner_vtx[corner_n*6];// vertex array
88/* window variable */
89int window_m;              // margin
90int window_vtx[8];         // vertex array
91ivec2 ratio_2d(2,4);       // 2d ratio
92ivec2 map_size(256,256);   // texture map size
93ivec2 font_size(8,8);      // font size
94vec2 car_size(1.0f/map_size.x*font_size.x, 1.0f/map_size.y*font_size.y);
95int shell_vtx[8];          // vertex array
96float shell_tex[] = {1.0f, 0.96875f, 1.0f, 1.0f, 0.78125f, 1.0f, 0.78125f, 0.96875f};
97/* common variable */
98float value, angle, radius, scale, speed;
99/* shader variable */
100int glow_fbo_size = 2;        // glow fbo size
101float glow_smoothstep = 0.0f; // glow smoothstep value (try 0.025f)
102float glow_mix_ratio1 = 0.5f; // glow mixing ratio
103float glow_mix_ratio2 = 0.5f; // source mixing ratio
104float radial_value1 = 2.0f;
105float radial_value2 = 0.8f;
106float radial_color = 0;       // color
107bool postfx_scanline = true;
108float postfx_deform = 0.5f;   // deformation ratio
109
110Shader *shader_simple, *shader_blur_h, *shader_blur_v;
111Shader *shader_glow, *shader_radial, *shader_postfx;
112// shader variables
113ShaderUniform shader_simple_texture;
114ShaderUniform shader_blur_h_texture,
115              shader_blur_h_screen_size,
116              shader_blur_h_time,
117              shader_blur_h_value;
118ShaderUniform shader_blur_v_texture,
119              shader_blur_v_screen_size,
120              shader_blur_v_time,
121              shader_blur_v_value;
122ShaderUniform shader_glow_texture,
123              shader_glow_texture_prv,
124              shader_glow_screen_size,
125              shader_glow_time,
126              shader_glow_step,
127              shader_glow_value1,
128              shader_glow_value2;
129ShaderUniform shader_radial_texture,
130              shader_radial_screen_size,
131              shader_radial_time,
132              shader_radial_value1,
133              shader_radial_value2,
134              shader_radial_color;
135ShaderUniform shader_postfx_texture,
136              shader_postfx_texture_2d,
137              shader_postfx_screen_size,
138              shader_postfx_time,
139              shader_postfx_flash,
140              shader_postfx_value,
141              shader_postfx_deform,
142              shader_postfx_scanline,
143              shader_postfx_sync;
144
145FrameBuffer *fbo_back, *fbo_front;
146FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
147
148TextRender *text_render;
149
150void fs_quad()
151{
152    glLoadIdentity();
153    glDrawArrays(GL_QUADS, 0, 4);
154}
155
156void draw_shader_simple(FrameBuffer *fbo_output, int n)
157{
158    shader_simple->Bind();
159    shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n);
160    fs_quad();
161    shader_simple->Unbind();
162}
163
164void rectangle(int x, int y, int w, int h)
165{
166    glLoadIdentity();
167    glBegin(GL_QUADS);
168        glVertex2i(x+w, y  );
169        glVertex2i(x  , y  );
170        glVertex2i(x  , y+h);
171        glVertex2i(x+w, y+h);
172    glEnd();
173}
174
175void corner()
176{
177    float vertex[6+corner_n*2];
178    vertex[0] = 0;
179    vertex[1] = 0;
180    for (int i = 1; i < corner_n + 1; i++)
181    {
182        int j = i*2;
183        float a = PID*90.0f/(corner_n-1)*(i-1);
184        vertex[j  ] = corner_w-corner_w*cosf(a);
185        vertex[j+1] = corner_w-corner_w*sinf(a);
186    }
187    for (int i = 0; i < corner_n; i++)
188    {
189        int j = i*6;
190        int k = i*2;
191        corner_vtx[j  ] = (int)vertex[0];
192        corner_vtx[j+1] = (int)vertex[1];
193        corner_vtx[j+2] = (int)vertex[2+k];
194        corner_vtx[j+3] = (int)vertex[3+k];
195        corner_vtx[j+4] = (int)vertex[4+k];
196        corner_vtx[j+5] = (int)vertex[5+k];
197    }
198}
199
200int Render::InitDraw(void)
201{
202    glDepthMask(GL_TRUE);     // do not write z-buffer
203    glEnable(GL_CULL_FACE);   // disable cull face
204    glCullFace(GL_BACK);      // don't draw front face
205
206    if (m_shader)
207    {
208        /* Initialise framebuffer objects */
209        fbo_back = new FrameBuffer(screen_size);
210        fbo_front = new FrameBuffer(screen_size);
211        fbo_blur_h = new FrameBuffer(screen_size / glow_fbo_size);
212        fbo_blur_v = new FrameBuffer(screen_size / glow_fbo_size);
213        fbo_ping = new FrameBuffer(screen_size);
214        fbo_pong = new FrameBuffer(screen_size);
215        // shader simple
216        shader_simple = Shader::Create(lolfx_simple);
217        shader_simple_texture = shader_simple->GetUniformLocation("texture");
218        // shader blur horizontal
219        shader_blur_h = Shader::Create(lolfx_blurh);
220        shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
221        shader_blur_h_screen_size = shader_blur_h->GetUniformLocation("screen_size");
222        shader_blur_h_time = shader_blur_h->GetUniformLocation("time");
223        shader_blur_h_value = shader_blur_h->GetUniformLocation("value");
224        // shader blur vertical
225        shader_blur_v = Shader::Create(lolfx_blurv);
226        shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
227        shader_blur_v_screen_size = shader_blur_v->GetUniformLocation("screen_size");
228        shader_blur_v_time = shader_blur_v->GetUniformLocation("time");
229        shader_blur_v_value = shader_blur_v->GetUniformLocation("value");
230        // shader glow
231        shader_glow = Shader::Create(lolfx_glow);
232        shader_glow_texture = shader_glow->GetUniformLocation("texture");
233        shader_glow_texture_prv = shader_glow->GetUniformLocation("texture_prv");
234        shader_glow_screen_size = shader_glow->GetUniformLocation("screen_size");
235        shader_glow_time = shader_glow->GetUniformLocation("time");
236        shader_glow_step = shader_glow->GetUniformLocation("step");
237        shader_glow_value1 = shader_glow->GetUniformLocation("value1");
238        shader_glow_value2 = shader_glow->GetUniformLocation("value2");
239        // shader radial
240        shader_radial = Shader::Create(lolfx_radial);
241        shader_radial_texture = shader_radial->GetUniformLocation("texture");
242        shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
243        shader_radial_time = shader_radial->GetUniformLocation("time");
244        shader_radial_value1 = shader_radial->GetUniformLocation("value1");
245        shader_radial_value2 = shader_radial->GetUniformLocation("value2");
246        shader_radial_color = shader_radial->GetUniformLocation("color");
247        // shader postfx
248        shader_postfx = Shader::Create(lolfx_postfx);
249        shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
250        shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
251        shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
252        shader_postfx_time = shader_postfx->GetUniformLocation("time");
253        shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
254        shader_postfx_value = shader_postfx->GetUniformLocation("value");
255        shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
256        shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline");
257        shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
258    }
259
260    return true;
261}
262
263int Render::CreateGLWindow()
264{
265    screen_size = Video::GetSize();
266    corner_w = 16*ratio_2d.x;
267    corner();
268    window_m=12*ratio_2d.x;
269    window_vtx[0]=font_size.x*ratio_2d.x/2.0f;
270    window_vtx[1]=font_size.y*ratio_2d.y/2.0f;
271    window_vtx[2]=font_size.x*ratio_2d.x/2.0f;
272    window_vtx[3]=-font_size.y*ratio_2d.y/2.0f;
273    window_vtx[4]=-font_size.x*ratio_2d.x/2.0f;
274    window_vtx[5]=-font_size.y*ratio_2d.y/2.0f;
275    window_vtx[6]=-font_size.x*ratio_2d.x/2.0f;
276    window_vtx[7]=font_size.y*ratio_2d.y/2.0f;
277    shell_vtx[0]=window_m+58*ratio_2d.x;
278    shell_vtx[1]=window_m+(font_size.y+1)*ratio_2d.y;
279    shell_vtx[2]=window_m+58*ratio_2d.x;
280    shell_vtx[3]=window_m+ratio_2d.y;
281    shell_vtx[4]=window_m+2*ratio_2d.x;
282    shell_vtx[5]=window_m+ratio_2d.y;
283    shell_vtx[6]=window_m+2*ratio_2d.x;
284    shell_vtx[7]=window_m+(font_size.y+1)*ratio_2d.y;
285    InitDraw();
286    return true;
287}
288
289Render::Render(caca_canvas_t *caca)
290  : m_caca(caca),
291    m_ready(false),
292    m_pause(false),
293    m_polygon(true),
294    m_shader(true),
295    m_shader_blur(true),
296    m_shader_glow(true),
297    m_shader_fx(true),
298    m_shader_postfx(true)
299{
300    text_render = new TextRender(m_caca, font_size);
301}
302
303void Render::TickGame(float seconds)
304{
305    Entity::TickGame(seconds);
306}
307
308void Render::Pause()
309{
310    m_pause=!m_pause;
311}
312
313void Render::TickDraw(float seconds)
314{
315    /* keyboard manager */
316    if (Input::GetButtonState(27/*SDLK_ESCAPE*/))
317        Ticker::Shutdown();
318    //if (Input::GetButtonState(282/*SDLK_F1*/))
319    //    Pause();
320    if (Input::GetButtonState(283/*SDLK_F2*/))
321        {
322        m_polygon=!m_polygon;
323        polygon_fillmode=(m_polygon)?GL_FILL:GL_LINE;
324        glPolygonMode(GL_FRONT,polygon_fillmode);
325        }
326    if (Input::GetButtonState(284/*SDLK_F3*/)&&key_state!=284)
327        {
328        m_shader=!m_shader;
329        key_state=284;
330        }
331    if (Input::GetButtonState(285/*SDLK_F4*/))
332        m_shader_postfx=!m_shader_postfx;
333    if (Input::GetButtonState(286/*SDLK_F5*/))
334        Pause();
335
336    Entity::TickDraw(seconds);
337
338    if (!m_ready)
339    {
340        CreateGLWindow();
341        text_render->Init();
342        m_ready = true;
343    }
344
345    // timer
346    if(!m_pause)
347        main_angle += seconds * 100.0f * PID;
348    if(sync_flag)
349    {
350        angle=(main_angle-sync_angle)*sync_speed;
351        sync_value=1.0f-sinf(angle);
352        if(angle>90.0f*PID)
353        {
354            sync_value=0;
355            sync_flag=false;
356        }
357    }
358    if(beat_flag)
359    {
360        angle=(main_angle-beat_angle)*beat_speed;
361        beat_value=1.0f-sinf(angle);
362        if(angle>90.0f*PID)
363        {
364            beat_value=0;
365            beat_flag=false;
366        }
367    }
368    if(flash_flag)
369    {
370        angle=(main_angle-flash_angle)*flash_speed;
371        flash_value=1.0f-sinf(angle);
372        if(angle>90.0f*PID)
373        {
374            flash_value=0;
375            flash_flag=false;
376        }
377    }
378    if(fade_flag)
379    {
380        angle=(main_angle-fade_angle)*fade_speed;
381        fade_value=1.0f-sinf(angle);
382        if(angle>90.0f*PID)
383        {
384            fade_value=0;
385            fade_flag=false;
386        }
387    }
388
389    Draw2D();
390    Draw3D();
391}
392
393void Render::Draw2D()
394{
395    /* Draw text in an offline buffer */
396    text_render->Render();
397
398    if(m_shader)
399        fbo_back->Bind();
400
401    glViewport(0, 0, screen_size.x, screen_size.y);
402
403    /* Clear the back buffer */
404    glEnable(GL_BLEND);
405    glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
406    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
407    glClearDepth(1.0f); // set depth buffer
408    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
409
410    ivec2 border_top = ivec2(window_m, window_m + font_size.y * ratio_2d.y)
411                     + ratio_2d * 2;
412    ivec2 border_bottom = ivec2(window_m * 2, window_m * 2 + font_size.y * ratio_2d.y)
413                        + ratio_2d * 2;
414    text_render->Blit(border_top, screen_size - border_bottom);
415
416    //if(m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
417    glLineWidth((m_polygon)?2.0f:1.0f);
418    fx_angle=main_angle-part_angle;
419    if(m_polygon) glEnable(GL_TEXTURE_2D);
420
421    glMatrixMode(GL_PROJECTION);
422    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
423    glLoadMatrixf(&m[0][0]);
424    glMatrixMode(GL_MODELVIEW);
425    // draw window
426    glDisable(GL_TEXTURE_2D);
427    glDisable(GL_BLEND);
428    glColor3f(1.0f,1.0f,1.0f);
429    rectangle(window_m,window_m,screen_size.x-53*ratio_2d.x-window_m*2,(font_size.y+2)*ratio_2d.y);
430    rectangle(screen_size.x-51*ratio_2d.x-window_m,window_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
431    rectangle(screen_size.x-27*ratio_2d.x-window_m,window_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
432    rectangle(screen_size.x-3*ratio_2d.x-window_m,window_m,3*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
433    rectangle(window_m,window_m+(font_size.y+2)*ratio_2d.y,2*ratio_2d.x,screen_size.y-(font_size.y+2)*ratio_2d.y-window_m*2);
434    rectangle(screen_size.x-2*ratio_2d.x-window_m,window_m+(font_size.y+2)*ratio_2d.y,2*ratio_2d.x,screen_size.y-(font_size.y+2)*ratio_2d.y-window_m*2);
435    rectangle(window_m+2*ratio_2d.x,screen_size.y-ratio_2d.y-window_m,screen_size.x-4*ratio_2d.x-window_m*2,ratio_2d.y);
436    glColor3f(screen_color.x,screen_color.y,screen_color.z);
437    rectangle(window_m+2*ratio_2d.x,window_m+ratio_2d.y,56*ratio_2d.x,font_size.y*ratio_2d.y);
438    rectangle(window_m+60*ratio_2d.x,window_m+2*ratio_2d.y,screen_size.x-115*ratio_2d.x-window_m*2,2*ratio_2d.y);
439    rectangle(window_m+60*ratio_2d.x,window_m+6*ratio_2d.y,screen_size.x-115*ratio_2d.x-window_m*2,2*ratio_2d.y);
440    rectangle(screen_size.x-49*ratio_2d.x-window_m,window_m+ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
441    glColor3f(1.0f,1.0f,1.0f);
442    rectangle(screen_size.x-47*ratio_2d.x-window_m,window_m+2*ratio_2d.y,10*ratio_2d.x,4*ratio_2d.y);
443    glColor3f(0,0,0);
444    rectangle(screen_size.x-45*ratio_2d.x-window_m,window_m+3*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
445    rectangle(screen_size.x-25*ratio_2d.x-window_m,window_m+1*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
446    glColor3f(screen_color.x,screen_color.y,screen_color.z);
447    rectangle(screen_size.x-21*ratio_2d.x-window_m,window_m+2*ratio_2d.y,14*ratio_2d.x,7*ratio_2d.y);
448    glColor3f(1.0f,1.0f,1.0f);
449    rectangle(screen_size.x-19*ratio_2d.x-window_m,window_m+3*ratio_2d.y,10*ratio_2d.x,5*ratio_2d.y);
450    rectangle(screen_size.x-16*ratio_2d.x-window_m,screen_size.y-9*ratio_2d.y-window_m,14*ratio_2d.x,8*ratio_2d.y);
451    glColor3f(screen_color.x,screen_color.y,screen_color.z);
452    rectangle(screen_size.x-14*ratio_2d.x-window_m,screen_size.y-8*ratio_2d.y-window_m,12*ratio_2d.x,7*ratio_2d.y);
453    glColor3f(1.0f,1.0f,1.0f);
454    rectangle(screen_size.x-8*ratio_2d.x-window_m,screen_size.y-8*ratio_2d.y-window_m,8*ratio_2d.x,2*ratio_2d.y);
455    rectangle(screen_size.x-14*ratio_2d.x-window_m,screen_size.y-5*ratio_2d.y-window_m,4*ratio_2d.x,5*ratio_2d.y);
456    rectangle(screen_size.x-12*ratio_2d.x-window_m,screen_size.y-7*ratio_2d.y-window_m,2*ratio_2d.x,1*ratio_2d.y);
457    rectangle(screen_size.x-8*ratio_2d.x-window_m,screen_size.y-5*ratio_2d.y-window_m,4*ratio_2d.x,3*ratio_2d.y);
458    glEnable(GL_BLEND);
459    if(m_polygon) glEnable(GL_TEXTURE_2D);
460    glBlendFunc(GL_ONE, GL_ONE);
461    glVertexPointer(2, GL_INT, 0, shell_vtx);
462    glTexCoordPointer(2, GL_FLOAT, 0, shell_tex);
463    glDrawArrays(GL_QUADS, 0, 4);
464    // draw corner
465    glDisable(GL_TEXTURE_2D);
466    glDisable(GL_BLEND);
467    glVertexPointer(2, GL_INT, 0, corner_vtx);
468    glLoadIdentity();
469    glColor3f(1.0f, 1.0f, 1.0f);
470    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
471    glTranslated(screen_size.x, 0, 0);
472    glRotated(90.0f, 0, 0, 1.0f);
473    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
474    glTranslated(screen_size.y, 0, 0);
475    glRotated(90.0f, 0, 0, 1.0f);
476    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
477    glTranslated(screen_size.x, 0, 0);
478    glRotated(90.0f, 0, 0, 1.0f);
479    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
480    glEnable(GL_BLEND);
481}
482
483void Render::Draw3D()
484{
485    if (!m_shader)
486        return;
487
488    glDisable(GL_DEPTH_TEST);
489    glDisable(GL_BLEND);
490
491    glEnableClientState(GL_VERTEX_ARRAY);
492    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
493
494    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
495    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
496
497    fbo_back->Unbind();
498    if (m_shader_fx && m_shader_blur)
499    {
500        // shader blur horizontal
501        fbo_ping->Bind();
502        shader_blur_h->Bind();
503        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
504        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f));
505        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
506        shader_blur_h->SetUniform(shader_blur_h_value, 0.5f/screen_size.x);
507        fs_quad();
508        shader_blur_h->Unbind();
509        fbo_ping->Unbind();
510        // shader blur vertical
511        fbo_front->Bind();
512        shader_blur_v->Bind();
513        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
514        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f));
515        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
516        shader_blur_v->SetUniform(shader_blur_v_value, 0.5f/screen_size.y);
517        fs_quad();
518        shader_blur_v->Unbind();
519    }
520    else
521    {
522        // shader simple
523        fbo_front->Bind();
524        draw_shader_simple(fbo_back, 0);
525    }
526    fbo_front->Unbind();
527    // shader glow
528    if(m_shader_fx && m_shader_glow)
529    {
530        // shader blur horizontal
531        fbo_blur_h->Bind();
532        shader_blur_h->Bind();
533        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_ping->GetTexture(), 0);
534        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
535        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
536        shader_blur_h->SetUniform(shader_blur_h_value, 2.5f/screen_size.x);
537        fs_quad();
538        shader_blur_h->Unbind();
539        fbo_blur_h->Unbind();
540        // shader blur vertical
541        fbo_blur_v->Bind();
542        shader_blur_v->Bind();
543        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
544        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
545        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
546        shader_blur_v->SetUniform(shader_blur_h_value, 2.5f/screen_size.y);
547        fs_quad();
548        shader_blur_v->Unbind();
549        fbo_blur_v->Unbind();
550        // shader blur horizontal
551        fbo_blur_h->Bind();
552        shader_blur_h->Bind();
553        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
554        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
555        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
556        shader_blur_h->SetUniform(shader_blur_h_value, 1.0f/screen_size.x);
557        fs_quad();
558        shader_blur_h->Unbind();
559        fbo_blur_h->Unbind();
560        // shader blur vertical
561        fbo_blur_v->Bind();
562        shader_blur_v->Bind();
563        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
564        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
565        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
566        shader_blur_v->SetUniform(shader_blur_h_value, 1.0f/screen_size.y);
567        fs_quad();
568        shader_blur_v->Unbind();
569        fbo_blur_v->Unbind();
570        // shader glow
571        fbo_pong->Bind();
572        shader_glow->Bind();
573        shader_glow->SetTexture(shader_glow_texture, fbo_blur_v->GetTexture(), 0);
574        shader_glow->SetTexture(shader_glow_texture_prv, fbo_front->GetTexture(), 1);
575        shader_glow->SetUniform(shader_glow_screen_size, vec2(1.0f));
576        shader_glow->SetUniform(shader_glow_time, fx_angle);
577        shader_glow->SetUniform(shader_glow_step, glow_smoothstep);
578        shader_glow->SetUniform(shader_glow_value1, glow_mix_ratio1);
579        shader_glow->SetUniform(shader_glow_value2, glow_mix_ratio2);
580        fs_quad();
581        shader_glow->Unbind();
582    }
583    if(!m_shader_fx)
584    {
585        // shader simple
586        fbo_pong->Bind();
587        draw_shader_simple(fbo_front, 0);
588    }
589    fbo_pong->Unbind();
590    if(m_shader_postfx)
591    {
592        // shader postfx
593        shader_postfx->Bind();
594        shader_postfx->SetTexture(shader_postfx_texture, fbo_pong->GetTexture(), 0);
595        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
596        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
597        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
598        shader_postfx->SetUniform(shader_postfx_value, 4.0f);
599        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
600        shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline);
601        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
602        fs_quad();
603        shader_postfx->Unbind();
604    }
605    else
606    {
607        // shader simple
608        draw_shader_simple(fbo_pong, 0);
609    }
610
611    glDisableClientState(GL_VERTEX_ARRAY);
612    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
613}
614
615Render::~Render()
616{
617}
Note: See TracBrowser for help on using the repository browser.