diff options
author | Bad Diode <bd@badd10de.dev> | 2023-04-17 09:39:36 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2023-04-17 09:39:36 +0200 |
commit | 70d6b8a2cbe4c7343297f466132ac2d7ce1a652d (patch) | |
tree | 8bae2bb8d7ac23adf7dba8a0fb32f5301900de15 | |
parent | 54bf0529ab9e2af55f63890b819ece37ab854194 (diff) | |
download | gba-renderers-70d6b8a2cbe4c7343297f466132ac2d7ce1a652d.tar.gz gba-renderers-70d6b8a2cbe4c7343297f466132ac2d7ce1a652d.zip |
Start updating line drawing to the approach by Tom Forsynth
For more information check:
https://cohost.org/tomforsyth/post/648716-how-to-draw-ugly-lin
-rw-r--r-- | src/renderer_m0.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/renderer_m0.c b/src/renderer_m0.c index 45923e8..94a3d9d 100644 --- a/src/renderer_m0.c +++ b/src/renderer_m0.c | |||
@@ -184,15 +184,27 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { | |||
184 | int x_step = x0 > x1 ? -1 : 1; | 184 | int x_step = x0 > x1 ? -1 : 1; |
185 | int y_step = y0 > y1 ? -1 : 1; | 185 | int y_step = y0 > y1 ? -1 : 1; |
186 | if (dx >= dy) { | 186 | if (dx >= dy) { |
187 | int diff = 2 * dy - dx; | 187 | // int diff = 2 * dy - dx; |
188 | // int distance = dx * dy - (y1 - y0) * dx; | ||
189 | int distance = (dy - dx) / 2; | ||
188 | for (int i = 0; i < dx + 1; i++) { | 190 | for (int i = 0; i < dx + 1; i++) { |
189 | draw_pixel(x0, y0, clr); | 191 | // Previous implementation (Tom Forsyth). |
190 | if (diff >= 0) { | 192 | if (distance > dx / 2) { |
191 | diff -= 2 * dx; | 193 | distance -= dx; |
192 | y0 += y_step; | 194 | y0 += y_step; |
193 | } | 195 | } |
194 | diff += 2 * dy; | 196 | draw_pixel(x0, y0, clr); |
197 | distance += dy; | ||
195 | x0 += x_step; | 198 | x0 += x_step; |
199 | |||
200 | // Previous implementation, slightly faster. | ||
201 | // draw_pixel(x0, y0, clr); | ||
202 | // if (diff >= 0) { | ||
203 | // diff -= 2 * dx; | ||
204 | // y0 += y_step; | ||
205 | // } | ||
206 | // diff += 2 * dy; | ||
207 | // x0 += x_step; | ||
196 | } | 208 | } |
197 | } else { | 209 | } else { |
198 | int diff = 2 * dx - dy; | 210 | int diff = 2 * dx - dy; |