Open walter76 opened 4 months ago
Works in windows
Fails in Linux
I'm working on a pixel art game and this has been an absolute nightmare. I've tried messing around with different thicknesses and I can never get a perfect rectangle. The problem also extends to drawing simple lines as well, if you try to draw a rectangle out of lines very often the corners will be missing.
I really get the impression that the cause of this bug is weirdness with floating point numbers, maybe it would be appropriate to have a second set of drawing functions that take in integer coordinates?
After quite a bit of experimentation, I've come up with this which seems to render an entire rectangle with corners quite consistently. The main thing is to round all coordinates and then add a small epsilon to the coordinate of the top corner. Here's what I've come up with. It's really dirty, but it gets the job done. Your mileage may vary and this might require some adjustment depending on what you're doing.
let x = x.round();
let y = y.round();
let w = w.round();
let h = h.round();
const EPSILON: f32 = 0.5;
draw_rectangle_lines(x, y, w, h, 1.0, WHITE);
draw_line(x + EPSILON, y + EPSILON, x + w, y, 1.0, WHITE);
draw_line(x + w, y + EPSILON, x + w, y + h, 1.0, WHITE);
draw_line(x + w, y + h, x, y + h, 1.0, WHITE);
draw_line(x + EPSILON, y + h, x, y, 1.0, WHITE);
Since this seems to be a Linux-specific issue (haven't tested on Windows yet), you could wrap this in a Nope, it happens on Windows as well for me.#cfg[(target_os = "linux")]
and then have the normal draw_rectangle_lines
under a #cfg[(target_os = "windows")]
. Hope this helps anyone who is having trouble with this same issue.
idk if this is a good solution but I was able to fix this by changing line 55 in src/shapes.rs
from
let t = thickness / 2.;
,
to
let t = f32::max(thickness / 2., 1.);
just clamping the value of t
to 1.0.
Hi,
I have no idea if this is on purpose, but with macroquad v0.4.5, when I use
draw_rectangle_lines
with a thickness of1.0
I only get half of the rectangle drawn. It works fine with a thickness of2.0
.Code to reproduce:
Sample image:
Is this a bug or does this have to do with some other setting?
/walter