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

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

neercs: the text rendering object now owns its rendering buffer.

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