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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

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

Post by darkfrei »

Hi all!

I've tried to make this picture:
what Ive expected.png
what Ive expected.png (7.99 KiB) Viewed 4294 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 4294 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 4295 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

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

Post 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 4290 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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3593
Joined: Sun Oct 18, 2015 2:58 pm

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

Post 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.
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

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

Post 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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3593
Joined: Sun Oct 18, 2015 2:58 pm

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests