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

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

replacement of PI #define by M_PI

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