aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-09-23 21:11:29 +1000
committerquou <quou@disroot.org>2024-09-23 21:11:29 +1000
commit259237fae792e8f19d9b7920b2354f75bc1789e2 (patch)
treeaf079430f30f7df1b76efc4f96f520b0b6eee0af /render.c
initial commit, basic platform and rendering code.
Diffstat (limited to 'render.c')
-rw-r--r--render.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/render.c b/render.c
new file mode 100644
index 0000000..34416c0
--- /dev/null
+++ b/render.c
@@ -0,0 +1,97 @@
+#include "rect.h"
+#include "render.h"
+
+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
+};
+
+void ren_begin(Renderer* r, unsigned* t, int w, int h) {
+ r->t = t;
+ r->w = w;
+ r->h = h;
+ r->clip[0] = 0;
+ r->clip[1] = 0;
+ r->clip[2] = w;
+ r->clip[3] = h;
+}
+
+void ren_end(Renderer* r) {
+ (void)r;
+}
+
+void ren_clear(Renderer* r) {
+ int e = r->w * r->h >> 5, i;
+ for (i = 0; i < e; i++)
+ r->t[i] = 0;
+}
+
+void ren_char(Renderer* r, int x, int y, char ch) {
+ Rect re, su;
+ int i, j, sx, sy, ex, ey;
+ re.x = x;
+ re.y = y;
+ re.w = 4;
+ re.h = 4;
+ su.x = (ch - ' ') * 4;
+ su.y = 0;
+ su.w = 4;
+ su.h = 4;
+ rect_clipsr(&re, &su, r->clip);
+ ex = re.x + re.w;
+ ey = re.y + re.h;
+ for (j = re.y, sy = su.y; j < ey; j++, sy++) {
+ for (i = re.x, sx = su.x; i < ex; i++, sx++) {
+ int di = (i + j * r->w);
+ int si = (sx + sy * smol_font_w);
+ int bit = (1 << (si & 0x1f));
+ bit &= smol_font_data[si >> 5];
+ r->t[di >> 5] ^= (1 << (di & 0x1f)) * (bit != 0);
+ }
+ }
+}
+
+void ren_text(Renderer* r, int x, int y, const char* t) {
+ for (; *t; t++, x += 4)
+ ren_char(r, x, y, *t);
+}
+
+void ren_map(
+ Renderer* r,
+ int x,
+ int y,
+ const Rect* re,
+ const Bitmap* bm
+) {
+ Rect rect, su = *re;
+ const unsigned* data = (const unsigned*)&bm[1];
+ int i, j, sx, sy, ex, ey;
+ rect.x = x;
+ rect.y = y;
+ rect.w = re->w;
+ rect.h = re->h;
+ rect_clipsr(&rect, &su, r->clip);
+ ex = rect.x + rect.w;
+ ey = rect.y + rect.h;
+ for (j = rect.y, sy = su.y; j < ey; j++, sy++) {
+ for (i = rect.x, sx = su.x; i < ex; i++, sx++) {
+ int di = (i + j * r->w);
+ int si = (sx + sy * bm->w);
+ int bit = (1 << (si & 0x1f));
+ bit &= data[si >> 5];
+ r->t[di >> 5] ^= (1 << (di & 0x1f)) * (bit != 0);
+ }
+ }
+}
+