From 0b86e0d8e96ccb313bd8033aec013f29fe8a8b99 Mon Sep 17 00:00:00 2001 From: kkard2 Date: Sat, 6 Sep 2025 14:29:05 +0200 Subject: multiple examples --- README.md | 2 +- example.c | 12 ------------ example.h | 1 + examples/rects.c | 11 +++++++++++ platform_win32.c | 8 +++++--- run.bat | 6 +++--- sponge.h | 12 ++++++------ 7 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 example.c create mode 100644 example.h create mode 100644 examples/rects.c diff --git a/README.md b/README.md index 9481ca7..6abee55 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # windows 1. open folder in developer command prompt for visual studio -2. execute `run` +2. run `run rects.c` diff --git a/example.c b/example.c deleted file mode 100644 index 1ff063c..0000000 --- a/example.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#define SPONGE_IMPLEMENTATION -#include "sponge.h" - -void draw_frame(sponge_Canvas c) { - assert(c.width > 140 + 20); - assert(c.height > 70 + 40); - sponge_clear(c, 0xFF000000); - sponge_draw_rect(c, 80, 70, 80 + 20, 70 + 40, 0xFFFF00FF); - sponge_draw_rect(c, 140, 70, 140 + 20, 70 + 40, 0xFFFF00FF); -} diff --git a/example.h b/example.h new file mode 100644 index 0000000..960c321 --- /dev/null +++ b/example.h @@ -0,0 +1 @@ +void draw_frame(sponge_Texture c); diff --git a/examples/rects.c b/examples/rects.c new file mode 100644 index 0000000..e78ac69 --- /dev/null +++ b/examples/rects.c @@ -0,0 +1,11 @@ +#include + +#include "../sponge.h" + +void draw_frame(sponge_Texture c) { + assert(c.width > 140 + 20); + assert(c.height > 70 + 40); + sponge_clear(c, 0xFF000000); + sponge_draw_rect(c, 80, 70, 80 + 20, 70 + 40, 0xFFFF00FF); + sponge_draw_rect(c, 140, 70, 140 + 20, 70 + 40, 0xFFFF00FF); +} diff --git a/platform_win32.c b/platform_win32.c index d02bbb4..a41b135 100644 --- a/platform_win32.c +++ b/platform_win32.c @@ -1,8 +1,10 @@ #define UNICODE #include -// TODO(kard): we should probably put more thought into this -#include "example.c" +#define SPONGE_IMPLEMENTATION +#include "sponge.h" + +#include "example.h" // TODO(kard): ofc some resizing stuff #define WIDTH 256 @@ -63,7 +65,7 @@ int WinMain( bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; - sponge_Canvas canvas = { + sponge_Texture canvas = { .pixels = pixel_buffer, .width = WIDTH, .height = HEIGHT, diff --git a/run.bat b/run.bat index f6cf655..e5916e5 100644 --- a/run.bat +++ b/run.bat @@ -1,3 +1,3 @@ -del platform_win32.exe -cl platform_win32.c user32.lib gdi32.lib -platform_win32.exe +del out.exe +cl platform_win32.c "examples\%1" user32.lib gdi32.lib /Fe:out.exe +out.exe diff --git a/sponge.h b/sponge.h index a383b0a..6255236 100644 --- a/sponge.h +++ b/sponge.h @@ -1,28 +1,28 @@ #include -// TODO(kard): consider storing pixels buffer size typedef struct { // TODO(kard): define byte order uint32_t *pixels; uint32_t width; uint32_t height; uint32_t stride; -} sponge_Canvas; +} sponge_Texture; -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); +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, uint32_t x1, uint32_t y1, sponge_Texture texture); // TODO(kard): prefix stripping #ifdef SPONGE_IMPLEMENTATION -void sponge_clear(sponge_Canvas c, uint32_t color) { +void sponge_clear(sponge_Texture 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) { +void sponge_draw_rect(sponge_Texture 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) { -- cgit v1.3.1