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

Last change on this file since 1585 was 1585, checked in by rez, 11 years ago

added function key and renamed some variables

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