Page 1 of 1

love.draw.line - line width is one pixel too wide

Posted: Sun Apr 19, 2020 4:34 pm
by darkfrei
Hi all!

I've tried to make this picture:
what Ive expected.png
what Ive expected.png (7.99 KiB) Viewed 4825 times
The square and the line have the same width, default one pixel. The square was drawn the right way, but the line is too wide:
what Ive got.png
what Ive got.png (8.42 KiB) Viewed 4825 times
Is the line width not the same as by the square? Why?

UPD:
The

Code: Select all

	love.graphics.setLineWidth(1)
	love.graphics.rectangle (mode, x, y, width, heigh)
	love.graphics.setLineWidth(0.5)
	love.graphics.line( x1, y1, x2, y2)

makes the line too wide too, small color changing near the line:
what Ive got.png
what Ive got.png (8.42 KiB) Viewed 4826 times

Re: love.draw.line - line width is one pixel too wide

Posted: Sun Apr 19, 2020 4:44 pm
by darkfrei
Cannot attach the file properly, sorry.

With the code

Code: Select all

	love.graphics.setLineWidth(1)
	love.graphics.rectangle (mode, x, y, width, heigh)
	love.graphics.setLineWidth(0.5)
	love.graphics.line( x1, y1, x2, y2)
it looks like:
another line thickness.png
another line thickness.png (5.35 KiB) Viewed 4821 times
You can see small green lines about the middle line.
The love.graphics.setLineWidth(0) sets the line width to the default 1 pixel for this line.

Re: love.draw.line - line width is one pixel too wide

Posted: Sun Apr 19, 2020 6:32 pm
by pgimeno
We don't know what your coordinates are, but assuming they are centred in the pixel, you can use love.graphics.setLineStyle("rough") to get rid of the issue.

Re: love.draw.line - line width is one pixel too wide

Posted: Mon Apr 20, 2020 8:36 am
by darkfrei
pgimeno wrote: Sun Apr 19, 2020 6:32 pm We don't know what your coordinates are, but assuming they are centred in the pixel, you can use love.graphics.setLineStyle("rough") to get rid of the issue.
Thanks, with the "rough" style works like it must. But why the square doesn't need this trick? It makes by default exactly one pixel wide lines.

All coordinates are prepared to be centered it the middle of the square.

Re: love.draw.line - line width is one pixel too wide

Posted: Mon Apr 20, 2020 10:09 am
by pgimeno
darkfrei wrote: Mon Apr 20, 2020 8:36 am Thanks, with the "rough" style works like it must. But why the square doesn't need this trick? It makes by default exactly one pixel wide lines.
It's a good question, and I don't have the answer. It appears as if setLineWidth is clamped to 1.1 or so for love.graphics.line. It's also possible that it's due to the antialiasing requirements for drawing slanted lines; horizontal and vertical lines are simpler to draw than arbitrary lines.