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

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

neercs: minor vertex buffer usage optimisation.

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