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

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

neercs: try to get the point sprite code to work.

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