source: trunk/neercs/video/render.cpp @ 1508

Last change on this file since 1508 was 1508, checked in by rez, 9 years ago

glclear: set opacity to 0.5f

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