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

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

neercs: move texture loading to the TextRender object.

File size: 26.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
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
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
166/*
167 * Text rendering interface
168 */
169struct TextRender
170{
171    TextRender(caca_canvas_t *caca, ivec2 font_size)
172      : m_caca(caca),
173        m_font_size(font_size),
174        m_canvas_size(caca_get_canvas_width(m_caca),
175                      caca_get_canvas_height(m_caca)),
176        m_cells(m_canvas_size.x * m_canvas_size.y)
177    {
178        for (int j = 0; j < m_canvas_size.y; j++)
179        for (int i = 0; i < m_canvas_size.x; i++)
180            m_vertices << vec2(i, j);
181    }
182
183    void Init(ivec2 screen_size)
184    {
185        m_font = new TileSet("neercs/video/resource/map.png",
186                             ivec2(256, 256), ivec2(1));
187
188        m_shader = Shader::Create(lolfx_text);
189        m_coord = m_shader->GetAttribLocation("in_Position",
190                                              VertexUsage::Position, 0);
191        m_color = m_shader->GetAttribLocation("in_Attr",
192                                              VertexUsage::Color, 0);
193        m_char = m_shader->GetAttribLocation("in_Char",
194                                             VertexUsage::Color, 1);
195        m_texture = m_shader->GetUniformLocation("in_Texture");
196        m_transform = m_shader->GetUniformLocation("in_Transform");
197        m_vdecl
198          = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position),
199                                  VertexStream<uint32_t>(VertexUsage::Color),
200                                  VertexStream<uint32_t>(VertexUsage::Color));
201
202        m_vbo1 = new VertexBuffer(m_vertices.Bytes());
203        void *vertices = m_vbo1->Lock(0, 0);
204        memcpy(vertices, &m_vertices[0], m_vertices.Bytes());
205        m_vbo1->Unlock();
206
207        m_vbo2 = new VertexBuffer(m_cells * sizeof(int32_t));
208        m_vbo3 = new VertexBuffer(m_cells * sizeof(int32_t));
209
210        m_fbo = new FrameBuffer(screen_size);
211    }
212
213    void Render(ivec2 fbo_size)
214    {
215        /* Transform matrix for the scene:
216         *  - translate to the centre of the glyph
217         *  - scale by 2.f * font_size / fbo_size
218         *  - translate to the upper left corner */
219        mat4 xform = mat4::translate(-1.f, 1.f, 0.f)
220                   * mat4::scale(vec3(2.f * m_font_size / (fbo_size), 1.f)
221                                  * vec3(1.f, -1.f, 1.f))
222                   * mat4::translate(0.5f, 0.5f, 0.f);
223
224        /* Upload libcaca canvas contents to the vertex buffers */
225        uint32_t *colors = (uint32_t *)m_vbo2->Lock(0, 0);
226        for (int j = 0; j < m_canvas_size.y; j++)
227        for (int i = 0; i < m_canvas_size.x; i++)
228        {
229            uint32_t attr = caca_get_attr(m_caca, i, j);
230            uint16_t fg = caca_attr_to_rgb12_fg(attr);
231            uint16_t bg = caca_attr_to_rgb12_bg(attr);
232            caca_set_color_argb(m_caca, fg, bg);
233            attr = caca_get_attr(m_caca, -1, -1);
234            caca_put_attr(m_caca, i, j, attr);
235            uint32_t a2 = caca_get_attr(m_caca, i, j);
236        }
237        memcpy(colors, caca_get_canvas_attrs(m_caca),
238               m_cells * sizeof(uint32_t));
239        m_vbo2->Unlock();
240
241        uint32_t *chars = (uint32_t *)m_vbo3->Lock(0, 0);
242        memcpy(chars, caca_get_canvas_chars(m_caca),
243               m_cells * sizeof(uint32_t));
244        m_vbo3->Unlock();
245
246        m_fbo->Bind();
247        glDisable(GL_DEPTH_TEST);
248        glEnable(GL_POINT_SPRITE);
249        //glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
250        glDisable(GL_POINT_SMOOTH);
251        glPointSize((float)max(m_font_size.x, m_font_size.y));
252        m_shader->Bind();
253        m_font->Bind();
254        m_shader->SetUniform(m_texture, 0);
255        m_shader->SetUniform(m_transform, xform);
256        m_vdecl->SetStream(m_vbo1, m_coord);
257        m_vdecl->SetStream(m_vbo2, m_color);
258        m_vdecl->SetStream(m_vbo3, m_char);
259        m_vdecl->Bind();
260        m_vdecl->DrawElements(MeshPrimitive::Points, 0, m_cells);
261        m_vdecl->Unbind();
262        m_font->Unbind();
263        m_shader->Unbind();
264        glDisable(GL_POINT_SPRITE);
265        m_fbo->Unbind();
266    }
267
268    void Blit(ivec2 fbo_size, ivec2 pos, ivec2 size)
269    {
270        glDisable(GL_BLEND);
271        glEnable(GL_TEXTURE_2D);
272        glBindTexture(GL_TEXTURE_2D, m_fbo->GetTexture());
273        glColor3f(1.0f, 1.0f, 1.0f);
274
275        vec2 tc = (vec2)m_canvas_size * m_font_size / fbo_size;
276
277        glLoadIdentity();
278        glBegin(GL_QUADS);
279            glTexCoord2f(tc.x, 1.0f);
280            glVertex2i(pos.x + size.x, pos.y);
281            glTexCoord2f(0.0f, 1.0f);
282            glVertex2i(pos.x, pos.y);
283            glTexCoord2f(0.0f, 1.0f - tc.y);
284            glVertex2i(pos.x, pos.y + size.y);
285            glTexCoord2f(tc.x, 1.0f - tc.y);
286            glVertex2i(pos.x + size.x, pos.y + size.y);
287        glEnd();
288    }
289
290private:
291    caca_canvas_t *m_caca;
292    ivec2 m_font_size, m_canvas_size;
293    int m_cells;
294
295    Array<vec2> m_vertices;
296    TileSet *m_font;
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    if (shader_flag)
364    {
365        /* Initialise framebuffer objects */
366        fbo_back = new FrameBuffer(screen_size);
367        fbo_front = new FrameBuffer(screen_size);
368        fbo_blur_h = new FrameBuffer(screen_size / glow_fbo_size);
369        fbo_blur_v = new FrameBuffer(screen_size / glow_fbo_size);
370        fbo_ping = new FrameBuffer(screen_size);
371        fbo_pong = new FrameBuffer(screen_size);
372        // shader simple
373        shader_simple = Shader::Create(lolfx_simple);
374        shader_simple_texture = shader_simple->GetUniformLocation("texture");
375        // shader blur horizontal
376        shader_blur_h = Shader::Create(lolfx_blurh);
377        shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
378        shader_blur_h_screen_size = shader_blur_h->GetUniformLocation("screen_size");
379        shader_blur_h_time = shader_blur_h->GetUniformLocation("time");
380        shader_blur_h_value = shader_blur_h->GetUniformLocation("value");
381        // shader blur vertical
382        shader_blur_v = Shader::Create(lolfx_blurv);
383        shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
384        shader_blur_v_screen_size = shader_blur_v->GetUniformLocation("screen_size");
385        shader_blur_v_time = shader_blur_v->GetUniformLocation("time");
386        shader_blur_v_value = shader_blur_v->GetUniformLocation("value");
387        // shader glow
388        shader_glow = Shader::Create(lolfx_glow);
389        shader_glow_texture = shader_glow->GetUniformLocation("texture");
390        shader_glow_texture_prv = shader_glow->GetUniformLocation("texture_prv");
391        shader_glow_screen_size = shader_glow->GetUniformLocation("screen_size");
392        shader_glow_time = shader_glow->GetUniformLocation("time");
393        shader_glow_step = shader_glow->GetUniformLocation("step");
394        shader_glow_value1 = shader_glow->GetUniformLocation("value1");
395        shader_glow_value2 = shader_glow->GetUniformLocation("value2");
396        // shader radial
397        shader_radial = Shader::Create(lolfx_radial);
398        shader_radial_texture = shader_radial->GetUniformLocation("texture");
399        shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
400        shader_radial_time = shader_radial->GetUniformLocation("time");
401        shader_radial_value1 = shader_radial->GetUniformLocation("value1");
402        shader_radial_value2 = shader_radial->GetUniformLocation("value2");
403        shader_radial_color = shader_radial->GetUniformLocation("color");
404        // shader postfx
405        shader_postfx = Shader::Create(lolfx_postfx);
406        shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
407        shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
408        shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
409        shader_postfx_time = shader_postfx->GetUniformLocation("time");
410        shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
411        shader_postfx_value = shader_postfx->GetUniformLocation("value");
412        shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
413        shader_postfx_scanline = shader_postfx->GetUniformLocation("scanline");
414        shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
415    }
416
417    return true;
418}
419
420int CreateGLWindow(char const *title)
421{
422    screen_size = Video::GetSize();
423    corner_w = 16*ratio_2d.x;
424    corner();
425    dos_m=12*ratio_2d.x;
426    dos_vtx[0]=font_size.x*ratio_2d.x/2.0f;
427    dos_vtx[1]=font_size.y*ratio_2d.y/2.0f;
428    dos_vtx[2]=font_size.x*ratio_2d.x/2.0f;
429    dos_vtx[3]=-font_size.y*ratio_2d.y/2.0f;
430    dos_vtx[4]=-font_size.x*ratio_2d.x/2.0f;
431    dos_vtx[5]=-font_size.y*ratio_2d.y/2.0f;
432    dos_vtx[6]=-font_size.x*ratio_2d.x/2.0f;
433    dos_vtx[7]=font_size.y*ratio_2d.y/2.0f;
434    shell_vtx[0]=dos_m+58*ratio_2d.x;
435    shell_vtx[1]=dos_m+(font_size.y+1)*ratio_2d.y;
436    shell_vtx[2]=dos_m+58*ratio_2d.x;
437    shell_vtx[3]=dos_m+ratio_2d.y;
438    shell_vtx[4]=dos_m+2*ratio_2d.x;
439    shell_vtx[5]=dos_m+ratio_2d.y;
440    shell_vtx[6]=dos_m+2*ratio_2d.x;
441    shell_vtx[7]=dos_m+(font_size.y+1)*ratio_2d.y;
442    InitGL();
443    return true;
444}
445
446Render::Render(caca_canvas_t *caca)
447  : m_caca(caca),
448    m_ready(false)
449{
450    text_render = new TextRender(m_caca, font_size);
451}
452
453void Render::TickGame(float seconds)
454{
455    Entity::TickGame(seconds);
456}
457
458void Render::TickDraw(float seconds)
459{
460    Entity::TickDraw(seconds);
461
462    if (!m_ready)
463    {
464        CreateGLWindow("LOL");
465        text_render->Init(screen_size);
466
467        m_ready = true;
468    }
469
470    // timer
471    if(!paused)
472        main_angle += seconds * 100.0f * PID;
473    if(sync_flag)
474    {
475        angle=(main_angle-sync_angle)*sync_speed;
476        sync_value=1.0f-sinf(angle);
477        if(angle>90.0f*PID)
478        {
479            sync_value=0;
480            sync_flag=false;
481        }
482    }
483    if(beat_flag)
484    {
485        angle=(main_angle-beat_angle)*beat_speed;
486        beat_value=1.0f-sinf(angle);
487        if(angle>90.0f*PID)
488        {
489            beat_value=0;
490            beat_flag=false;
491        }
492    }
493    if(flash_flag)
494    {
495        angle=(main_angle-flash_angle)*flash_speed;
496        flash_value=1.0f-sinf(angle);
497        if(angle>90.0f*PID)
498        {
499            flash_value=0;
500            flash_flag=false;
501        }
502    }
503    if(fade_flag)
504    {
505        angle=(main_angle-fade_angle)*fade_speed;
506        fade_value=1.0f-sinf(angle);
507        if(angle>90.0f*PID)
508        {
509            fade_value=0;
510            fade_flag=false;
511        }
512    }
513
514    Draw2D();
515    Draw3D();
516}
517
518void Render::Draw2D()
519{
520    /* Draw text in an offline buffer */
521    text_render->Render(screen_size);
522
523    if(shader_flag)
524        fbo_back->Bind();
525
526    /* Clear the back buffer */
527    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
528    glClearDepth(1.0f); // set depth buffer
529    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
530
531    ivec2 border_top = ivec2(dos_m, dos_m + font_size.y * ratio_2d.y)
532                     + ratio_2d * 2;
533    ivec2 border_bottom = ivec2(dos_m * 2, dos_m * 2 + font_size.y * ratio_2d.y)
534                        + ratio_2d * 2;
535    text_render->Blit(screen_size, border_top, screen_size - border_bottom);
536
537    glEnable(GL_BLEND);
538    //if(polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
539    glLineWidth((polygon)?2.0f:1.0f);
540    fx_angle=main_angle-part_angle;
541    if(polygon) glEnable(GL_TEXTURE_2D);
542
543    glViewport(0, 0, screen_size.x, screen_size.y);
544    glMatrixMode(GL_PROJECTION);
545    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
546    glLoadMatrixf(&m[0][0]);
547    glMatrixMode(GL_MODELVIEW);
548
549    glEnable(GL_BLEND);
550    // draw dos
551    if(dos_flag)
552    {
553        glDisable(GL_TEXTURE_2D);
554        glDisable(GL_BLEND);
555        glColor3f(1.0f,1.0f,1.0f);
556        rectangle(dos_m,dos_m,screen_size.x-53*ratio_2d.x-dos_m*2,(font_size.y+2)*ratio_2d.y);
557        rectangle(screen_size.x-51*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
558        rectangle(screen_size.x-27*ratio_2d.x-dos_m,dos_m,22*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
559        rectangle(screen_size.x-3*ratio_2d.x-dos_m,dos_m,3*ratio_2d.x,(font_size.y+2)*ratio_2d.y);
560        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);
561        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);
562        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);
563        glColor3f(dos_color.x,dos_color.y,dos_color.z);
564        rectangle(dos_m+2*ratio_2d.x,dos_m+ratio_2d.y,56*ratio_2d.x,font_size.y*ratio_2d.y);
565        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);
566        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);
567        rectangle(screen_size.x-49*ratio_2d.x-dos_m,dos_m+ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
568        glColor3f(1.0f,1.0f,1.0f);
569        rectangle(screen_size.x-47*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,10*ratio_2d.x,4*ratio_2d.y);
570        glColor3f(0,0,0);
571        rectangle(screen_size.x-45*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
572        rectangle(screen_size.x-25*ratio_2d.x-dos_m,dos_m+1*ratio_2d.y,14*ratio_2d.x,6*ratio_2d.y);
573        glColor3f(dos_color.x,dos_color.y,dos_color.z);
574        rectangle(screen_size.x-21*ratio_2d.x-dos_m,dos_m+2*ratio_2d.y,14*ratio_2d.x,7*ratio_2d.y);
575        glColor3f(1.0f,1.0f,1.0f);
576        rectangle(screen_size.x-19*ratio_2d.x-dos_m,dos_m+3*ratio_2d.y,10*ratio_2d.x,5*ratio_2d.y);
577        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);
578        glColor3f(dos_color.x,dos_color.y,dos_color.z);
579        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);
580        glColor3f(1.0f,1.0f,1.0f);
581        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);
582        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);
583        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);
584        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);
585        glEnable(GL_BLEND);
586        if(polygon) glEnable(GL_TEXTURE_2D);
587        glBlendFunc(GL_ONE, GL_ONE);
588        glVertexPointer(2, GL_INT, 0, shell_vtx);
589        glTexCoordPointer(2, GL_FLOAT, 0, shell_tex);
590        glDrawArrays(GL_QUADS, 0, 4);
591    }
592    // draw corner
593    glDisable(GL_TEXTURE_2D);
594    glDisable(GL_BLEND);
595    glVertexPointer(2, GL_INT, 0, corner_vtx);
596    glLoadIdentity();
597    glColor3f(0, 0, 0);
598    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
599    glTranslated(screen_size.x, 0, 0);
600    glRotated(90.0f, 0, 0, 1.0f);
601    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
602    glTranslated(screen_size.y, 0, 0);
603    glRotated(90.0f, 0, 0, 1.0f);
604    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
605    glTranslated(screen_size.x, 0, 0);
606    glRotated(90.0f, 0, 0, 1.0f);
607    glDrawArrays(GL_TRIANGLES, 0, corner_n*3);
608    glEnable(GL_BLEND);
609}
610
611void Render::Draw3D()
612{
613    if (!shader_flag)
614        return;
615
616    glDisable(GL_DEPTH_TEST);
617    glDisable(GL_BLEND);
618
619    glEnableClientState(GL_VERTEX_ARRAY);
620    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
621
622    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
623    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
624
625    fbo_back->Unbind();
626    if (shader_effect_flag && shader_blur_flag)
627    {
628        // shader blur horizontal
629        fbo_ping->Bind();
630        shader_blur_h->Bind();
631        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
632        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f));
633        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
634        shader_blur_h->SetUniform(shader_blur_h_value, 0.5f/screen_size.x);
635        fs_quad();
636        shader_blur_h->Unbind();
637        fbo_ping->Unbind();
638        // shader blur vertical
639        fbo_front->Bind();
640        shader_blur_v->Bind();
641        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
642        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f));
643        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
644        shader_blur_v->SetUniform(shader_blur_v_value, 0.5f/screen_size.y);
645        fs_quad();
646        shader_blur_v->Unbind();
647    }
648    else
649    {
650        // shader simple
651        fbo_front->Bind();
652        draw_shader_simple(fbo_back, 0);
653    }
654    fbo_front->Unbind();
655    // shader glow
656    if(shader_effect_flag && shader_glow_flag)
657    {
658        // shader blur horizontal
659        fbo_blur_h->Bind();
660        shader_blur_h->Bind();
661        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_ping->GetTexture(), 0);
662        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
663        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
664        shader_blur_h->SetUniform(shader_blur_h_value, 2.5f/screen_size.x);
665        fs_quad();
666        shader_blur_h->Unbind();
667        fbo_blur_h->Unbind();
668        // shader blur vertical
669        fbo_blur_v->Bind();
670        shader_blur_v->Bind();
671        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
672        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
673        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
674        shader_blur_v->SetUniform(shader_blur_h_value, 2.5f/screen_size.y);
675        fs_quad();
676        shader_blur_v->Unbind();
677        fbo_blur_v->Unbind();
678        // shader blur horizontal
679        fbo_blur_h->Bind();
680        shader_blur_h->Bind();
681        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
682        shader_blur_h->SetUniform(shader_blur_h_screen_size, vec2(1.0f / glow_fbo_size));
683        shader_blur_h->SetUniform(shader_blur_h_time, fx_angle);
684        shader_blur_h->SetUniform(shader_blur_h_value, 1.0f/screen_size.x);
685        fs_quad();
686        shader_blur_h->Unbind();
687        fbo_blur_h->Unbind();
688        // shader blur vertical
689        fbo_blur_v->Bind();
690        shader_blur_v->Bind();
691        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
692        shader_blur_v->SetUniform(shader_blur_v_screen_size, vec2(1.0f / glow_fbo_size));
693        shader_blur_v->SetUniform(shader_blur_v_time, fx_angle);
694        shader_blur_v->SetUniform(shader_blur_h_value, 1.0f/screen_size.y);
695        fs_quad();
696        shader_blur_v->Unbind();
697        fbo_blur_v->Unbind();
698        // shader glow
699        fbo_pong->Bind();
700        shader_glow->Bind();
701        shader_glow->SetTexture(shader_glow_texture, fbo_blur_v->GetTexture(), 0);
702        shader_glow->SetTexture(shader_glow_texture_prv, fbo_front->GetTexture(), 1);
703        shader_glow->SetUniform(shader_glow_screen_size, vec2(1.0f));
704        shader_glow->SetUniform(shader_glow_time, fx_angle);
705        shader_glow->SetUniform(shader_glow_step, glow_smoothstep);
706        shader_glow->SetUniform(shader_glow_value1, glow_mix_ratio1);
707        shader_glow->SetUniform(shader_glow_value2, glow_mix_ratio2);
708        fs_quad();
709        shader_glow->Unbind();
710    }
711    if(!shader_effect_flag)
712    {
713        // shader simple
714        fbo_pong->Bind();
715        draw_shader_simple(fbo_front, 0);
716    }
717    fbo_pong->Unbind();
718    if(shader_postfx_flag)
719    {
720        // shader postfx
721        shader_postfx->Bind();
722        shader_postfx->SetTexture(shader_postfx_texture, fbo_pong->GetTexture(), 0);
723        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
724        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
725        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
726        shader_postfx->SetUniform(shader_postfx_value, 4.0f);
727        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
728        shader_postfx->SetUniform(shader_postfx_scanline, postfx_scanline);
729        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
730        fs_quad();
731        shader_postfx->Unbind();
732    }
733    else
734    {
735        // shader simple
736        draw_shader_simple(fbo_pong, 0);
737    }
738
739    glDisableClientState(GL_VERTEX_ARRAY);
740    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
741}
742
743Render::~Render()
744{
745}
746
Note: See TracBrowser for help on using the repository browser.