From 3e5a38dbf6bc785e73ce127dbd2d9566b2dbf1c2 Mon Sep 17 00:00:00 2001 From: kkard2 Date: Mon, 1 Sep 2025 20:21:40 +0200 Subject: rename to sponge --- sponge.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 sponge.h (limited to 'sponge.h') diff --git a/sponge.h b/sponge.h new file mode 100644 index 0000000..dc50693 --- /dev/null +++ b/sponge.h @@ -0,0 +1,35 @@ +#include + +typedef struct { + // TODO(kard): define byte order + uint32_t *pixels; + uint32_t width; + uint32_t height; + uint32_t stride; +} sponge_Canvas; + +void sponge_clear(sponge_Canvas c, uint32_t color); +void sponge_draw_rect(sponge_Canvas c, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t color); + +// TODO(kard): prefix stripping + +#ifdef SPONGE_IMPLEMENTATION + +void sponge_clear(sponge_Canvas c, uint32_t color) { + sponge_draw_rect(c, 0, 0, c.width - 1, c.height - 1, color); +} + +// TODO(kard): probably bounds checking +// TODO(kard): alpha blending maybe +void sponge_draw_rect(sponge_Canvas c, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t color) { + uint32_t *row = c.pixels + (y0 * c.stride); + + for (uint32_t y = y0; y <= y1; y++, row += c.stride) { + for (uint32_t x = x0; x <= x1; x++) { + row[x] = color; + } + } +} + +#endif // SPONGE_IMPLEMENTATION + -- cgit v1.3.1