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

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

neercs: improve the point sprite rendering routine.

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