diff options
author | quou <quou@disroot.org> | 2024-07-14 00:18:56 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-07-14 00:18:56 +1000 |
commit | 86c4c02743726edd01b9878f3640129815704390 (patch) | |
tree | a00dace5be2967434411d7e2a61ad6b61031ec5c | |
parent | e2b3f2486875ca7e3eeadd8767ebaec28e711745 (diff) |
Add a little font too
-rw-r--r-- | 3de.c | 6 | ||||
-rw-r--r-- | render.c | 98 | ||||
-rw-r--r-- | render.h | 14 |
3 files changed, 92 insertions, 26 deletions
@@ -80,11 +80,11 @@ int entrypoint(int argc, const char** argv, Arena* a) { ren_clear(&r); ren_cleard(&r, f1 * 300); sprintf(buf, "FPS: %d", app->fps); - ren_text(&r, blue, 3, 3, buf); + ren_texts(&r, blue, 3, 3, buf); sprintf(buf, "CAP: %d", f.fps); - ren_text(&r, blue, 3, 13, buf); + ren_texts(&r, blue, 3, 8, buf); sprintf(buf, "MOUSE: %d, %d", app->mx, app->my); - ren_text(&r, blue, 3, 23, buf); + ren_texts(&r, blue, 3, 13, buf); draw_monkey(&r); ren_end(&r); app_end(app); @@ -66,6 +66,21 @@ static unsigned font_data[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0003c01e, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; +static int smol_font_w = 384; +static unsigned smol_font_data[] = { + 0x2296a520, 0x40000524, 0x77757767, 0x60002077, + 0x6773637e, 0x69b15475, 0x95576767, 0x02616755, + 0x66640102, 0x00021421, 0x00020000, 0xf0326000, + 0x2543e520, 0x20002242, 0x41152645, 0x92740277, + 0x1135175d, 0x9bf13427, 0x95523595, 0x05422272, + 0x72d66364, 0x73f25003, 0x95576677, 0xfa6233a9, + 0x06267000, 0x20727542, 0x27674145, 0x44022045, + 0x53151571, 0x9d915525, 0xf55243d7, 0x00422122, + 0x47351550, 0x55d23425, 0xb5522277, 0xf5222266, + 0x0b935020, 0x12022024, 0x277437e7, 0x42742277, + 0x61736756, 0x69975775, 0xb27235e1, 0x70646725, + 0x32666370, 0x75945625, 0xf2763241, 0xf0326639, +}; Colour make_colour(unsigned rgb, unsigned char a) { Colour r; @@ -181,6 +196,31 @@ void ren_point(Renderer* r, Colour c, int x, int y) { r->t[x + y * r->w] = c; } +#define imp_ren_char(chw, chh, fw, data) \ + int i, j, k, l, ex, ey, s; \ + Colour* dst; \ + Rect re = { 0, 0, chw, chh }; \ + Rect sub = { 0, 0, chh, chh }; \ + re.x = x; \ + re.y = y; \ + sub.x = (ch - ' ') * chw; \ + rect_clips(&re, &sub, &r->clip); \ + ex = re.x + re.w; \ + ey = re.y + re.h; \ + dst = r->t + (re.x + re.y * r->w); \ + s = r->w - re.w; \ + for (j = re.y, l = sub.y; j < ey; j++, l++) { \ + for (i = re.x, k = sub.x; i < ex; i++, k++) { \ + int si = k + l * fw; \ + unsigned bits = data[si >> 5]; \ + int bit = bits & 1 << (si & 0x1f); \ + if (bit) \ + *dst = blend(*dst, c); \ + dst++; \ + } \ + dst += s; \ + } + void ren_char( Renderer* r, Colour c, @@ -188,31 +228,31 @@ void ren_char( int y, char ch ) { - int i, j, k, l, ex, ey, s; - Colour* dst; - Rect re = { 0, 0, 10, 10 }; - Rect sub = { 0, 0, 10, 10 }; - re.x = x; - re.y = y; - sub.x = (ch - ' ') * 10; - rect_clips(&re, &sub, &r->clip); - ex = re.x + re.w; - ey = re.y + re.h; - dst = r->t + (re.x + re.y * r->w); - s = r->w - re.w; - for (j = re.y, l = sub.y; j < ey; j++, l++) { - for (i = re.x, k = sub.x; i < ex; i++, k++) { - int si = k + l * font_w; - unsigned bits = font_data[si >> 5]; - int bit = bits & 1 << (si & 0x1f); - if (bit) - *dst = blend(*dst, c); - dst++; - } - dst += s; - } + imp_ren_char( + 10, + 10, + font_w, + font_data + ); } +void ren_chars( + Renderer* r, + Colour c, + int x, + int y, + char ch +) { + imp_ren_char( + 4, + 4, + smol_font_w, + smol_font_data + ); +} + +#undef imp_ren_char + void ren_text( Renderer* r, Colour c, @@ -225,6 +265,18 @@ void ren_text( ren_char(r, c, x, y, *s); } +void ren_texts( + Renderer* r, + Colour c, + int x, + int y, + const char* t +) { + const char* s; + for (s = t; *s; s++, x += 5) + ren_chars(r, c, x, y, *s); +} + void swap_vert(int* a, int* b, int ec) { int t, i; for (i = 0; i < ec; i++) { @@ -55,6 +55,13 @@ void ren_char( int y, char ch ); +void ren_chars( + Renderer* r, + Colour c, + int x, + int y, + char ch +); void ren_text( Renderer* r, Colour c, @@ -62,6 +69,13 @@ void ren_text( int y, const char* t ); +void ren_texts( + Renderer* r, + Colour c, + int x, + int y, + const char* t +); /* Vertex format: * x y z u v r g b * All fixed point values with 9 bits of precision. |