From d30d4c2c3832c1e4df1d4fb266b04ca4dfdd828b Mon Sep 17 00:00:00 2001 From: kkard2 Date: Sun, 14 Sep 2025 12:14:31 +0200 Subject: make examples more future proof (like if i want input and stuff) --- example.h | 9 +++++++++ examples/line.c | 4 ++-- examples/rainbow.c | 4 ++-- examples/rects.c | 4 ++-- examples/texture.c | 3 +++ examples/triangle.c | 4 ++-- examples/triangles.c | 4 ++-- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/example.h b/example.h index 9769c84..5c34ea1 100644 --- a/example.h +++ b/example.h @@ -1,2 +1,11 @@ void init(); void draw_frame(sponge_Texture c); + + +#ifdef SPONGE_EXAMPLE_IMPLEMENTATION + +#ifndef SPONGE_EXAMPLE_INIT_DEFINED +void init() {} +#endif // SPONGE_EXAMPLE_INIT_DEFINED + +#endif // SPONGE_EXAMPLE_IMPLEMENTATION diff --git a/examples/line.c b/examples/line.c index 71d7492..c190717 100644 --- a/examples/line.c +++ b/examples/line.c @@ -1,14 +1,14 @@ #include #include "../sponge.h" +#define SPONGE_EXAMPLE_IMPLEMENTATION +#include "../example.h" #define PI ((float)3.14159265358979323846) #define SPEED (0.5f / 360.0f * 2 * PI) static float angle = 0.0f; #define MIN(x, y) ((x) < (y) ? (x) : (y)) -void init() {} - void draw_frame(sponge_Texture c) { sponge_clear(c, sponge_color32_make(0xFF000000)); angle += SPEED; diff --git a/examples/rainbow.c b/examples/rainbow.c index 8439b0b..dac2fae 100644 --- a/examples/rainbow.c +++ b/examples/rainbow.c @@ -1,13 +1,13 @@ #include #include "../sponge.h" +#define SPONGE_EXAMPLE_IMPLEMENTATION +#include "../example.h" #define PI ((float)3.14159265358979323846) #define SPEED (2.0f / 360.0f * 2 * PI) static float angle = 0.0f; -void init() {} - void draw_frame(sponge_Texture c) { angle += SPEED; diff --git a/examples/rects.c b/examples/rects.c index 48cf5ba..5b12e40 100644 --- a/examples/rects.c +++ b/examples/rects.c @@ -1,8 +1,8 @@ #include #include "../sponge.h" - -void init() {} +#define SPONGE_EXAMPLE_IMPLEMENTATION +#include "../example.h" void draw_frame(sponge_Texture c) { assert(c.width > 140 + 20); diff --git a/examples/texture.c b/examples/texture.c index 6467efe..80388f7 100644 --- a/examples/texture.c +++ b/examples/texture.c @@ -1,6 +1,9 @@ #include #include "../sponge.h" +#define SPONGE_EXAMPLE_IMPLEMENTATION +#define SPONGE_EXAMPLE_INIT_DEFINED +#include "../example.h" #include "../stb_image.h" #define SPEED_X_ABS 2 diff --git a/examples/triangle.c b/examples/triangle.c index a3559e9..9e20b90 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -1,10 +1,10 @@ #include "../sponge.h" +#define SPONGE_EXAMPLE_IMPLEMENTATION +#include "../example.h" #define SPEED (4) static int32_t offset = 0; -void init() {} - void draw_frame(sponge_Texture c) { sponge_clear(c, sponge_color32_make(0xFF000000)); offset += SPEED; diff --git a/examples/triangles.c b/examples/triangles.c index 271de5f..63a2ca9 100644 --- a/examples/triangles.c +++ b/examples/triangles.c @@ -1,4 +1,6 @@ #include "../sponge.h" +#define SPONGE_EXAMPLE_IMPLEMENTATION +#include "../example.h" #define SPEED_ABS (2) #define GRID_SIZE (10) @@ -7,8 +9,6 @@ static int32_t offset = 0; static int32_t speed = SPEED_ABS; -void init() {} - void draw_frame(sponge_Texture c) { sponge_clear(c, sponge_color32_make(0xFF000000)); offset += speed; -- cgit v1.3.1