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

Last change on this file since 1497 was 1497, checked in by sam, 9 years ago

neercs: get rid of useless stuff.

File size: 26.7 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
33extern char const *lolfx_blurh;
34extern char const *lolfx_blurv;
35extern char const *lolfx_glow;
36extern char const *lolfx_postfx;
37extern char const *lolfx_radial;
38extern char const *lolfx_simple;
39extern char const *lolfx_text;
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
45bool done = false;
46
47/*
48 * Various variables
49 */
50
51int keys[256];             // keyboard array
52int active = true;         // window active flag
53bool fullscreen = DEBUG?false:true; // fullscreen flag
54bool paused = false;       // pause flag
55float nearplane = 0.1f;    // nearplane
56float farplane = 1000.0f;  // farplane
57bool polygon = true;       // polygon mode
58int polygon_fillmode = GL_FILL; // fill mode
59/* window variable */
60ivec2 screen_size;         // screen size
61int window_color = 32;     // color depth
62vec3 screen_color = CR * vec3(48, 56, 64); // screen color
63/* object variable */
64float main_angle = 0.0f;   // main angle
65float part_angle = 0.0f;   // part angle
66float fx_angle;            // current angle
67/* text variable */
68char const *name = "cacaShell";
69/* fs_quad variable */
70float 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};
71float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
72/* flash variable */
73bool flash_flag = false;   // flag
74float flash_angle = 0;     // angle
75float flash_value = 0;     // value
76float flash_speed = 1.5f;  // speed
77/* fade variable */
78bool fade_flag = false;    // flag
79float fade_angle = 0;      // angle
80float fade_value = 0;      // value
81float fade_speed = 0.2f;   // speed
82/* sync variable */
83bool sync_flag = false;    // flag
84float sync_angle = 0;      // angle
85float sync_value = 1.0f;   // value
86float sync_speed = 1.0f;   // speed
87/* beat variable */
88bool beat_flag = false;    // flag
89float beat_angle = 0;      // angle
90float beat_value = 0;      // value
91float beat_speed = 2.0f;   // speed
92/* corner variable */
93const int corner_n = 10;   // polygon number
94int corner_w = 24;         // radius
95int corner_vtx[corner_n*6];// vertex array
96/* dos variable */
97bool dos_flag = true;      // flag
98int dos_m;                 // margin
99vec3 dos_color = CR * vec3(48, 56, 64); // color value
100int dos_vtx[8];            // vertex array
101ivec2 ratio_2d(2,4);       // 2d ratio
102ivec2 map_size(256,256);   // texture map size
103ivec2 font_size(8,8);      // font size
104vec2 car_size(1.0f/map_size.x*font_size.x, 1.0f/map_size.y*font_size.y);
105int shell_vtx[8];          // vertex array
106float shell_tex[] = {1.0f, 0.96875f, 1.0f, 1.0f, 0.78125f, 1.0f, 0.78125f, 0.96875f};
107/* keyboard variable */
108int key_code = 0;          // keyboard code
109/* common variable */
110float value, angle, radius, scale, speed;
111TileSet *tex_map;
112/* shader variable */
113bool shader_flag = true;
114bool shader_blur_flag = true;
115bool shader_effect_flag = true;
116bool shader_glow_flag = true;
117bool shader_postfx_flag = true;
118bool shader_radial_flag = false;
119
120int glow_fbo_size = 2;        // glow fbo size
121float glow_smoothstep = 0.0f; // glow smoothstep value (try 0.025f)
122float glow_mix_ratio1 = 0.5f; // glow mixing ratio
123float glow_mix_ratio2 = 0.5f; // source mixing ratio
124
125float radial_value1 = 2.0f;
126float radial_value2 = 0.8f;
127float radial_color = 0;       // color
128
129bool postfx_scanline = true;
130float postfx_deform = 0.5f;   // deformation ratio
131
132Shader *shader_simple, *shader_blur_h, *shader_blur_v;
133Shader *shader_glow, *shader_radial, *shader_postfx;
134// shader variables
135ShaderUniform shader_simple_texture;
136ShaderUniform shader_blur_h_texture,
137              shader_blur_h_screen_size,
138              shader_blur_h_time,
139              shader_blur_h_value;
140ShaderUniform shader_blur_v_texture,
141              shader_blur_v_screen_size,
142              shader_blur_v_time,
143              shader_blur_v_value;
144ShaderUniform shader_glow_texture,
145              shader_glow_texture_prv,
146              shader_glow_screen_size,
147              shader_glow_time,
148              shader_glow_step,
149              shader_glow_value1,
150              shader_glow_value2;
151ShaderUniform shader_radial_texture,
152              shader_radial_screen_size,
153              shader_radial_time,
154              shader_radial_value1,
155              shader_radial_value2,
156              shader_radial_color;
157ShaderUniform shader_postfx_texture,
158              shader_postfx_texture_2d,
159              shader_postfx_screen_size,
160              shader_postfx_time,
161              shader_postfx_flash,
162              shader_postfx_value,
163              shader_postfx_deform,
164              shader_postfx_scanline,
165              shader_postfx_sync;
166
167FrameBuffer *fbo_back, *fbo_front;
168FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
169
170/*
171 * Text rendering interface
172 */
173struct TextRender
174{
175    TextRender(caca_canvas_t *caca, ivec2 font_size)
176      : m_caca(caca),
177        m_font_size(font_size),
178        m_canvas_size(caca_get_canvas_width(m_caca),
179                      caca_get_canvas_height(m_caca)),
180        m_cells(m_canvas_size.x * m_canvas_size.y)
181    {
182        for (int j = 0; j < m_canvas_size.y; j++)
183        for (int i = 0; i < m_canvas_size.x; i++)
184            m_vertices << vec2(i, j);
185    }
186
187    void Init(ivec2 screen_size)
188    {
189        m_shader = Shader::Create(lolfx_text);
190        m_coord = m_shader->GetAttribLocation("in_Position",
191                                              VertexUsage::Position, 0);
192        m_color = m_shader->GetAttribLocation("in_Attr",
193                                              VertexUsage::Color, 0);
194        m_char = m_shader->GetAttribLocation("in_Char",
195                                             VertexUsage::Color, 1);
196        m_texture = m_shader->GetUniformLocation("in_Texture");
197        m_transform = m_shader->GetUniformLocation("in_Transform");
198        m_vdecl
199          = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position),
200                                  VertexStream<uint32_t>(VertexUsage::Color),
201                                  VertexStream<uint32_t>(VertexUsage::Color));
202
203        m_vbo1 = new VertexBuffer(m_vertices.Bytes());
204        void *vertices = m_vbo1->Lock(0, 0);
205        memcpy(vertices, &m_vertices[0], m_vertices.Bytes());
206        m_vbo1->Unlock();
207
208        m_vbo2 = new VertexBuffer(m_cells * sizeof(int32_t));
209        m_vbo3 = new VertexBuffer(m_cells * sizeof(int32_t));
210
211        m_fbo = new FrameBuffer(screen_size);
212    }
213
214    void Render(ivec2 fbo_size)
215    {
216        /* Transform matrix for the scene:
217         *  - translate to the centre of the glyph
218         *  - scale by 2.f * font_size / fbo_size
219         *  - translate to the upper left corner */
220        mat4 xform = mat4::translate(-1.f, 1.f, 0.f)
221                   * mat4::scale(vec3(2.f * m_font_size / (fbo_size), 1.f)
222                                  * vec3(1.f, -1.f, 1.f))
223                   * mat4::translate(0.5f, 0.5f, 0.f);
224
225        /* Upload libcaca canvas contents to the vertex buffers */
226        uint32_t *colors = (uint32_t *)m_vbo2->Lock(0, 0);
227        for (int j = 0; j < m_canvas_size.y; j++)
228        for (int i = 0; i < m_canvas_size.x; i++)
229        {
230            uint32_t attr = caca_get_attr(m_caca, i, j);
231            uint16_t fg = caca_attr_to_rgb12_fg(attr);
232            uint16_t bg = caca_attr_to_rgb12_bg(attr);
233            caca_set_color_argb(m_caca, fg, bg);
234            attr = caca_get_attr(m_caca, -1, -1);
235            caca_put_attr(m_caca, i, j, attr);
236            uint32_t a2 = caca_get_attr(m_caca, i, j);
237        }
238        memcpy(colors, caca_get_canvas_attrs(m_caca),
239               m_cells * sizeof(uint32_t));
240        m_vbo2->Unlock();
241
242        uint32_t *chars = (uint32_t *)m_vbo3->Lock(0, 0);
243        memcpy(chars, caca_get_canvas_chars(m_caca),
244               m_cells * sizeof(uint32_t));
245        m_vbo3->Unlock();
246
247        m_fbo->Bind();
248        glDisable(GL_DEPTH_TEST);
249        glEnable(GL_POINT_SPRITE);
250        //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
251        glDisable(GL_POINT_SMOOTH);
252        glPointSize((float)max(m_font_size.x, m_font_size.y));
253        m_shader->Bind();
254        tex_map->Bind();
255        m_shader->SetUniform(m_texture, 0);
256        m_shader->SetUniform(m_transform, xform);
257        m_vdecl->SetStream(m_vbo1, m_coord);
258        m_vdecl->SetStream(m_vbo2, m_color);
259        m_vdecl->SetStream(m_vbo3, m_char);
260        m_vdecl->Bind();
261        m_vdecl->DrawElements(MeshPrimitive::Points, 0, m_cells);
262        m_vdecl->Unbind();
263        tex_map->Unbind();
264        m_shader->Unbind();
265        glDisable(GL_POINT_SPRITE);
266        m_fbo->Unbind();
267    }
268
269    void Blit(ivec2 fbo_size, ivec2 pos, ivec2 size)
270    {
271        glDisable(GL_BLEND);
272        glEnable(GL_TEXTURE_2D);
273        glBindTexture(GL_TEXTURE_2D, m_fbo->GetTexture());
274        glColor3f(1.0f, 1.0f, 1.0f);
275
276        vec2 tc = (vec2)m_canvas_size * m_font_size / fbo_size;
277
278        glLoadIdentity();
279        glBegin(GL_QUADS);
280            glTexCoord2f(tc.x, 1.0f);
281            glVertex2i(pos.x + size.x, pos.y);
282            glTexCoord2f(0.0f, 1.0f);
283            glVertex2i(pos.x, pos.y);
284            glTexCoord2f(0.0f, 1.0f - tc.y);
285            glVertex2i(pos.x, pos.y + size.y);
286            glTexCoord2f(tc.x, 1.0f - tc.y);
287            glVertex2i(pos.x + size.x, pos.y + size.y);
288        glEnd();
289    }
290
291private:
292    caca_canvas_t *m_caca;
293    ivec2 m_font_size, m_canvas_size;
294    int m_cells;
295
296    Array<vec2> m_vertices;
297    Shader *m_shader;
298    ShaderAttrib m_coord, m_color, m_char;
299    ShaderUniform m_texture, m_transform;
300    VertexDeclaration *m_vdecl;
301    VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3;
302    FrameBuffer *m_fbo;
303};
304
305TextRender *text_render;
306
307void fs_quad()
308{
309    glLoadIdentity();
310    glDrawArrays(GL_QUADS, 0, 4);
311}
312
313void draw_shader_simple(FrameBuffer *fbo_output, int n)
314{
315    shader_simple->Bind();
316    shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n);
317    fs_quad();
318    shader_simple->Unbind();
319}
320
321void rectangle(int x, int y, int w, int h)
322{
323    glLoadIdentity();
324    glBegin(GL_QUADS);
325        glVertex2i(x+w, y  );
326        glVertex2i(x  , y  );
327        glVertex2i(x  , y+h);
328        glVertex2i(x+w, y+h);
329    glEnd();
330}
331
332void corner()
333{
334    float vertex[6+corner_n*2];
335    vertex[0] = 0;
336    vertex[1] = 0;
337    for (int i = 1; i < corner_n + 1; i++)
338    {
339        int j = i*2;
340        float a = PID*90.0f/(corner_n-1)*(i-1);
341        vertex[j  ] = corner_w-corner_w*cosf(a);
342        vertex[j+1] = corner_w-corner_w*sinf(a);
343    }
344    for (int i = 0; i < corner_n; i++)
345    {
346        int j = i*6;
347        int k = i*2;
348        corner_vtx[j  ] = (int)vertex[0];
349        corner_vtx[j+1] = (int)vertex[1];
350        corner_vtx[j+2] = (int)vertex[2+k];
351        corner_vtx[j+3] = (int)vertex[3+k];
352        corner_vtx[j+4] = (int)vertex[4+k];
353        corner_vtx[j+5] = (int)vertex[5+k];
354    }
355}
356
357int InitGL(void)
358{
359    glDepthMask(GL_TRUE);     // do not write z-buffer
360    glEnable(GL_CULL_FACE);   // disable cull face
361    glCullFace(GL_BACK);      // don't draw front face
362
363    // load texture
364    tex_map = new TileSet("neercs/video/resource/map.png",
365                          ivec2(256, 256), ivec2(1));
366
367    if (shader_flag)
368    {
369        /* Initialise framebuffer objects */
370        fbo_back = new FrameBuffer(screen_size);
371        fbo_front = new FrameBuffer(screen_size);
372        fbo_blur_h = new FrameBuffer(screen_size / glow_fbo_size);
373        fbo_blur_v = new FrameBuffer(screen_size / glow_fbo_size);
374        fbo_ping = new FrameBuffer(screen_size);
375        fbo_pong = new FrameBuffer(screen_size);
376        // shader simple
377        shader_simple = Shader::Create(lolfx_simple);
378        shader_simple_texture = shader_simple->GetUniformLocation("texture");
379        // shader blur horizontal
380        shader_blur_h = Shader::Create(lolfx_blurh);
381        shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
382        shader_blur_h_screen_size = shader_blur_h->GetUniformLocation("screen_size");
383        shader_blur_h_time = shader_blur_h->GetUniformLocation("time");
384        shader_blur_h_value = shader_blur_h->GetUniformLocation("value");
385        // shader blur vertical
386        shader_blur_v = Shader::Create(lolfx_blurv);
387        shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
388        shader_blur_v_screen_size = shader_blur_v->GetUniformLocation("screen_size");
389        shader_blur_v_time = shader_blur_v->GetUniformLocation("time");
390        shader_blur_v_value = shader_blur_v->GetUniformLocation("value");
391        // shader glow
392        shader_glow = Shader::Create(lolfx_glow);
393        shader_glow_texture = shader_glow->GetUniformLocation("texture");
394        shader_glow_texture_prv = shader_glow->GetUniformLocation("texture_prv");
395        shader_glow_screen_size = shader_glow->GetUniformLocation("screen_size");
396        shader_glow_time = shader_glow->GetUniformLocation("time");
397        shader_glow_step = shader_glow->GetUniformLocation("step");
398        shader_glow_value1 = shader_glow->GetUniformLocation("value1");
399        shader_glow_value2 = shader_glow->GetUniformLocation("value2");
400        // shader radial
401        shader_radial = Shader::Create(lolfx_radial);
402        shader_radial_texture = shader_radial->GetUniformLocation("texture");
403        shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
404        shader_radial_time = shader_radial->GetUniformLocation("time");
405        shader_radial_value1 = shader_radial->GetUniformLocation("value1");
406        shader_radial_value2 = shader_radial->GetUniformLocation("value2");
407        shader_radial_color = shader_radial->GetUniformLocation("color");
408        // shader postfx
409        shader_postfx = Shader::Create(lolfx_postfx);
410        shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
411        shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
412        shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
413        shader_postfx_time = shader_postfx->GetUniformLocation("time");
414        shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
415        shader_postfx_value = shader_postfx->GetUniformLocation("value");
416        shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
417        shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline");
418        shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
419    }
420
421    return true;
422}
423
424int CreateGLWindow(char const *title)
425{
426    screen_size = Video::GetSize();
427    corner_w = 16*ratio_2d.x;
428    corner();
429    dos_m=12*ratio_2d.x;
430    dos_vtx[0]=font_size.x*ratio_2d.x/2.0f;
431    dos_vtx[1]=font_size.y*ratio_2d.y/2.0f;
432    dos_vtx[2]=font_size.x*ratio_2d.x/2.0f;
433    dos_vtx[3]=-font_size.y*ratio_2d.y/2.0f;
434    dos_vtx[4]=-font_size.x*ratio_2d.x/2.0f;
435    dos_vtx[5]=-font_size.y*ratio_2d.y/2.0f;
436    dos_vtx[6]=-font_size.x*ratio_2d.x/2.0f;
437    dos_vtx[7]=font_size.y*ratio_2d.y/2.0f;
438    shell_vtx[0]=dos_m+58*ratio_2d.x;
439    shell_vtx[1]=dos_m+(font_size.y+1)*ratio_2d.y;
440    shell_vtx[2]=dos_m+58*ratio_2d.x;
441    shell_vtx[3]=dos_m+ratio_2d.y;
442    shell_vtx[4]=dos_m+2*ratio_2d.x;
443    shell_vtx[5]=dos_m+ratio_2d.y;
444    shell_vtx[6]=dos_m+2*ratio_2d.x;
445    shell_vtx[7]=dos_m+(font_size.y+1)*ratio_2d.y;
446    InitGL();
447    return true;
448}
449
450Render::Render(caca_canvas_t *caca)
451  : m_caca(caca),
452    m_ready(false)
453{
454    text_render = new TextRender(m_caca, font_size);
455}
456
457void Render::TickGame(float seconds)
458{
459    Entity::TickGame(seconds);
460}
461
462void Render::TickDraw(float seconds)
463{
464    Entity::TickDraw(seconds);
465
466    if (!m_ready)
467    {
468        CreateGLWindow("LOL");
469        text_render->Init(screen_size);
470
471        m_ready = true;
472    }
473
474    // timer
475    if(!paused)
476        main_angle += seconds * 100.0f * PID;
477    if(sync_flag)
478    {
479        angle=(main_angle-sync_angle)*sync_speed;
480        sync_value=1.0f-sinf(angle);
481        if(angle>90.0f*PID)
482        {
483            sync_value=0;
484            sync_flag=false;
485        }
486    }
487    if(beat_flag)
488    {
489        angle=(main_angle-beat_angle)*beat_speed;
490        beat_value=1.0f-sinf(angle);
491        if(angle>90.0f*PID)
492        {
493            beat_value=0;
494            beat_flag=false;
495        }
496    }
497    if(flash_flag)
498    {
499        angle=(main_angle-flash_angle)*flash_speed;
500        flash_value=1.0f-sinf(angle);
501        if(angle>90.0f*PID)
502        {
503            flash_value=0;
504            flash_flag=false;
505        }
506    }
507    if(fade_flag)
508    {
509        angle=(main_angle-fade_angle)*fade_speed;
510        fade_value=1.0f-sinf(angle);
511        if(angle>90.0f*PID)
512        {
513            fade_value=0;
514            fade_flag=false;
515        }
516    }
517
518    Draw2D();
519    Draw3D();
520}
521
522void Render::Draw2D()
523{
524    /* Draw text in an offline buffer */
525    text_render->Render(screen_size);
526
527    if(shader_flag)
528        fbo_back->Bind();
529
530    /* Clear the back buffer */
531    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
532    glClearDepth(1.0f); // set depth buffer
533    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
534
535    ivec2 border_top = ivec2(dos_m, dos_m + font_size.y * ratio_2d.y)
536                     + ratio_2d * 2;
537    ivec2 border_bottom = ivec2(dos_m * 2, dos_m * 2 + font_size.y * ratio_2d.y)
538                        + ratio_2d * 2;
539    text_render->Blit(screen_size, border_top, screen_size - border_bottom);
540
541    glEnable(GL_BLEND);
542    //if(polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
543    glLineWidth((polygon)?2.0f:1.0f);
544    fx_angle=main_angle-part_angle;
545    if(polygon) glEnable(GL_TEXTURE_2D);
546
547    glViewport(0, 0, screen_size.x, screen_size.y);
548    glMatrixMode(GL_PROJECTION);
549    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
550    glLoadMatrixf(&m[0][0]);
551    glMatrixMode(GL_MODELVIEW);
552
553    tex_map->Bind();
554    glEnable(GL_BLEND);
555    // draw dos
556    if(dos_flag)
557    {
558        glDisable(GL_TEXTURE_2D);
559        glDisable(GL_BLEND);
560        glColor3f(1.0f,1.0f,1.0f);
561        rectangle(dos_m,dos_m,screen_size.x-53*ratio_2d.x-dos_m*2,(font_size.y+2)*ratio_2d.y);
562        rectangle(screen_size.x-51*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
563        rectangle(screen_size.x-27*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
564        rectangle(screen_size.x-3*ratio_2d.x-dos_m,dos_m,3*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
565        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);
566        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);
567        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);
568        glColor3f(dos_color.x,dos_color.y,dos_color.z);
569        rectangle(dos_m+2*ratio_2d.x,dos_m+ratio_2d.y,56*ratio_2d.x,font_size.y*ratio_2d.y);
570        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);
571        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);
572        rectangle(screen_size.x-49*ratio_2d.x-dos_m,dos_m+ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
573        glColor3f(1.0f,1.0f,1.0f);
574        rectangle(screen_size.x-47*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,10*ratio_2d.x,4*ratio_2d.y);
575        glColor3f(0,0,0);
576        rectangle(screen_size.x-45*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
577        rectangle(screen_size.x-25*ratio_2d.x-dos_m,dos_m+1*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
578        glColor3f(dos_color.x,dos_color.y,dos_color.z);
579        rectangle(screen_size.x-21*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,14*ratio_2d.x,7*ratio_2d.y);
580        glColor3f(1.0f,1.0f,1.0f);
581        rectangle(screen_size.x-19*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,10*ratio_2d.x,5*ratio_2d.y);
582        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);
583        glColor3f(dos_color.x,dos_color.y,dos_color.z);
584        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);
585        glColor3f(1.0f,1.0f,1.0f);
586        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);
587        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);
588        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);
589        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);
590        glEnable(GL_BLEND);
591        if(polygon) glEnable(GL_TEXTURE_2D);
592        glBlendFunc(GL_ONE, GL_ONE);
593        glVertexPointer(2, GL_INT, 0, shell_vtx);
594        glTexCoordPointer(2, GL_FLOAT, 0, shell_tex);
595        glDrawArrays(GL_QUADS, 0, 4);
596    }
597    // draw corner
598    glDisable(GL_TEXTURE_2D);
599    glDisable(GL_BLEND);
600    glVertexPointer(2, GL_INT, 0, corner_vtx);
601    glLoadIdentity();
602    glColor3f(0, 0, 0);
603    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
604    glTranslated(screen_size.x, 0, 0);
605    glRotated(90.0f, 0, 0, 1.0f);
606    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
607    glTranslated(screen_size.y, 0, 0);
608    glRotated(90.0f, 0, 0, 1.0f);
609    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
610    glTranslated(screen_size.x, 0, 0);
611    glRotated(90.0f, 0, 0, 1.0f);
612    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
613    glEnable(GL_BLEND);
614    tex_map->Unbind();
615}
616
617void Render::Draw3D()
618{
619    if (!shader_flag)
620        return;
621
622    glDisable(GL_DEPTH_TEST);
623    glDisable(GL_BLEND);
624
625    glEnableClientState(GL_VERTEX_ARRAY);
626    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
627
628    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
629    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
630
631    fbo_back->Unbind();
632    if (shader_effect_flag && shader_blur_flag)
633    {
634        // shader blur horizontal
635        fbo_ping->Bind();
636        shader_blur_h->Bind();
637        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
638        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f));
639        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
640        shader_blur_h->SetUniform(shader_blur_h_value, 0.5f/screen_size.x);
641        fs_quad();
642        shader_blur_h->Unbind();
643        fbo_ping->Unbind();
644        // shader blur vertical
645        fbo_front->Bind();
646        shader_blur_v->Bind();
647        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
648        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f));
649        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
650        shader_blur_v->SetUniform(shader_blur_v_value, 0.5f/screen_size.y);
651        fs_quad();
652        shader_blur_v->Unbind();
653    }
654    else
655    {
656        // shader simple
657        fbo_front->Bind();
658        draw_shader_simple(fbo_back, 0);
659    }
660    fbo_front->Unbind();
661    // shader glow
662    if(shader_effect_flag && shader_glow_flag)
663    {
664        // shader blur horizontal
665        fbo_blur_h->Bind();
666        shader_blur_h->Bind();
667        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_ping->GetTexture(), 0);
668        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
669        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
670        shader_blur_h->SetUniform(shader_blur_h_value, 2.5f/screen_size.x);
671        fs_quad();
672        shader_blur_h->Unbind();
673        fbo_blur_h->Unbind();
674        // shader blur vertical
675        fbo_blur_v->Bind();
676        shader_blur_v->Bind();
677        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
678        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
679        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
680        shader_blur_v->SetUniform(shader_blur_h_value, 2.5f/screen_size.y);
681        fs_quad();
682        shader_blur_v->Unbind();
683        fbo_blur_v->Unbind();
684        // shader blur horizontal
685        fbo_blur_h->Bind();
686        shader_blur_h->Bind();
687        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
688        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
689        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
690        shader_blur_h->SetUniform(shader_blur_h_value, 1.0f/screen_size.x);
691        fs_quad();
692        shader_blur_h->Unbind();
693        fbo_blur_h->Unbind();
694        // shader blur vertical
695        fbo_blur_v->Bind();
696        shader_blur_v->Bind();
697        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
698        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
699        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
700        shader_blur_v->SetUniform(shader_blur_h_value, 1.0f/screen_size.y);
701        fs_quad();
702        shader_blur_v->Unbind();
703        fbo_blur_v->Unbind();
704        // shader glow
705        fbo_pong->Bind();
706        shader_glow->Bind();
707        shader_glow->SetTexture(shader_glow_texture, fbo_blur_v->GetTexture(), 0);
708        shader_glow->SetTexture(shader_glow_texture_prv, fbo_front->GetTexture(), 1);
709        shader_glow->SetUniform(shader_glow_screen_size, vec2(1.0f));
710        shader_glow->SetUniform(shader_glow_time, fx_angle);
711        shader_glow->SetUniform(shader_glow_step, glow_smoothstep);
712        shader_glow->SetUniform(shader_glow_value1, glow_mix_ratio1);
713        shader_glow->SetUniform(shader_glow_value2, glow_mix_ratio2);
714        fs_quad();
715        shader_glow->Unbind();
716    }
717    if(!shader_effect_flag)
718    {
719        // shader simple
720        fbo_pong->Bind();
721        draw_shader_simple(fbo_front, 0);
722    }
723    fbo_pong->Unbind();
724    if(shader_postfx_flag)
725    {
726        // shader postfx
727        shader_postfx->Bind();
728        shader_postfx->SetTexture(shader_postfx_texture, fbo_pong->GetTexture(), 0);
729        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
730        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
731        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
732        shader_postfx->SetUniform(shader_postfx_value, 4.0f);
733        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
734        shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline);
735        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
736        fs_quad();
737        shader_postfx->Unbind();
738    }
739    else
740    {
741        // shader simple
742        draw_shader_simple(fbo_pong, 0);
743    }
744
745    glDisableClientState(GL_VERTEX_ARRAY);
746    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
747}
748
749Render::~Render()
750{
751}
752
Note: See TracBrowser for help on using the repository browser.