source: trunk/tools/neercs/video/render.cpp @ 1736

Last change on this file since 1736 was 1736, checked in by rez, 8 years ago

added TONS of new parameters into the setup menu

File size: 31.8 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#include "text-render.h"
33
34extern char const *lolfx_blurh;
35extern char const *lolfx_blurv;
36extern char const *lolfx_remanency;
37extern char const *lolfx_glow;
38extern char const *lolfx_postfx;
39extern char const *lolfx_radial;
40extern char const *lolfx_simple;
41
42#define PID M_PI/180.0f    // pi ratio
43#define CR 1.0f/256.0f     // color ratio
44
45/*
46 * Various variables
47 */
48
49int active = true;         // window active flag
50float nearplane = 0.1f;    // nearplane
51float farplane = 1000.0f;  // farplane
52int polygon_fillmode = GL_FILL; // fill mode
53/* timer variable */
54float timer = 0;           // timer
55float timer_key = 0;       // key timer
56float timer_key_repeat = 0.25f;// key repeat delay
57/* window variable */
58ivec2 screen_size;         // screen size
59vec3 screen_color = CR * vec3(32, 32, 32); // screen color
60/* object variable */
61float main_angle = 0.0f;   // main angle
62float part_angle = 0.0f;   // part angle
63float fx_angle;            // current angle
64/* fs_quad variable */
65float 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};
66float fs_quad_tex[] = {0, 1.0f, 0, 0, 1.0f, 0, 1.0f, 1.0f};
67/* flash variable */
68bool flash_flag = false;   // flag
69float flash_angle = 0;     // angle
70float flash_value = 0;     // value
71float flash_speed = 1.5f;  // speed
72/* fade variable */
73bool fade_flag = false;    // flag
74float fade_angle = 0;      // angle
75float fade_value = 0;      // value
76float fade_speed = 0.2f;   // speed
77/* sync variable */
78bool sync_flag = false;    // flagsh
79float sync_angle = 0;      // angle
80float sync_value = 1.0f;   // value
81float sync_speed = 1.0f;   // speed
82/* beat variable */
83bool beat_flag = false;    // flag
84float beat_angle = 0;      // angle
85float beat_value = 0;      // value
86float beat_speed = 2.0f;   // speed
87/* window variable */
88ivec2 border;              // border width
89/* text variable */
90ivec2 ratio_2d(2,4);       // 2d ratio
91ivec2 map_size(256,256);   // texture map size
92ivec2 font_size(8,8);      // font size
93ivec2 canvas_char(0,0);    // canvas char number
94ivec2 canvas_size(0,0);    // caca size
95/* setup variable */
96bool setup_switch=false;        // switch [option/item]
97int setup_option=0;             // selected option
98int setup_option_n=9;           // option number
99int setup_item=0;               // selected item
100int setup_item_n=8;             // item number
101int setup_item_key=0;           // item array key
102ivec2 setup_p(1,1);             // position [x,y]
103ivec3 setup_size(30,0,12);      // size [w,h,split]
104ivec2 setup_color(0x678,0x234); // size [w,h]
105char const *setup_text[] = {
106    "remanency",
107        "enable",
108        "buffer new frame",
109        "buffer old frame",
110        "source mix",
111        "buffer mix",
112        "",
113        "",
114        "",
115    "glow",
116        "enable",
117        "source mix",
118        "glow mix",
119        "large center",
120        "large corner",
121        "small center",
122        "small corner",
123        "",
124    "blur",
125        "enable",
126        "blur center",
127        "blur corner",
128        "",
129        "",
130        "",
131        "",
132        "",
133    "screen",
134        "enable",
135        "deform ratio",
136        "zoom base",
137        "zoom variable",
138        "corner radius",
139        "corner blur",
140        "",
141        "",
142    "color",
143        "filter red",
144        "filter green",
145        "filter blue",
146        "brightness",
147        "contrast",
148        "grayscale",
149        "",
150        "",
151    "noise",
152        "offset h",
153        "offset v",
154        "noise",
155        "aberration",
156        "retrace strength",
157        "retrace length",
158        "retrace speed",
159        "",
160    "ghost",
161        "back distance",
162        "back strength",
163        "front distance",
164        "front strength",
165        "",
166        "",
167        "",
168        "",
169    "moire",
170        "h base",
171        "h variable",
172        "h repeat x",
173        "h repeat y",
174        "v base",
175        "v variable",
176        "v repeat x",
177        "v repeat y",
178    "scanline",
179        "h base",
180        "h variable",
181        "h repeat x",
182        "h repeat y",
183        "v base",
184        "v variable",
185        "v repeat x",
186        "v repeat y"
187    };
188/* common variable */
189float value, angle, radius, scale, speed;
190/* shader variable */
191vec2 buffer(0.7f,0.3f);         // [new frame mix,old frame mix]
192vec2 remanency(0.3f,0.7f);      // remanency [source mix,buffer mix]
193vec2 glow_mix(0.6f,0.4f);       // glow mix [source mix,glow mix]
194vec2 glow_large(2.0f,2.0f);     // large glow radius [center,corner]
195vec2 glow_small(1.0f,1.0f);     // small glow radius [center,corner]
196vec2 blur(0.25f,0.5f);          // glow radius [center,corner]
197//vec3 radial(2.0f,0.8f,0);     // radial [mix,strength,color mode]
198//------------------------------// [IDEAS] http://www.youtube.com/watch?v=d1qEP2vMe-I
199vec2 postfx_deform(0.7f,0.54f); // deformation [ratio,zoom]
200vec3 postfx_filter(0.8f,0.9f,0.4f);   // color filter [red,green,blue]
201vec3 postfx_color(1.8f,1.5f,0.5f);    // color modifier [brightness,contrast,grayscale]
202vec2 postfx_corner(0.75f,0.95f);      // corner [radius,blur]
203vec3 postfx_retrace(0.05f,2.0f,4.0f); // retrace [strength,length,speed]
204vec2 postfx_offset(3.0f,3.0f);  // random line [horizontal,vertical]
205float postfx_noise = 0.15f;     // noise
206float postfx_aberration = 3.0f; // chromatic aberration
207vec4 postfx_ghost(0.1f,0.25f,0.1f,0.5f);        // ghost picture [distance,strength,distance,strength]
208vec4 postfx_moire_h(0.75f,-0.25f,0.0f,1.0f);    // vertical moire [base,variable,repeat x,repeat y]
209vec4 postfx_moire_v(0.75f,-0.25f,1.0f,1.5f);    // horizontal moire [base,variable,repeat x,repeat y]
210vec4 postfx_scanline_h(0.75f, 0.25f,0.0f,2.0f); // vertical scanline [base,variable,repeat x,repeat y]
211vec4 postfx_scanline_v(0.75f,-0.25f,2.0f,0.0f); // horizontal scanline [base,variable,repeat x,repeat y]
212//------------------------------//
213vec4 setup_var[]={
214    vec4(0), /* remanency */
215        vec4(0, 1, 1, 1),
216        vec4(0.0f, 1.0f, 0.1f, buffer.x),
217        vec4(0.0f, 1.0f, 0.1f, buffer.y),
218        vec4(0.0f, 1.0f, 0.1f, remanency.x),
219        vec4(0.0f, 1.0f, 0.1f, remanency.y),
220        vec4(0),
221        vec4(0),
222        vec4(0),
223    vec4(0), /* glow */
224        vec4(0, 1, 1, 1),
225        vec4(0.0f, 1.0f, 0.1f, glow_mix.x),
226        vec4(0.0f, 1.0f, 0.1f, glow_mix.y),
227        vec4(0.0f, 4.0f, 0.1f, glow_large.x),
228        vec4(0.0f, 4.0f, 0.1f, glow_large.y),
229        vec4(0.0f, 2.0f, 0.1f, glow_small.x),
230        vec4(0.0f, 2.0f, 0.1f, glow_small.y),
231        vec4(0),
232    vec4(0), /* blur */
233        vec4(0, 1, 1, 1),
234        vec4(0.0f, 2.0f, 0.1f, blur.x),
235        vec4(0.0f, 2.0f, 0.1f, blur.y),
236        vec4(0),
237        vec4(0),
238        vec4(0),
239        vec4(0),
240        vec4(0),
241    vec4(0), /* screen */
242        vec4(0, 1, 1, 1),
243        vec4(0.0f, 1.0f, 0.05f, postfx_deform.x),
244        vec4(0.5f, 0.7f, 0.01f, postfx_deform.y),
245        vec4(0.0f, 1.0f, 0.05f, postfx_corner.x),
246        vec4(0.0f, 1.0f, 0.05f, postfx_corner.y),
247        vec4(0),
248        vec4(0),
249        vec4(0),
250    vec4(0), /* color */
251        vec4(0.0f, 1.0f, 0.1f, postfx_filter.x),
252        vec4(0.0f, 1.0f, 0.1f, postfx_filter.y),
253        vec4(0.0f, 1.0f, 0.1f, postfx_filter.z),
254        vec4(0.0f, 4.0f, 0.1f, postfx_color.x),
255        vec4(0.0f, 4.0f, 0.1f, postfx_color.y),
256        vec4(0.0f, 1.5f, 0.1f, postfx_color.z),
257        vec4(0),
258        vec4(0),
259    vec4(0), /* noise */
260        vec4(0.0f, 4.0f, 0.5f, postfx_offset.x),
261        vec4(0.0f, 4.0f, 0.5f, postfx_offset.y),
262        vec4(0.0f, 1.0f, 0.05f, postfx_noise),
263        vec4(0.0f, 5.0f, 0.5f, postfx_aberration),
264        vec4(0.0f, 0.2f, 0.01f, postfx_retrace.x),
265        vec4(0.0f, 8.0f, 0.5f, postfx_retrace.y),
266        vec4(0.0f, 4.0f, 0.25f, postfx_retrace.z),
267        vec4(0),
268    vec4(0), /* ghost */
269        vec4(0.0f, 0.2f, 0.01f, postfx_ghost.x),
270        vec4(0.0f, 1.0f, 0.05f, postfx_ghost.y),
271        vec4(0.0f, 0.2f, 0.01f, postfx_ghost.z),
272        vec4(0.0f, 1.0f, 0.05f, postfx_ghost.w),
273        vec4(0),
274        vec4(0),
275        vec4(0),
276        vec4(0),
277    vec4(0), /* moire */
278        vec4(0.5f, 1.0f, 0.05f, postfx_moire_h.x),
279        vec4(-0.5f, 0.5f, 0.05f, postfx_moire_h.y),
280        vec4(0.0f, 4.0f, 0.5f, postfx_moire_h.z),
281        vec4(0.0f, 4.0f, 0.5f, postfx_moire_h.w),
282        vec4(0.5f, 1.0f, 0.1f, postfx_moire_v.x),
283        vec4(-0.5f, 0.5f, 0.1f, postfx_moire_v.y),
284        vec4(0.0f, 4.0f, 0.5f, postfx_moire_v.z),
285        vec4(0.0f, 4.0f, 0.5f, postfx_moire_v.w),
286    vec4(0), /* scanline */
287        vec4(0.5f, 1.0f, 0.05f, postfx_scanline_h.x),
288        vec4(-0.5f, 0.5f, 0.05f, postfx_scanline_h.y),
289        vec4(0.0f, 4.0f, 0.5f, postfx_scanline_h.z),
290        vec4(0.0f, 4.0f, 0.5f, postfx_scanline_h.w),
291        vec4(0.5f, 1.0f, 0.1f, postfx_scanline_v.x),
292        vec4(-0.5f, 0.5f, 0.1f, postfx_scanline_v.y),
293        vec4(0.0f, 4.0f, 0.5f, postfx_scanline_v.z),
294        vec4(0.0f, 4.0f, 0.5f, postfx_scanline_v.w),
295    vec4(0)
296    };
297
298void Render::UpdateVar()
299{
300    int k = 1;
301    m_shader_remanency = (setup_var[k].w == 1) ? true : false; k++;
302    buffer = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
303    remanency = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
304    k += 4;
305    m_shader_glow = (setup_var[k].w == 1) ? true : false; k++;
306    glow_mix = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
307    glow_large = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
308    glow_small = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
309    k += 2;
310    m_shader_blur = (setup_var[k].w == 1) ? true : false; k++;
311    blur = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
312    k += 6;
313    m_shader_postfx = (setup_var[k].w == 1) ? true : false; k++;
314    postfx_deform = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
315    postfx_corner = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
316    k += 4;
317    postfx_filter = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
318    postfx_color = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
319    k += 3;
320    postfx_offset = vec2(setup_var[k].w, setup_var[k + 1].w); k += 2;
321    postfx_noise = setup_var[k].w; k++;
322    postfx_aberration = setup_var[k].w; k++;
323    postfx_retrace = vec3(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w); k += 3;
324    k += 2;
325    postfx_ghost = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
326    k += 5;
327    postfx_moire_h = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
328    postfx_moire_v = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
329    k++;
330    postfx_scanline_h = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
331    postfx_scanline_v = vec4(setup_var[k].w, setup_var[k + 1].w, setup_var[k + 2].w, setup_var[k + 3].w); k += 4;
332}
333
334Shader *shader_simple;
335Shader *shader_blur_h, *shader_blur_v;
336Shader *shader_remanency, *shader_glow, *shader_radial, *shader_postfx;
337// shader variables
338ShaderUniform shader_simple_texture;
339ShaderUniform shader_remanency_source,
340              shader_remanency_buffer,
341              shader_remanency_mix;
342ShaderUniform shader_glow_glow,
343              shader_glow_source,
344              shader_glow_mix;
345ShaderUniform shader_blur_h_texture,
346              shader_blur_h_radius,
347              shader_blur_v_texture,
348              shader_blur_v_radius;
349ShaderUniform shader_radial_texture,
350              shader_radial_screen_size,
351              shader_radial_time,
352              shader_radial_value1,
353              shader_radial_value2,
354              shader_radial_color;
355ShaderUniform shader_postfx_texture,
356              shader_postfx_texture_2d,
357              shader_postfx_screen_size,
358              shader_postfx_time,
359              shader_postfx_deform,
360              shader_postfx_ghost,
361              shader_postfx_filter,
362              shader_postfx_color,
363              shader_postfx_corner,
364              shader_postfx_retrace,
365              shader_postfx_offset,
366              shader_postfx_noise,
367              shader_postfx_aberration,
368              shader_postfx_moire_h,
369              shader_postfx_moire_v,
370              shader_postfx_scanline_h,
371              shader_postfx_scanline_v,
372              shader_postfx_flash,
373              shader_postfx_sync;
374
375FrameBuffer *fbo_back, *fbo_front, *fbo_buffer;
376FrameBuffer *fbo_blur_h, *fbo_blur_v, *fbo_ping, *fbo_pong;
377
378TextRender *text_render;
379
380void fs_quad()
381{
382    glLoadIdentity();
383    glDrawArrays(GL_QUADS, 0, 4);
384}
385
386void draw_shader_simple(FrameBuffer *fbo_output, int n)
387{
388    shader_simple->Bind();
389    shader_simple->SetTexture(shader_simple_texture, fbo_output->GetTexture(), n);
390    fs_quad();
391    shader_simple->Unbind();
392}
393
394void rectangle(int x, int y, int w, int h)
395{
396    glLoadIdentity();
397    glBegin(GL_QUADS);
398        glVertex2i(x+w, y  );
399        glVertex2i(x  , y  );
400        glVertex2i(x  , y+h);
401        glVertex2i(x+w, y+h);
402    glEnd();
403}
404
405int Render::InitDraw(void)
406{
407    glDepthMask(GL_TRUE);     // do not write z-buffer
408    glEnable(GL_CULL_FACE);   // disable cull face
409    glCullFace(GL_BACK);      // don't draw front face
410
411    /* Initialise framebuffer objects */
412    fbo_back = new FrameBuffer(screen_size);
413    fbo_front = new FrameBuffer(screen_size);
414    fbo_buffer = new FrameBuffer(screen_size);
415    fbo_blur_h = new FrameBuffer(screen_size);
416    fbo_blur_v = new FrameBuffer(screen_size);
417    fbo_ping = new FrameBuffer(screen_size);
418    fbo_pong = new FrameBuffer(screen_size);
419    // shader simple
420    shader_simple = Shader::Create(lolfx_simple);
421    shader_simple_texture = shader_simple->GetUniformLocation("texture");
422    // shader remanency
423    shader_remanency = Shader::Create(lolfx_remanency);
424    shader_remanency_source = shader_remanency->GetUniformLocation("source");
425    shader_remanency_buffer = shader_remanency->GetUniformLocation("buffer");
426    shader_remanency_mix = shader_remanency->GetUniformLocation("mix");
427    // shader glow
428    shader_glow = Shader::Create(lolfx_glow);
429    shader_glow_glow = shader_glow->GetUniformLocation("glow");
430    shader_glow_source = shader_glow->GetUniformLocation("source");
431    shader_glow_mix = shader_glow->GetUniformLocation("mix");
432    // shader blur horizontal
433    shader_blur_h = Shader::Create(lolfx_blurh);
434    shader_blur_h_texture = shader_blur_h->GetUniformLocation("texture");
435    shader_blur_h_radius = shader_blur_h->GetUniformLocation("radius");
436    // shader blur vertical
437    shader_blur_v = Shader::Create(lolfx_blurv);
438    shader_blur_v_texture = shader_blur_v->GetUniformLocation("texture");
439    shader_blur_v_radius = shader_blur_v->GetUniformLocation("radius");
440    // shader radial
441    shader_radial = Shader::Create(lolfx_radial);
442    shader_radial_texture = shader_radial->GetUniformLocation("texture");
443    shader_radial_screen_size = shader_radial->GetUniformLocation("screen_size");
444    shader_radial_time = shader_radial->GetUniformLocation("time");
445    shader_radial_value1 = shader_radial->GetUniformLocation("value1");
446    shader_radial_value2 = shader_radial->GetUniformLocation("value2");
447    shader_radial_color = shader_radial->GetUniformLocation("color");
448    // shader postfx
449    shader_postfx = Shader::Create(lolfx_postfx);
450    shader_postfx_texture = shader_postfx->GetUniformLocation("texture");
451    shader_postfx_texture_2d = shader_postfx->GetUniformLocation("texture_2d");
452    shader_postfx_screen_size = shader_postfx->GetUniformLocation("screen_size");
453    shader_postfx_time = shader_postfx->GetUniformLocation("time");
454    shader_postfx_deform = shader_postfx->GetUniformLocation("deform");
455    shader_postfx_ghost = shader_postfx->GetUniformLocation("ghost");
456    shader_postfx_filter = shader_postfx->GetUniformLocation("filter");
457    shader_postfx_color = shader_postfx->GetUniformLocation("color");
458    shader_postfx_corner = shader_postfx->GetUniformLocation("corner");
459    shader_postfx_retrace = shader_postfx->GetUniformLocation("retrace");
460    shader_postfx_offset = shader_postfx->GetUniformLocation("offset");
461    shader_postfx_noise = shader_postfx->GetUniformLocation("noise");
462    shader_postfx_aberration = shader_postfx->GetUniformLocation("aberration");
463    shader_postfx_moire_h = shader_postfx->GetUniformLocation("moire_h");
464    shader_postfx_moire_v = shader_postfx->GetUniformLocation("moire_v");
465    shader_postfx_scanline_h = shader_postfx->GetUniformLocation("scanline_h");
466    shader_postfx_scanline_v = shader_postfx->GetUniformLocation("scanline_v");
467    shader_postfx_flash = shader_postfx->GetUniformLocation("flash");
468    shader_postfx_sync = shader_postfx->GetUniformLocation("sync");
469
470    return true;
471}
472
473int Render::CreateGLWindow()
474{
475    screen_size = Video::GetSize();
476    border = 18 * ratio_2d;
477    border.y = border.x; // enabled to get same border everywhere
478    canvas_char = (screen_size - border * 2) / (font_size * ratio_2d);
479    canvas_size = canvas_char * font_size * ratio_2d;
480
481    border = (screen_size - canvas_size) / 2;
482
483    caca_set_canvas_size(m_caca, canvas_char.x, canvas_char.y);
484
485    setup_size.y = ((setup_option_n > setup_item_n) ? setup_option_n : setup_item_n) + 1;
486    setup_p = (canvas_char - setup_size.xy) / 2;
487
488    InitDraw();
489    return true;
490}
491
492Render::Render(caca_canvas_t *caca)
493  : m_caca(caca),
494    m_ready(false),
495    m_pause(false),
496    m_polygon(true),
497    m_setup(true),
498    m_shader(true),
499    m_shader_remanency(true),
500    m_shader_glow(true),
501    m_shader_blur(true),
502    m_shader_postfx(true)
503{
504    text_render = new TextRender(m_caca, font_size);
505}
506
507void Render::TickGame(float seconds)
508{
509    Entity::TickGame(seconds);
510}
511
512void Render::Pause()
513{
514    m_pause=!m_pause;
515}
516
517void Render::TickDraw(float seconds)
518{
519    /* keyboard manager */
520    if (Input::GetButtonState(27/*SDLK_ESCAPE*/))
521        Ticker::Shutdown();
522    if (Input::GetButtonState(282/*SDLK_F1*/) && (timer - timer_key > timer_key_repeat))
523    {
524        m_setup = !m_setup;
525        timer_key = timer;
526    }
527    if (Input::GetButtonState(283/*SDLK_F2*/) && (timer - timer_key > timer_key_repeat))
528    {
529        m_polygon = !m_polygon;
530        polygon_fillmode = (m_polygon)?GL_FILL:GL_LINE;
531        glPolygonMode(GL_FRONT, polygon_fillmode);
532        timer_key = timer;
533    }
534    if (Input::GetButtonState(284/*SDLK_F3*/) && (timer - timer_key > timer_key_repeat))
535    {
536        m_shader_glow = !m_shader_glow;
537        m_shader_blur = !m_shader_blur;
538        timer_key = timer;
539    }
540    if (Input::GetButtonState(285/*SDLK_F4*/)&&(timer-timer_key>timer_key_repeat))
541    {
542        m_shader_postfx = !m_shader_postfx;
543        timer_key = timer;
544    }
545    if (Input::GetButtonState(286/*SDLK_F5*/))
546    {
547        Pause();
548    }
549   if (Input::GetButtonState(9/*SDLK_TAB*/)&&(timer-timer_key>timer_key_repeat))
550    {
551        if (m_setup)
552        {
553            setup_switch = !setup_switch;
554        }
555        timer_key = timer;
556    }
557    if (Input::GetButtonState(273/*SDLK_UP*/)&&(timer-timer_key>timer_key_repeat))
558    {
559        if (m_setup)
560        {
561            if (!setup_switch)
562            {
563                setup_option--;
564                if (setup_option < 0) setup_option = setup_option_n - 1;
565                setup_item = 0;
566            }
567            else
568            {
569                setup_item--;
570                if (setup_item < 0) setup_item = setup_item_n - 1;
571            }
572        }
573        timer_key = timer;
574    }
575    if (Input::GetButtonState(274/*SDLK_DOWN*/)&&(timer-timer_key>timer_key_repeat))
576    {
577        if (m_setup)
578        {
579            if (!setup_switch)
580            {
581                setup_option++;
582                if (setup_option > setup_option_n - 1) setup_option = 0;
583                setup_item = 0;
584            }
585            else
586            {
587                setup_item++;
588                if (setup_item > setup_item_n - 1) setup_item = 0;
589            }
590        }
591        timer_key = timer;
592    }
593    if (Input::GetButtonState(276/*SDLK_LEFT*/)&&(timer-timer_key>timer_key_repeat))
594    {
595        if (m_setup && setup_switch)
596        {
597            setup_var[setup_item_key].w -= setup_var[setup_item_key].z;
598            if (setup_var[setup_item_key].w < setup_var[setup_item_key].x) setup_var[setup_item_key].w = setup_var[setup_item_key].x;
599            Render::UpdateVar();
600        }
601        timer_key = timer;
602    }
603    if (Input::GetButtonState(275/*SDLK_RIGHT*/)&&(timer-timer_key>timer_key_repeat))
604    {
605        if (m_setup && setup_switch)
606        {
607            setup_var[setup_item_key].w += setup_var[setup_item_key].z;
608            if (setup_var[setup_item_key].w > setup_var[setup_item_key].y) setup_var[setup_item_key].w = setup_var[setup_item_key].y;
609            Render::UpdateVar();
610        }
611        timer_key = timer;
612    }
613    if (Input::GetButtonState(13/*SDLK_RETURN*/)&&(timer-timer_key>timer_key_repeat))
614    {
615        timer_key = timer;
616    }
617
618    Entity::TickDraw(seconds);
619
620    if (!m_ready)
621    {
622        CreateGLWindow();
623        text_render->Init();
624        m_ready = true;
625    }
626
627    // timer
628    if (!m_pause)
629    {
630        timer += seconds;
631        main_angle = timer * 100.0f * PID;
632    }
633    if (sync_flag)
634    {
635        angle=(main_angle-sync_angle)*sync_speed;
636        sync_value=1.0f-sinf(angle);
637        if (angle>90.0f*PID)
638        {
639            sync_value=0;
640            sync_flag=false;
641        }
642    }
643    if (beat_flag)
644    {
645        angle=(main_angle-beat_angle)*beat_speed;
646        beat_value=1.0f-sinf(angle);
647        if (angle>90.0f*PID)
648        {
649            beat_value=0;
650            beat_flag=false;
651        }
652    }
653    if (flash_flag)
654    {
655        angle=(main_angle-flash_angle)*flash_speed;
656        flash_value=1.0f-sinf(angle);
657        if (angle>90.0f*PID)
658        {
659            flash_value=0;
660            flash_flag=false;
661        }
662    }
663    if (fade_flag)
664    {
665        angle=(main_angle-fade_angle)*fade_speed;
666        fade_value=1.0f-sinf(angle);
667        if (angle>90.0f*PID)
668        {
669            fade_value=0;
670            fade_flag=false;
671        }
672    }
673    /* draw setup */
674    if (m_setup)
675    {
676        /* background */
677        caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
678        caca_fill_box(m_caca, setup_p.x, setup_p.y, setup_size.x + 1, setup_size.y,' ');
679        caca_draw_line(m_caca, setup_p.x + setup_size.z - 1, setup_p.y + 1, setup_p.x + setup_size.z - 1, setup_p.y + setup_size.y - 1,'|');
680        /* title */
681        caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
682        caca_draw_line(m_caca, setup_p.x, setup_p.y, setup_p.x + setup_size.x, setup_p.y,' ');
683        caca_put_str(m_caca, setup_p.x + setup_size.x / 2 - 3, setup_p.y, "SETUP");
684        /* display option */
685        for (int i = 0; i < setup_option_n; i++)
686        {
687            int y = setup_p.y + 1 + i;
688            int k = i * (setup_item_n + 1);
689            if (setup_option != i || setup_switch)
690            {
691                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
692                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
693            }
694            else
695            {
696                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
697                caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.z - 2, y,' ');
698                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
699            }
700        }
701        /* display item */
702        for (int i = 0; i < setup_item_n; i++)
703        {
704            int y = setup_p.y + 1 + i;
705            int k = setup_option * (setup_item_n + 1) + 1;
706            if (setup_item != i || !setup_switch)
707            {
708                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
709                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
710            }
711            else
712            {
713                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
714                caca_draw_line(m_caca, setup_p.x + setup_size.z, y, setup_p.x + setup_size.x, y,' ');
715                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
716            }
717        }
718        /* display variable */
719        int y = setup_p.y + setup_size.y;
720        setup_item_key = setup_option * (setup_item_n + 1) + 1 + setup_item;
721        caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
722        caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.x, y,' ');
723        if (setup_switch && setup_text[setup_item_key] != "")
724        {
725            int w = setup_size.x - 3 - 4;
726            int bar_w = (w / (setup_var[setup_item_key].y - setup_var[setup_item_key].x) * setup_var[setup_item_key].w);
727            if ((setup_var[setup_item_key].y - setup_var[setup_item_key].x) / setup_var[setup_item_key].z > 2)
728            {
729                caca_printf(m_caca, setup_p.x + setup_size.x - 4, y, "%4.2f", setup_var[setup_item_key].w);
730                caca_draw_line(m_caca, setup_p.x + 1, y, setup_p.x + 1 + w, y,'.');
731                if(setup_var[setup_item_key].w > setup_var[setup_item_key].x) caca_draw_line(m_caca, setup_p.x + 1, y, setup_p.x + 1 + bar_w, y,'x');
732            }
733            else
734            {
735                caca_put_str(m_caca, setup_p.x + setup_size.x - 3, y, (setup_var[setup_item_key].w == setup_var[setup_item_key].y)?"YES":" NO");
736            }
737        }
738    }
739
740    Draw2D();
741    Draw3D();
742
743}
744
745void Render::Draw2D()
746{
747    /* Draw text in an offline buffer */
748    text_render->Render();
749
750    if (m_shader)
751        fbo_back->Bind();
752
753    glViewport(0, 0, screen_size.x, screen_size.y);
754
755    /* Clear the back buffer */
756    glEnable(GL_BLEND);
757    glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
758    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
759    glClearDepth(1.0f); // set depth buffer
760    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
761
762    text_render->Blit(border, canvas_size);
763
764    //if (m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
765    glLineWidth((m_polygon)?2.0f:1.0f);
766    fx_angle=main_angle-part_angle;
767    if (m_polygon)
768        glEnable(GL_TEXTURE_2D);
769
770    glMatrixMode(GL_PROJECTION);
771    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
772    glLoadMatrixf(&m[0][0]);
773    glMatrixMode(GL_MODELVIEW);
774}
775
776void Render::Draw3D()
777{
778    if (!m_shader)
779        return;
780
781    glDisable(GL_DEPTH_TEST);
782    glDisable(GL_BLEND);
783
784    glEnableClientState(GL_VERTEX_ARRAY);
785    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
786
787    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
788    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
789
790    if (m_shader_remanency)
791    {
792        // shader remanency
793        fbo_ping->Bind();
794        shader_remanency->Bind();
795        shader_remanency->SetTexture(shader_remanency_source, fbo_back->GetTexture(), 0);
796        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
797        shader_remanency->SetUniform(shader_remanency_mix, remanency);
798        fs_quad();
799        shader_remanency->Unbind();
800        fbo_ping->Unbind();
801        // shader simple
802        fbo_back->Bind();
803        draw_shader_simple(fbo_ping, 0);
804        fbo_back->Unbind();
805        // save previous fbo
806        fbo_ping->Bind();
807        shader_remanency->Bind();
808        shader_remanency->SetTexture(shader_remanency_source, fbo_front->GetTexture(), 0);
809        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
810        shader_remanency->SetUniform(shader_remanency_mix, buffer);
811        fs_quad();
812        shader_remanency->Unbind();
813        fbo_ping->Unbind();
814        // shader simple
815        fbo_buffer->Bind();
816        draw_shader_simple(fbo_ping, 0);
817        fbo_buffer->Unbind();
818    }
819
820    // shader glow
821    if (m_shader_glow)
822    {
823        // shader blur horizontal
824        fbo_blur_h->Bind();
825        shader_blur_h->Bind();
826        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
827        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
828        fs_quad();
829        shader_blur_h->Unbind();
830        fbo_blur_h->Unbind();
831        // shader blur vertical
832        fbo_blur_v->Bind();
833        shader_blur_v->Bind();
834        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
835        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
836        fs_quad();
837        shader_blur_v->Unbind();
838        fbo_blur_v->Unbind();
839        // shader blur horizontal
840        fbo_blur_h->Bind();
841        shader_blur_h->Bind();
842        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
843        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
844        fs_quad();
845        shader_blur_h->Unbind();
846        fbo_blur_h->Unbind();
847        // shader blur vertical
848        fbo_blur_v->Bind();
849        shader_blur_v->Bind();
850        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
851        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
852        fs_quad();
853        shader_blur_v->Unbind();
854        fbo_blur_v->Unbind();
855        // shader glow
856        fbo_front->Bind();
857        shader_glow->Bind();
858        shader_glow->SetTexture(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
859        shader_glow->SetTexture(shader_glow_source, fbo_back->GetTexture(), 1);
860        shader_glow->SetUniform(shader_glow_mix, glow_mix);
861        fs_quad();
862        shader_glow->Unbind();
863        fbo_front->Unbind();
864    }
865    else
866    {
867        // shader simple
868        fbo_front->Bind();
869        draw_shader_simple(fbo_back, 0);
870        fbo_front->Unbind();
871    }
872
873    if (m_shader_blur)
874    {
875        // shader blur horizontal
876        fbo_ping->Bind();
877        shader_blur_h->Bind();
878        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_front->GetTexture(), 0);
879        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
880        fs_quad();
881        shader_blur_h->Unbind();
882        fbo_ping->Unbind();
883        // shader blur vertical
884        fbo_front->Bind();
885        shader_blur_v->Bind();
886        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
887        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
888        fs_quad();
889        shader_blur_v->Unbind();
890        fbo_front->Unbind();
891    }
892
893    if (m_shader_postfx)
894    {
895        // shader postfx
896        shader_postfx->Bind();
897        shader_postfx->SetTexture(shader_postfx_texture, fbo_front->GetTexture(), 0);
898        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
899        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
900        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
901        shader_postfx->SetUniform(shader_postfx_ghost, postfx_ghost);
902        shader_postfx->SetUniform(shader_postfx_filter, postfx_filter);
903        shader_postfx->SetUniform(shader_postfx_color, postfx_color);
904        shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
905        shader_postfx->SetUniform(shader_postfx_retrace, postfx_retrace);
906        shader_postfx->SetUniform(shader_postfx_offset, postfx_offset);
907        shader_postfx->SetUniform(shader_postfx_noise, postfx_noise);
908        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
909        shader_postfx->SetUniform(shader_postfx_moire_h, postfx_moire_h);
910        shader_postfx->SetUniform(shader_postfx_moire_v, postfx_moire_v);
911        shader_postfx->SetUniform(shader_postfx_scanline_h, postfx_scanline_h);
912        shader_postfx->SetUniform(shader_postfx_scanline_v, postfx_scanline_v);
913        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
914        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
915        fs_quad();
916        shader_postfx->Unbind();
917    }
918    else
919    {
920        // shader simple
921        draw_shader_simple(fbo_front, 0);
922    }
923
924    glDisableClientState(GL_VERTEX_ARRAY);
925    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
926}
927
928Render::~Render()
929{
930}
Note: See TracBrowser for help on using the repository browser.