Kaynağa Gözat

glsl letterbox and round corner & some new fancy animation!

master
rez Sam Hocevar <sam@hocevar.net> 12 yıl önce
ebeveyn
işleme
466829732a
4 değiştirilmiş dosya ile 58 ekleme ve 69 silme
  1. +27
    -32
      neercs/neercs.cpp
  2. +15
    -26
      neercs/video/postfx.lolfx
  3. +15
    -11
      neercs/video/render.cpp
  4. +1
    -0
      neercs/video/render.h

+ 27
- 32
neercs/neercs.cpp Dosyayı Görüntüle

@@ -71,54 +71,49 @@ void Neercs::TickGame(float seconds)
caca_set_color_argb(m_caca, 0xfff, bg_color);
caca_clear_canvas(m_caca);

caca_set_color_argb(m_caca, 0x444, bg_color);

int n = 16;
int radius = 48;
int speed = 1;
int z = 1;
caca_set_color_argb(m_caca, 0x234, bg_color);
for(int i = 0; i < h; i++)
{
float a = M_PI / 180 * i * 16 + m_time * 4;
float b = M_PI / 180 * i * 12;
int x = w / 2 - 15 + h / 3 * lol::cos(a) + h / 4 * lol::sin(b);
caca_put_str(m_caca, x, i, "LOL WUT! NEERCS SI TEH RULEZ!");
}

for(int i = 0; i < n; i++)
caca_set_color_argb(m_caca, 0x444, bg_color);
for(int i = 0; i < w; i++)
{
//z -= speed;
int r = (radius - i * 4) / z;
int x1 = w / 2 + r * lol::cos(m_time * 2 - M_PI / 20);
int y1 = h / 2 + r * lol::sin(m_time * 2 - M_PI / 20);
int x2 = w / 2 + r * lol::cos(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
int y2 = h / 2 + r * lol::sin(m_time * 2 + M_PI * 2 / 3 - M_PI / 20);
int x3 = w / 2 + r * lol::cos(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
int y3 = h / 2 + r * lol::sin(m_time * 2 + M_PI * 2 / 3 * 2 - M_PI / 20);
caca_set_color_argb(m_caca, 0x642, bg_color);
caca_draw_thin_line(m_caca, x1, y1, x2, y2);
caca_draw_thin_line(m_caca, x2, y2, x3, y3);
caca_draw_thin_line(m_caca, x3, y3, x1, y1);
float a = m_time * 1 + M_PI / 180 * i * 8;
float b = m_time * -2 + M_PI / 180 * i * 5;
int y = h / 2 + h / 4 * lol::cos(a) + h / 4 * lol::sin(b);
caca_draw_line(m_caca, i, y - 1, i, y + 1,'%');
}

/*
.___ __ ______ ______ ______ ______ ______,
\° \| /° __ \° __ \° __ \/° ___//° ___/
/ ` > ____/ ____/ ,_ < <____\___ \
/__/\___\______\______\__| \__\_____________\
/ ` > ____/ ____/ ,_ <_ <____\___ \
/__/\___\______\______\__| \__/_____________\
*/

int logo_x = (w - 46) / 2;
int logo_x = (w - 45) / 2;
int logo_y = h / 2 - 2;

caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * lol::cos(m_time * 3 ),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 )), bg_color);
caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * lol::cos(m_time * 3 ),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 )), bg_color);
caca_put_str(m_caca, logo_x, logo_y ,".___ __ ______ ______ ______ ______ ______,");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * lol::cos(m_time * 3 + M_PI / 4 * 1),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 1)), bg_color);
caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * lol::cos(m_time * 3 + M_PI / 4 * 1),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 1)), bg_color);
caca_put_str(m_caca, logo_x, logo_y + 1, " \\° \\| /° __ \\° __ \\° __ \\/° ___//° ___/");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * lol::cos(m_time * 3 + M_PI / 4 * 2),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 2)), bg_color);
caca_put_str(m_caca, logo_x, logo_y + 2, " / ` > ____/ ____/ ,_ < <____\\___ \\");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.25f * lol::cos(m_time * 3 + M_PI / 4 * 3),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 3)), bg_color);
caca_put_str(m_caca, logo_x, logo_y + 3, "/__/\\___\\______\\______\\__| \\__\\_____________\\");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * lol::cos(m_time * 3 + M_PI / 4 * 2),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 2)), bg_color);
caca_put_str(m_caca, logo_x, logo_y + 2, " / ` > ____/ ____/ ,_ <_ <____\\___ \\");
caca_set_color_argb(m_caca, hex_color(0.5f + 0.375f * lol::cos(m_time * 3 + M_PI / 4 * 3),0.5f,0.5f + 0.25f * lol::sin(m_time * 3 + M_PI / 4 * 3)), bg_color);
caca_put_str(m_caca, logo_x, logo_y + 3, "/__/\\___\\______\\______\\__| \\__/_____________\\");
caca_set_color_argb(m_caca, 0xdef, bg_color);
caca_put_str(m_caca, logo_x + 5, logo_y + 5, "ALL YOUR TERMINALS ARE BELONG TO US");

