diff options
| author | kkard2 <[email protected]> | 2025-09-06 14:29:05 +0200 |
|---|---|---|
| committer | kkard2 <[email protected]> | 2025-09-06 14:29:05 +0200 |
| commit | 0b86e0d8e96ccb313bd8033aec013f29fe8a8b99 (patch) | |
| tree | fc9dbb02a66c12fbc450e18030ce6607372d79dc | |
| parent | ccda453a9095f1643fabcbb4befd148fa0d0d34e (diff) | |
multiple examples
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | example.h | 1 | ||||
| -rw-r--r-- | examples/rects.c (renamed from example.c) | 5 | ||||
| -rw-r--r-- | platform_win32.c | 8 | ||||
| -rw-r--r-- | run.bat | 6 | ||||
| -rw-r--r-- | sponge.h | 12 |
6 files changed, 18 insertions, 16 deletions
@@ -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.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/example.c b/examples/rects.c index 1ff063c..e78ac69 100644 --- a/example.c +++ b/examples/rects.c @@ -1,9 +1,8 @@ #include <assert.h> -#define SPONGE_IMPLEMENTATION -#include "sponge.h" +#include "../sponge.h" -void draw_frame(sponge_Canvas c) { +void draw_frame(sponge_Texture c) { assert(c.width > 140 + 20); assert(c.height > 70 + 40); sponge_clear(c, 0xFF000000); 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 <windows.h> -// 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, @@ -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 @@ -1,28 +1,28 @@ #include <stdint.h> -// 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) { |
