(solved) Rectangle lines are to thick

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
mcjohnalds45
Prole
Posts: 18
Joined: Sat Jun 02, 2012 12:08 pm

(solved) Rectangle lines are to thick

Post by mcjohnalds45 »

Rectangles drawn with love.graphics.rectangle are (at least on love 0.8.0) automatically two or three pixels wide love.graphics.setLineWidth doesn't help, it's kind of a minor thing but it would be nice if love.graphics.setLineWidth(1) made rectangles have a line width of 1.
TvN9x.png
TvN9x.png (21.2 KiB) Viewed 196 times
Attachments
rectangle glitch.love
does a three line program really need a .love? lmao
(235 Bytes) Downloaded 57 times
Last edited by mcjohnalds45 on Sun Jun 17, 2012 10:53 am, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Rectangle lines are to thick

Post by bartbes »

This is something we've been struggling with, and actually, the line is one pixel wide, but it's drawn between two pixels, interpolating it to two (about) half-filled pixels.

As a temporary solution, you could move your rectangle by (0.5, 0.5).
User avatar
mcjohnalds45
Prole
Posts: 18
Joined: Sat Jun 02, 2012 12:08 pm

Re: Rectangle lines are to thick

Post by mcjohnalds45 »

That works perfectly, thanks a bunch bartbes!
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Rectangle lines are to thick

Post by Kingdaro »

Would it be possible to automatically move it down and right half a pixel in drawing?
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Rectangle lines are to thick

Post by Xgoff »

Kingdaro wrote:Would it be possible to automatically move it down and right half a pixel in drawing?
i wonder if love itself could cheat and do a translate call each frame in love.run

who knows what that would potentially mess up, though
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Rectangle lines are to thick

Post by Boolsheet »

In my opinion, LÖVE should not do any shifting by default. It currently places the center of the line exactly where you specify it. Adding some shifting rule complicates this for no good reason. Also, only odd line widths need the 0.5 shift to get them into the position where it matches the pixels exactly. The even widths need coordinates inbetween the pixel for that.
Shallow indentations.
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Rectangle lines are to thick

Post by Lafolie »

Also, try setting the line style to "rough" before drawing lines. I am able to get lines drawn at whole integers using this, without having to add 0.5 to the position values.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Rectangle lines are to thick

Post by Boolsheet »

Lafolie wrote:Also, try setting the line style to "rough" before drawing lines. I am able to get lines drawn at whole integers using this, without having to add 0.5 to the position values.
Note that this will only work as long as FSAA/multisampling is turned off.

There's a way for doing the shift automatically. Well... If love.graphics.getLineWidth would actually work (it's broken in 0.8.0 and I push a patch to the developers right now) you could do something like this:

Code: Select all

local l_g_rectangle = love.graphics.rectangle
function love.graphics.rectangle(style, x, y, ...)
	if style == "line" then
		local offset = love.graphics.getLineWidth() / 2 % 1
		x = x + offset
		y = y + offset
	end
	l_g_rectangle(style, x, y, ...)
end
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 64 guests