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

Last change on this file since 1461 was 1461, checked in by sam, 10 years ago

neercs: fix the rendering pipeline by disabling depth test and passing
the correct arguments to mat4::ortho().

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