From 770f7a569c1617f3e7590f04221c1f69e430024d Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 18 Oct 2025 17:43:22 +0100 Subject: [PATCH] Fix wrapping --- renderer.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/renderer.c b/renderer.c index a413217..1cc42a5 100644 --- a/renderer.c +++ b/renderer.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -31,9 +30,7 @@ static void page_flip_handler(int, unsigned, unsigned, unsigned, void *) static void set_pixel(uint32_t x, uint32_t y) { - x %= width; - y %= height; - const uint32_t offset = y * (fbs[back].pitch / 4) + x; + const uint32_t offset = y * (fbs[back].pitch / 4) + x; fbs[back].buf[offset] = 0xff'ff'ff; } @@ -45,8 +42,22 @@ static void draw_line(vec3_t v1, vec3_t v2) if (step != 0.0) { const float step_x = delta_x / step; const float step_y = delta_y / step; - for (unsigned i = 0; i <= step; ++i) - set_pixel(roundf(v1.x + i * step_x), roundf(v1.y + i * step_y)); + + for (unsigned i = 0; i <= step; ++i) { + float x = roundf(v1.x + i * step_x); + if (x >= width) + x -= width; + else if (x < 0) + x += width; + + float y = roundf(v1.y + i * step_y); + if (y >= height) + y -= height; + else if (y < 0) + y += height; + + set_pixel(x, y); + } } else { set_pixel(roundf(v1.x), roundf(v1.y)); }