From 90d40f283f6e7a8a1c57849841ddee11f362d95e Mon Sep 17 00:00:00 2001 From: kkard2 Date: Sun, 14 Sep 2025 10:14:08 +0200 Subject: refactored everything procrastination experience --- examples/line.c | 8 ++++---- examples/rainbow.c | 10 +++++----- examples/rects.c | 6 +++--- examples/texture.c | 20 ++++++++++---------- examples/triangles.c | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'examples') diff --git a/examples/line.c b/examples/line.c index 31724a9..71d7492 100644 --- a/examples/line.c +++ b/examples/line.c @@ -10,7 +10,7 @@ static float angle = 0.0f; void init() {} void draw_frame(sponge_Texture c) { - sponge_clear(c, 0xFF000000); + sponge_clear(c, sponge_color32_make(0xFF000000)); angle += SPEED; float x = sinf(angle); @@ -19,7 +19,7 @@ void draw_frame(sponge_Texture c) { sponge_draw_line( c, - half + (int32_t)( x * (float)half), half + (int32_t)( y * (float)half), - half + (int32_t)(-x * (float)half), half + (int32_t)(-y * (float)half), - 0xFFFF00FF); + sponge_vec2i_make(half + (int32_t)( x * (float)half), half + (int32_t)( y * (float)half)), + sponge_vec2i_make(half + (int32_t)(-x * (float)half), half + (int32_t)(-y * (float)half)), + sponge_color32_make(0xFFFF00FF)); } diff --git a/examples/rainbow.c b/examples/rainbow.c index 31657ff..8439b0b 100644 --- a/examples/rainbow.c +++ b/examples/rainbow.c @@ -15,10 +15,10 @@ void draw_frame(sponge_Texture c) { float gf = (sinf(angle + (PI * 2.0f / 3.0f)) + 1.0f) * 255.0f / 2.0f; float bf = (sinf(angle + (PI * 4.0f / 3.0f)) + 1.0f) * 255.0f / 2.0f; - int r = (((int)rf) & 0xFF) << 16; - int g = (((int)gf) & 0xFF) << 8; - int b = (((int)bf) & 0xFF) << 0; - - uint32_t color = 0xFF000000 | r | g | b; + sponge_Color32 color; + color.a = 0xFF; + color.r = (((int)rf) & 0xFF); + color.g = (((int)gf) & 0xFF); + color.b = (((int)bf) & 0xFF); sponge_clear(c, color); } diff --git a/examples/rects.c b/examples/rects.c index 293f833..48cf5ba 100644 --- a/examples/rects.c +++ b/examples/rects.c @@ -7,7 +7,7 @@ void init() {} 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); + sponge_clear(c, sponge_color32_make(0xFF000000)); + sponge_draw_rect(c, sponge_vec2i_make(80, 70), sponge_vec2i_make(80 + 20, 70 + 40), sponge_color32_make(0xFFFF00FF)); + sponge_draw_rect(c, sponge_vec2i_make(140, 70), sponge_vec2i_make(140 + 20, 70 + 40), sponge_color32_make(0xFFFF00FF)); } diff --git a/examples/texture.c b/examples/texture.c index d6bee54..6467efe 100644 --- a/examples/texture.c +++ b/examples/texture.c @@ -20,16 +20,16 @@ void init() { assert(0); } - texture.stride = texture.width; - texture.pixels = (uint32_t *)data; // NOTE(kard): be careful if changing following loop + texture.stride_pixels = texture.width; + texture.pixels = (sponge_Color32 *)data; // NOTE(kard): be careful if changing following loop - // converting from stbi's RGBA to ARGB + // converting from stbi's RGBA for (size_t i = 0; i < texture.width * texture.height; i++) { - uint32_t result = 0; - result |= data[i * 4 + 0] << 16; // R - result |= data[i * 4 + 1] << 8; // G - result |= data[i * 4 + 2] << 0; // B - result |= data[i * 4 + 3] << 24; // A + sponge_Color32 result; + result.r = data[i * 4 + 0]; + result.g = data[i * 4 + 1]; + result.b = data[i * 4 + 2]; + result.a = data[i * 4 + 3]; texture.pixels[i] = result; } @@ -40,7 +40,7 @@ void init() { } void draw_frame(sponge_Texture c) { - sponge_clear(c, 0xFF000000); + sponge_clear(c, sponge_color32_make(0xFF000000)); pos_x += speed_x; pos_y += speed_y; @@ -59,5 +59,5 @@ void draw_frame(sponge_Texture c) { speed_y = -SPEED_Y_ABS; } - sponge_draw_texture(c, pos_x, pos_y, texture); + sponge_draw_texture(c, sponge_vec2i_make(pos_x, pos_y), texture); } diff --git a/examples/triangles.c b/examples/triangles.c index f995574..8515a28 100644 --- a/examples/triangles.c +++ b/examples/triangles.c @@ -31,7 +31,7 @@ void draw_frame(sponge_Texture c) { c, x, y + offset_y, x + offset_x, y, - x + (offset_x / 4), y + (offset_y / 4), + x + (offset_x * 3 / 4), y + (offset_y * 3 / 4), 0xFFFF0000, 0xFF00FF00, 0xFF0000FF); } } -- cgit v1.3.1