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

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

enhanced test screen

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