caca_set_color_ansi(m_caca, 0x666, bg_color);
caca_printf(m_caca, 1, h - 2, "W=%i H=%i", w, h);
//caca_printf(m_caca, 1, h - 2, "2d ratio=%i*%i", ratio_2d.x, ratio_2d.y);
caca_put_str(m_caca, w - 11, h - 2, "CACA RULEZ");
caca_set_color_argb(m_caca, 0x666, bg_color);
caca_put_str(m_caca, w - 10, h - 1, "CACA RULEZ");
caca_printf(m_caca, 0, h - 2, "W=%i", w);
caca_printf(m_caca, 0, h - 1, "H=%i", h);
}




+ 15
- 26
neercs/video/postfx.lolfx Dosyayı Görüntüle

@@ -22,17 +22,16 @@ uniform bool scanline;
uniform float sync;

const float PI=3.14159265358979323846;
float lens=PI/(deform+sync*0.0625);
float lens=deform+sync*0.0625;

vec2 zoom(in vec2 p,in float radius)
{
float zoom=1.5-(radius*cos(p.x*PI/lens)+radius*cos(p.y*PI/lens));
float zoom=1.5-(radius*cos(p.x*lens)+radius*cos(p.y*lens));
return vec2(p.x*zoom-0.5,p.y*zoom-0.5);
}

vec3 get_color(in sampler2D tex,in vec2 p)
{
//return (p.x<-1.0||p.x>0.0||p.y<-1.0||p.y>0.0)?vec3(0.0,0.0,0.0):texture2D(tex,p).xyz; /* old code */
return texture2D(tex,clamp(p,-1.0,0.0)).xyz;
}

@@ -41,30 +40,20 @@ float rand(in vec2 p)
return fract(sin(dot(p.xy,vec2(12.9898,78.233)))*43758.5453);
}

float rounded_square(in vec2 rect,in float r)
float letterbox(in vec2 p,in float radius,in float smooth)
{
vec2 b=rect-vec2(r);
vec2 p=vec2(gl_TexCoord[0].xy-screen_size.xy*0.5);
return length(max(abs(p)-b,0.0))-r;
}

vec3 letterbox(in vec3 c)
{
vec2 rect=screen_size*0.49;
float r=screen_size.x*0.1;
float f=1.0-clamp(rounded_square(rect,r),0.0,1.0);
return c*f;
return 1.0-smoothstep(smooth,1.0,length(max(abs(p*2.0+1.0)+vec2(radius),0.0))-radius);
}

void main(void)
{
vec2 q=gl_TexCoord[0].xy;
vec2 p=-1.0+2.0*gl_TexCoord[0].xy;
vec2 q=gl_FragCoord.xy/screen_size.xy;
vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy;
p.y+=0.025*sync;
vec2 z =zoom(p,0.5250);
vec2 z1=zoom(p,0.5225);
vec2 z2=zoom(p,0.5275);
float g=(2.0-cos(PI/lens/2.0+z.x*PI/lens)-cos(PI/lens/2.0+z.y*PI/lens))*32.0;
float g=(2.0-cos(lens*0.5+z.x*lens)-cos(lens*0.5+z.y*lens))*32.0;

float rnd1=rand(vec2(p.x+time,p.y-time));
float rnd2=rand(vec2(p.x-time,p.y+time));
@@ -88,21 +77,21 @@ void main(void)

vec3 color=source+glass1*glass1*0.25+glass2*glass2*0.25+(scanline?noise:source);

color+=flash; // flash
color+=flash; // flash
if(scanline)
{
color-=0.0125*mod(z.y*4.0+time*0.25,1.0); // electron beam
color-=(vec3(rnd1,rnd1,rnd1)-vec3(rnd2,rnd2,rnd2))*0.1; // noise
color*=0.75+0.25*sin(z.x*float(screen_size.x*2)); // scanline w
color-=0.0125*mod(z.y*4.0+time*0.25,1.0); // electron beam
color-=(vec3(rnd1,rnd1,rnd1)-vec3(rnd2,rnd2,rnd2))*0.1; // noise
color*=0.75+0.25*sin(z.x*float(screen_size.x*2)); // scanline w
color*=0.90+0.10*cos(z.y*float(screen_size.y))*sin(0.5+z.x*float(screen_size.x)); // scanline h
}
else
{
color*=0.675;
}
color=vec3(color.x*0.875,color.y*1.0,color.z*0.625);
color*=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); // vignetting
//color=vec3(1.0,1.0,1.0);
//color=letterbox(color); // letterbox
color=vec3(color.x*0.875,color.y*1.25,color.z*0.5);
color*=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); // vignetting
//color*=2.0*letterbox(z,-0.75,0.125)*2.0; // vignetting
color*=letterbox(z,-0.75,0.975); // letterbox
gl_FragColor=vec4(color,1.0);
}

+ 15
- 11
neercs/video/render.cpp Dosyayı Görüntüle

@@ -52,7 +52,7 @@ int polygon_fillmode = GL_FILL; // fill mode
bool key_state = 0; // key state
/* window variable */
ivec2 screen_size; // screen size
vec3 screen_color = CR * vec3(48, 56, 64); // screen color
vec3 screen_color = CR * vec3(32, 32, 32); // screen color
/* object variable */
float main_angle = 0.0f; // main angle
float part_angle = 0.0f; // part angle
@@ -229,7 +229,7 @@ int Render::InitDraw(void)
int Render::CreateGLWindow()
{
screen_size = Video::GetSize();
border = 10 * ratio_2d;
border = 18 * ratio_2d;
border.y = border.x; // enabled to get same border everywhere
canvas_char = (screen_size - border * 2) / (font_size * ratio_2d);
canvas_size = canvas_char * font_size * ratio_2d;
@@ -251,7 +251,8 @@ Render::Render(caca_canvas_t *caca)
m_shader_blur(true),
m_shader_glow(true),
m_shader_fx(true),
m_shader_postfx(true)
m_shader_postfx(true),
m_border(false)
{
text_render = new TextRender(m_caca, font_size);
}
@@ -375,14 +376,17 @@ void Render::Draw2D()
glLoadMatrixf(&m[0][0]);
glMatrixMode(GL_MODELVIEW);
// draw border
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor3f(1.0f,1.0f,1.0f);
rectangle(border.x - ratio_2d.x, border.y - ratio_2d.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
rectangle(border.x - ratio_2d.x, border.y, ratio_2d.x, canvas_size.y);
rectangle(border.x + canvas_size.x, border.y, ratio_2d.x, canvas_size.y);
rectangle(border.x - ratio_2d.x, border.y + canvas_size.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
glEnable(GL_BLEND);
if(m_border)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor3f(1.0f,1.0f,1.0f);
rectangle(border.x - ratio_2d.x, border.y - ratio_2d.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
rectangle(border.x - ratio_2d.x, border.y, ratio_2d.x, canvas_size.y);
rectangle(border.x + canvas_size.x, border.y, ratio_2d.x, canvas_size.y);
rectangle(border.x - ratio_2d.x, border.y + canvas_size.y, canvas_size.x + ratio_2d.x * 2, ratio_2d.y);
glEnable(GL_BLEND);
}
}

void Render::Draw3D()


+ 1
- 0
neercs/video/render.h Dosyayı Görüntüle

@@ -34,6 +34,7 @@ private:
bool m_shader_glow;
bool m_shader_fx;
bool m_shader_postfx;
bool m_border;
};

#endif // __VIDEO_RENDER_H__


Yükleniyor…
İptal
Kaydet