From: John Tsiombikas Date: Tue, 3 Sep 2019 10:20:10 +0000 (+0300) Subject: census logo X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=commitdiff_plain;h=22dd4db1a4ff756f76bdd87062c2252fe3091228 census logo --- diff --git a/src/census/3dgfx.c b/src/census/3dgfx.c index 9058d28..a028262 100644 --- a/src/census/3dgfx.c +++ b/src/census/3dgfx.c @@ -585,20 +585,22 @@ void g3d_normal(float x, float y, float z) st->imm_curv.nz = z; } +#define CLAMP(x, a, b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x))) + void g3d_color3b(unsigned char r, unsigned char g, unsigned char b) { - st->imm_curv.r = r; - st->imm_curv.g = g; - st->imm_curv.b = b; + st->imm_curv.r = CLAMP(r, 0, 255); + st->imm_curv.g = CLAMP(g, 0, 255); + st->imm_curv.b = CLAMP(b, 0, 255); st->imm_curv.a = 255; } void g3d_color4b(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { - st->imm_curv.r = r; - st->imm_curv.g = g; - st->imm_curv.b = b; - st->imm_curv.a = a; + st->imm_curv.r = CLAMP(r, 0, 255); + st->imm_curv.g = CLAMP(g, 0, 255); + st->imm_curv.b = CLAMP(b, 0, 255); + st->imm_curv.a = CLAMP(a, 0, 255); } void g3d_color3f(float r, float g, float b) @@ -606,9 +608,9 @@ void g3d_color3f(float r, float g, float b) int ir = r * 255.0f; int ig = g * 255.0f; int ib = b * 255.0f; - st->imm_curv.r = ir > 255 ? 255 : ir; - st->imm_curv.g = ig > 255 ? 255 : ig; - st->imm_curv.b = ib > 255 ? 255 : ib; + st->imm_curv.r = CLAMP(ir, 0, 255); + st->imm_curv.g = CLAMP(ig, 0, 255); + st->imm_curv.b = CLAMP(ib, 0, 255); st->imm_curv.a = 255; } @@ -618,10 +620,10 @@ void g3d_color4f(float r, float g, float b, float a) int ig = g * 255.0f; int ib = b * 255.0f; int ia = a * 255.0f; - st->imm_curv.r = ir > 255 ? 255 : ir; - st->imm_curv.g = ig > 255 ? 255 : ig; - st->imm_curv.b = ib > 255 ? 255 : ib; - st->imm_curv.a = ia > 255 ? 255 : ia; + st->imm_curv.r = CLAMP(ir, 0, 255); + st->imm_curv.g = CLAMP(ig, 0, 255); + st->imm_curv.b = CLAMP(ib, 0, 255); + st->imm_curv.a = CLAMP(ia, 0, 255); } void g3d_texcoord(float u, float v) diff --git a/src/census/census.c b/src/census/census.c index 1755133..724ab2a 100644 --- a/src/census/census.c +++ b/src/census/census.c @@ -1,11 +1,26 @@ #include #include +#include #include "census.h" +#include "logo.h" +#include "timer.h" #include "3dgfx.h" #include "panic.h" +static void draw_disc(float x, float y, float rad, int sub); +static void draw_line(float x0, float y0, float x1, float y1, float rad); + +static int nverts = 256; +static long start_time; + +#define LOOPTIME 1.45f + void init_census(void *pixels, int xsz, int ysz) { + float aspect = (float)xsz / (float)ysz; + + init_logo(0); + fb_pixels = pixels; fb_width = xsz; fb_height = ysz; @@ -13,31 +28,95 @@ void init_census(void *pixels, int xsz, int ysz) g3d_init(); g3d_framebuffer(xsz, ysz, fb_pixels); g3d_polygon_mode(G3D_FLAT); + g3d_viewport(0, 0, xsz, ysz); + g3d_matrix_mode(G3D_PROJECTION); + g3d_load_identity(); + g3d_scale(1.0f / aspect , 1.0f, 1.0f); + + start_time = TICKS_TO_MSEC(nticks); } void draw_census(void) { int i; + long msec = TICKS_TO_MSEC(nticks); + float t = (float)msec / 1000.0f; + float a[2], b[2], dt; + float anim, alpha, center_alpha; + memset(fb_pixels, 0, fb_width * fb_height * 4); - g3d_matrix_mode(G3D_MODELVIEW); - g3d_load_identity(); + anim = fmod(t / 6.0f, LOOPTIME); + alpha = 1.0f - ((anim - (LOOPTIME - 0.075)) / 0.06f); + if(alpha < 0.0f) alpha = 0.0f; + if(alpha > 1.0f) alpha = 1.0f; + + dt = (anim > 1.0f ? 1.0f : anim) / (float)(nverts - 1); + + g3d_color4f(1, 1, 1, alpha); + for(i=0; i 0.0f) { + eval_logo(a, 0); + draw_disc(a[0], a[1], 0.05, 22); + } + if(anim >= 1.0f) { + eval_logo(b, 1); + draw_disc(b[0], b[1], 0.05, 22); + } + + + center_alpha = 2.0 * (anim - 1.0f) / (LOOPTIME - 1.0f); + if(center_alpha > 0.4) { + g3d_color4f(0.8, 0, 0, center_alpha); + draw_disc(0, 0, 0.14, 30); + } - g3d_enable(G3D_BLEND); +} + +static void draw_disc(float x, float y, float rad, int sub) +{ + int i; + float dt = 1.0f / (float)(sub - 1); + float da = dt * M_PI * 2.0; - g3d_color4b(64, 128, 255, 255); - for(i=0; i<2; i++) { - g3d_begin(G3D_QUADS); - g3d_vertex(-0.4, -0.5, 0); - g3d_vertex(0.6, -0.2, 0); - g3d_vertex(0, 0.8, 0); - g3d_vertex(-0.5, 0.6, 0); - g3d_end(); + g3d_begin(G3D_TRIANGLES); + for(i=0; i