Page 1 of 1

a little confusion with graphics.point , line, rectangle...

Posted: Mon Oct 01, 2012 9:45 pm
by pch
Hi there,
lately I tried drawing some lines and the result really surprised me (maybe "confused" me would be better)

I made a line using graphics.point command and it couldn't draw pixel in x = 599 - that value always put pixel on x = 588
After some "digging" I found a note saying something about pixels grid offset (0.5) so i shifted each X value by 0.5 and that solved the problem - well.. not quiet.
Then I checked another commands like line and rectangle and now I'm lost.

pls check the following couple of lines:

Code: Select all

function love.load()
	love.graphics.setLine(1, "rough")
	love.graphics.setPoint(1, "rough")
	love.graphics.setColorMode("replace")
end

function love.keypressed(key, code)
	if key == "escape" then return love.event.push("quit") end
end

function love.draw()

	n = 1
	love.graphics.setColor(255, 255, 255, 255)
	for x = 560, 640, 30 do
		
		y = 0.5
		for xx = x, x + 20 do
			love.graphics.point(xx, 		y + 3)	-- not shifted
			love.graphics.point(xx + 0.5,	y + 5)	-- shifted
		end
		
		love.graphics.rectangle("line",	x,			y + 10,	20,				5)		-- not shifted
		love.graphics.rectangle("line",	x + 0.5,	y + 18,	20,				5)		-- shifted

		love.graphics.rectangle("fill",	x,			y + 30,	20,				5)		-- not shifted
		love.graphics.rectangle("fill",	x + 0.5,	y + 38,	20,				5)		-- shifted
		
		love.graphics.line(				x,			y + 50,	x + 20,			y + 50)	-- not shifted
		love.graphics.line(				x + 0.5,	y + 52,	x + 20 + 0.5,	y + 52)	-- shifted
				
		love.graphics.print(n, x+5, y + 60)
		n = n + 1
	end
	
end
it draws set of:
2 lines made from graphisc.point (top line not shifted by 0.5 and the bottom one shifted)
2 rectangles "line" using graphics.rectangle (one shifted, other one not)
2 rectangles "fill" using graphics.rectangle (one shifted, other one not)
2 lines usig graphics.line (one shifted, one not)

then it repeats that set twice - each time moved a little bit more on X axis:
set 1: is drawn to the left of X = 599 - it means none of its components will reach X = 599
set 2: is drawn a liitle to the left and little to the right of x = 599 - it means it "includes" x = 599
set 3: is drawn to the right of X = 599 - so like set 1 but is drawn from other side

The only way to see what I'm talking about is to make a screen shot of results of above code and put it in some graphics application then zoom in the area with shapes (these are EXACTLY the same commands with EXACTLY the same parameters but the results are COMPLETELY different)

I'd like to know if it is normal behaviour ( I expected something else) or I'm doing something wrong
Thanks

Re: a little confusion with graphics.point , line, rectangle

Posted: Mon Oct 01, 2012 10:32 pm
by Boolsheet
The point, line, and other shape lines can indeed be a bit confusing if you're thinking in pixels. Have a look at this thread where something similar came up.

This is more or less expected behaviour. It's hard to explain without going into the technical details and it looks like I need some sleep before I try myself at that. ;)

I can answer some more specific questions, if you have them.

Edit: A note to myself: Look into the custom line drawing code when in rough mode.

Edit2: Actually, for lines in rough mode, the start and end point are on the edge.
lineends.png
lineends.png (1.44 KiB) Viewed 1516 times