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

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

added pageup/pagedown shortcut for setup

File size: 32.6 KB
Line 
1//
2// Neercs
3//
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#if defined _XBOX
10#   define _USE_MATH_DEFINES /* for M_PI */
11#   include <xtl.h>
12#elif defined _WIN32
13#   define _USE_MATH_DEFINES /* for M_PI */
14#   define WIN32_LEAN_AND_MEAN
15#   include <windows.h>
16#endif
17
18#include <cmath>
19#include <cstdio>
20#include <cstdlib>
21#include <ctime>
22#include <string>
23
24#include "core.h"
25#include "lolgl.h"
26
27using namespace std;
28using namespace lol;
29
30#include "../neercs.h"
31#include "render.h"
32#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(280/*SDLK_PAGEUP*/)&&(timer-timer_key>timer_key_repeat))
594    {
595        if (m_setup)
596        {
597            if (!setup_switch)
598            {
599                setup_option = 0;
600            }
601            else
602            {
603                setup_item = 0;
604            }
605        }
606        timer_key = timer;
607    }
608    if (Input::GetButtonState(281/*SDLK_PAGEDOWN*/)&&(timer-timer_key>timer_key_repeat))
609    {
610        if (m_setup)
611        {
612            if (!setup_switch)
613            {
614                setup_option = setup_option_n - 1;
615                setup_item = 0;
616            }
617            else
618            {
619                setup_item = setup_item_n - 1;
620            }
621        }
622        timer_key = timer;
623    }
624    if (Input::GetButtonState(276/*SDLK_LEFT*/)&&(timer-timer_key>timer_key_repeat))
625    {
626        if (m_setup && setup_switch)
627        {
628            setup_var[setup_item_key].w -= setup_var[setup_item_key].z;
629            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;
630            Render::UpdateVar();
631        }
632        timer_key = timer;
633    }
634    if (Input::GetButtonState(275/*SDLK_RIGHT*/)&&(timer-timer_key>timer_key_repeat))
635    {
636        if (m_setup && setup_switch)
637        {
638            setup_var[setup_item_key].w += setup_var[setup_item_key].z;
639            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;
640            Render::UpdateVar();
641        }
642        timer_key = timer;
643    }
644    if (Input::GetButtonState(13/*SDLK_RETURN*/)&&(timer-timer_key>timer_key_repeat))
645    {
646        timer_key = timer;
647    }
648
649    Entity::TickDraw(seconds);
650
651    if (!m_ready)
652    {
653        CreateGLWindow();
654        text_render->Init();
655        m_ready = true;
656    }
657
658    // timer
659    if (!m_pause)
660    {
661        timer += seconds;
662        main_angle = timer * 100.0f * PID;
663    }
664    if (sync_flag)
665    {
666        angle=(main_angle-sync_angle)*sync_speed;
667        sync_value=1.0f-sinf(angle);
668        if (angle>90.0f*PID)
669        {
670            sync_value=0;
671            sync_flag=false;
672        }
673    }
674    if (beat_flag)
675    {
676        angle=(main_angle-beat_angle)*beat_speed;
677        beat_value=1.0f-sinf(angle);
678        if (angle>90.0f*PID)
679        {
680            beat_value=0;
681            beat_flag=false;
682        }
683    }
684    if (flash_flag)
685    {
686        angle=(main_angle-flash_angle)*flash_speed;
687        flash_value=1.0f-sinf(angle);
688        if (angle>90.0f*PID)
689        {
690            flash_value=0;
691            flash_flag=false;
692        }
693    }
694    if (fade_flag)
695    {
696        angle=(main_angle-fade_angle)*fade_speed;
697        fade_value=1.0f-sinf(angle);
698        if (angle>90.0f*PID)
699        {
700            fade_value=0;
701            fade_flag=false;
702        }
703    }
704    /* draw setup */
705    if (m_setup)
706    {
707        /* background */
708        caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
709        caca_fill_box(m_caca, setup_p.x, setup_p.y, setup_size.x + 1, setup_size.y,' ');
710        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,'|');
711        /* title */
712        caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
713        caca_draw_line(m_caca, setup_p.x, setup_p.y, setup_p.x + setup_size.x, setup_p.y,' ');
714        caca_put_str(m_caca, setup_p.x + setup_size.x / 2 - 3, setup_p.y, "SETUP");
715        /* display option */
716        for (int i = 0; i < setup_option_n; i++)
717        {
718            int y = setup_p.y + 1 + i;
719            int k = i * (setup_item_n + 1);
720            if (setup_option != i || setup_switch)
721            {
722                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
723                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
724            }
725            else
726            {
727                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
728                caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.z - 2, y,' ');
729                caca_put_str(m_caca, setup_p.x + 1, y, setup_text[k]);
730            }
731        }
732        /* display item */
733        for (int i = 0; i < setup_item_n; i++)
734        {
735            int y = setup_p.y + 1 + i;
736            int k = setup_option * (setup_item_n + 1) + 1;
737            if (setup_item != i || !setup_switch)
738            {
739                caca_set_color_argb(m_caca, setup_color.x, setup_color.y);
740                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
741            }
742            else
743            {
744                caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
745                caca_draw_line(m_caca, setup_p.x + setup_size.z, y, setup_p.x + setup_size.x, y,' ');
746                caca_put_str(m_caca, setup_p.x + setup_size.z + 1, y, setup_text[k + i]);
747            }
748        }
749        /* display variable */
750        int y = setup_p.y + setup_size.y;
751        setup_item_key = setup_option * (setup_item_n + 1) + 1 + setup_item;
752        caca_set_color_argb(m_caca, setup_color.y, setup_color.x);
753        caca_draw_line(m_caca, setup_p.x, y, setup_p.x + setup_size.x, y,' ');
754        if (setup_switch && setup_text[setup_item_key] != "")
755        {
756            int w = setup_size.x - 3 - 4;
757            int bar_w = (w / (setup_var[setup_item_key].y - setup_var[setup_item_key].x) * setup_var[setup_item_key].w);
758            if ((setup_var[setup_item_key].y - setup_var[setup_item_key].x) / setup_var[setup_item_key].z > 2)
759            {
760                caca_printf(m_caca, setup_p.x + setup_size.x - 4, y, "%4.2f", setup_var[setup_item_key].w);
761                caca_draw_line(m_caca, setup_p.x + 1, y, setup_p.x + 1 + w, y,'.');
762                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');
763            }
764            else
765            {
766                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");
767            }
768        }
769    }
770
771    Draw2D();
772    Draw3D();
773
774}
775
776void Render::Draw2D()
777{
778    /* Draw text in an offline buffer */
779    text_render->Render();
780
781    if (m_shader)
782        fbo_back->Bind();
783
784    glViewport(0, 0, screen_size.x, screen_size.y);
785
786    /* Clear the back buffer */
787    glEnable(GL_BLEND);
788    glBlendFunc(GL_SRC_COLOR,GL_DST_ALPHA);
789    glClearColor(screen_color.r, screen_color.g, screen_color.b, 1.0f);
790    glClearDepth(1.0f); // set depth buffer
791    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
792
793    text_render->Blit(border, canvas_size);
794
795    //if (m_polygon) glEnable(GL_LINE_SMOOTH); else glDisable(GL_LINE_SMOOTH);
796    glLineWidth((m_polygon)?2.0f:1.0f);
797    fx_angle=main_angle-part_angle;
798    if (m_polygon)
799        glEnable(GL_TEXTURE_2D);
800
801    glMatrixMode(GL_PROJECTION);
802    mat4 m = mat4::ortho(0, screen_size.x, screen_size.y, 0, -1.f, 1.f);
803    glLoadMatrixf(&m[0][0]);
804    glMatrixMode(GL_MODELVIEW);
805}
806
807void Render::Draw3D()
808{
809    if (!m_shader)
810        return;
811
812    glDisable(GL_DEPTH_TEST);
813    glDisable(GL_BLEND);
814
815    glEnableClientState(GL_VERTEX_ARRAY);
816    glVertexPointer(4, GL_FLOAT, 0, fs_quad_vtx);
817
818    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
819    glTexCoordPointer(2, GL_FLOAT, 0, fs_quad_tex);
820
821    if (m_shader_remanency)
822    {
823        // shader remanency
824        fbo_ping->Bind();
825        shader_remanency->Bind();
826        shader_remanency->SetTexture(shader_remanency_source, fbo_back->GetTexture(), 0);
827        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
828        shader_remanency->SetUniform(shader_remanency_mix, remanency);
829        fs_quad();
830        shader_remanency->Unbind();
831        fbo_ping->Unbind();
832        // shader simple
833        fbo_back->Bind();
834        draw_shader_simple(fbo_ping, 0);
835        fbo_back->Unbind();
836        // save previous fbo
837        fbo_ping->Bind();
838        shader_remanency->Bind();
839        shader_remanency->SetTexture(shader_remanency_source, fbo_front->GetTexture(), 0);
840        shader_remanency->SetTexture(shader_remanency_buffer, fbo_buffer->GetTexture(), 1);
841        shader_remanency->SetUniform(shader_remanency_mix, buffer);
842        fs_quad();
843        shader_remanency->Unbind();
844        fbo_ping->Unbind();
845        // shader simple
846        fbo_buffer->Bind();
847        draw_shader_simple(fbo_ping, 0);
848        fbo_buffer->Unbind();
849    }
850
851    // shader glow
852    if (m_shader_glow)
853    {
854        // shader blur horizontal
855        fbo_blur_h->Bind();
856        shader_blur_h->Bind();
857        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_back->GetTexture(), 0);
858        shader_blur_h->SetUniform(shader_blur_h_radius, glow_large / screen_size.x);
859        fs_quad();
860        shader_blur_h->Unbind();
861        fbo_blur_h->Unbind();
862        // shader blur vertical
863        fbo_blur_v->Bind();
864        shader_blur_v->Bind();
865        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
866        shader_blur_v->SetUniform(shader_blur_v_radius, glow_large / screen_size.y);
867        fs_quad();
868        shader_blur_v->Unbind();
869        fbo_blur_v->Unbind();
870        // shader blur horizontal
871        fbo_blur_h->Bind();
872        shader_blur_h->Bind();
873        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_blur_v->GetTexture(), 0);
874        shader_blur_h->SetUniform(shader_blur_h_radius, glow_small / screen_size.x);
875        fs_quad();
876        shader_blur_h->Unbind();
877        fbo_blur_h->Unbind();
878        // shader blur vertical
879        fbo_blur_v->Bind();
880        shader_blur_v->Bind();
881        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_blur_h->GetTexture(), 0);
882        shader_blur_v->SetUniform(shader_blur_v_radius, glow_small / screen_size.y);
883        fs_quad();
884        shader_blur_v->Unbind();
885        fbo_blur_v->Unbind();
886        // shader glow
887        fbo_front->Bind();
888        shader_glow->Bind();
889        shader_glow->SetTexture(shader_glow_glow, fbo_blur_v->GetTexture(), 0);
890        shader_glow->SetTexture(shader_glow_source, fbo_back->GetTexture(), 1);
891        shader_glow->SetUniform(shader_glow_mix, glow_mix);
892        fs_quad();
893        shader_glow->Unbind();
894        fbo_front->Unbind();
895    }
896    else
897    {
898        // shader simple
899        fbo_front->Bind();
900        draw_shader_simple(fbo_back, 0);
901        fbo_front->Unbind();
902    }
903
904    if (m_shader_blur)
905    {
906        // shader blur horizontal
907        fbo_ping->Bind();
908        shader_blur_h->Bind();
909        shader_blur_h->SetTexture(shader_blur_h_texture, fbo_front->GetTexture(), 0);
910        shader_blur_h->SetUniform(shader_blur_h_radius, blur / screen_size.x);
911        fs_quad();
912        shader_blur_h->Unbind();
913        fbo_ping->Unbind();
914        // shader blur vertical
915        fbo_front->Bind();
916        shader_blur_v->Bind();
917        shader_blur_v->SetTexture(shader_blur_v_texture, fbo_ping->GetTexture(), 0);
918        shader_blur_v->SetUniform(shader_blur_v_radius, blur / screen_size.y);
919        fs_quad();
920        shader_blur_v->Unbind();
921        fbo_front->Unbind();
922    }
923
924    if (m_shader_postfx)
925    {
926        // shader postfx
927        shader_postfx->Bind();
928        shader_postfx->SetTexture(shader_postfx_texture, fbo_front->GetTexture(), 0);
929        shader_postfx->SetUniform(shader_postfx_screen_size, (vec2)screen_size);
930        shader_postfx->SetUniform(shader_postfx_time, fx_angle);
931        shader_postfx->SetUniform(shader_postfx_deform, postfx_deform);
932        shader_postfx->SetUniform(shader_postfx_ghost, postfx_ghost);
933        shader_postfx->SetUniform(shader_postfx_filter, postfx_filter);
934        shader_postfx->SetUniform(shader_postfx_color, postfx_color);
935        shader_postfx->SetUniform(shader_postfx_corner, postfx_corner);
936        shader_postfx->SetUniform(shader_postfx_retrace, postfx_retrace);
937        shader_postfx->SetUniform(shader_postfx_offset, postfx_offset);
938        shader_postfx->SetUniform(shader_postfx_noise, postfx_noise);
939        shader_postfx->SetUniform(shader_postfx_aberration, postfx_aberration);
940        shader_postfx->SetUniform(shader_postfx_moire_h, postfx_moire_h);
941        shader_postfx->SetUniform(shader_postfx_moire_v, postfx_moire_v);
942        shader_postfx->SetUniform(shader_postfx_scanline_h, postfx_scanline_h);
943        shader_postfx->SetUniform(shader_postfx_scanline_v, postfx_scanline_v);
944        shader_postfx->SetUniform(shader_postfx_flash, flash_value);
945        shader_postfx->SetUniform(shader_postfx_sync, (float)fabs(beat_value*cosf((main_angle-beat_angle)*8.0f)));
946        fs_quad();
947        shader_postfx->Unbind();
948    }
949    else
950    {
951        // shader simple
952        draw_shader_simple(fbo_front, 0);
953    }
954
955    glDisableClientState(GL_VERTEX_ARRAY);
956    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
957}
958
959Render::~Render()
960{
961}
Note: See TracBrowser for help on using the repository browser.