diff options
| author | kkard2 <[email protected]> | 2025-09-07 09:29:11 +0200 |
|---|---|---|
| committer | kkard2 <[email protected]> | 2025-09-07 09:29:11 +0200 |
| commit | ab6db2bfd9733552d6c25eaa806858ffed0e388a (patch) | |
| tree | 350f23a0c5b2ba5ff701545e122fefccdba44bbb /sponge.h | |
| parent | c451018c17ce4953a7011fce6cafa55e362e0005 (diff) | |
texture
Diffstat (limited to 'sponge.h')
| -rw-r--r-- | sponge.h | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -1,15 +1,15 @@ #include <stdint.h> typedef struct { - // TODO(kard): define byte order - uint32_t *pixels; + uint32_t *pixels; // AARRGGBB uint32_t width; uint32_t height; uint32_t stride; } sponge_Texture; -void sponge_clear(sponge_Texture c, uint32_t color); -void sponge_draw_rect(sponge_Texture c, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t color); +void sponge_clear (sponge_Texture c, uint32_t color); +void sponge_draw_rect (sponge_Texture c, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t color); +void sponge_draw_texture(sponge_Texture c, uint32_t x0, uint32_t y0, sponge_Texture tex); // TODO(kard): prefix stripping @@ -31,5 +31,24 @@ void sponge_draw_rect(sponge_Texture c, uint32_t x0, uint32_t y0, uint32_t x1, u } } +void sponge_draw_texture(sponge_Texture c, uint32_t x0, uint32_t y0, sponge_Texture tex) { + uint32_t *row_dst = c.pixels + (y0 * c.stride); + uint32_t *row_src = tex.pixels; + uint32_t x1 = x0 + tex.width; + uint32_t y1 = y0 + tex.height; + + if (x1 >= c.width) + x1 = c.width - 1; + if (y1 >= c.height) + y1 = c.height - 1; + + for (uint32_t y = y0; y <= y1; y++, row_src += tex.stride, row_dst += c.stride) { + // TODO(kard): memcpy? + for (uint32_t x = x0, x_src = 0; x <= x1; x++, x_src++) { + row_dst[x] = row_src[x_src]; + } + } +} + #endif // SPONGE_IMPLEMENTATION |
