Page 1 of 1

Canvases and thin lines.

Posted: Wed Aug 13, 2014 1:56 pm
by veethree
So i'm trying to draw some lines in a grid formation to a canvas. But i'm having some problems.

A picture is worth a thousand words.
Image
Screenshot is from my recent bloomy game of life implementation. The current version that's on the forum post isn't affected though, But i changed the resolution, and the cell size and it started happening.

For testing purposes i quickly threw together a function that generates one of these grids and returns a canvas.

Code: Select all

function create_grid(width, height, color, line_width, cell_size)
	local ow = love.graphics.getLineWidth()
	local c = love.graphics.newCanvas(width * cell_size, height * cell_size)
	love.graphics.setCanvas(c)
	love.graphics.setColor(color)
	love.graphics.setLineWidth(line_width)
	love.graphics.setLineStyle("rough")
	for y=1, height do
		love.graphics.line(0, y * cell_size, width * cell_size, y * cell_size)
	end
	for x=1, width do
		love.graphics.line(x * cell_size, 0, x * cell_size, height * cell_size)	
	end
	love.graphics.setCanvas()
	love.graphics.setLineWidth(ow)

	return c
end
And from my testing i've found this only/mostly happens when the line width is 1. And i kinda need the line width to be 1. Is there a way to do this with a canvas or should i just draw some lines with loops?

I do have shaders in the thing i'm making this for, But this doesn't need to be affected by them.

Re: Canvases and thin lines.

Posted: Wed Aug 13, 2014 2:51 pm
by slime
Make sure to use the 'premultiplied' blend mode when drawing the Canvas to the screen.

Re: Canvases and thin lines.

Posted: Wed Aug 13, 2014 3:23 pm
by veethree
Did that, Same thing. I did test it on my macbook after that, And it looks fine there. Perhaps it's a problem with my graphics card/drivers ?

Re: Canvases and thin lines.

Posted: Wed Aug 13, 2014 3:38 pm
by slime
Oh sorry, I misunderstood the problem (although it's still a good idea to use the 'premultiplied' blend mode in place of 'alpha' whenever drawing a canvas that has already been drawn to.)

The code in your .love is drawing to a half-sized Canvas - maybe it has something to do with that.

Re: Canvases and thin lines.

Posted: Wed Aug 13, 2014 3:42 pm
by veethree
slime wrote:Oh sorry, I misunderstood the problem (although it's still a good idea to use the 'premultiplied' blend mode in place of 'alpha' whenever drawing a canvas that has already been drawn to.)

The code in your .love is drawing to a half-sized Canvas - maybe it has something to do with that.
The half-sized canvases are for the bloom, I'm drawing the grid using the function in the OP. Since it looks fine on my mac, I'm just gonna assume it's to do with my GPU or drivers. Do you get this problem with that .love on your computer?

Re: Canvases and thin lines.

Posted: Wed Aug 13, 2014 3:48 pm
by slime
I don't, but I'm also using OS X.

Does it change anything if you offset everything by 0.5 pixels while drawing the grid (e.g. love.graphics.push(); love.graphics.translate(0.5, 0.5); create_grid(...); love.graphics.pop())?

Re: Canvases and thin lines.

Posted: Wed Aug 13, 2014 5:22 pm
by veethree
slime wrote:I don't, but I'm also using OS X.

Does it change anything if you offset everything by 0.5 pixels while drawing the grid (e.g. love.graphics.push(); love.graphics.translate(0.5, 0.5); create_grid(...); love.graphics.pop())?
Yes, That seems to fix it. But why?

Re: Canvases and thin lines.

Posted: Thu Aug 14, 2014 3:36 pm
by zorg
veethree wrote:But why?
This post has a neat image that i think explains it (i think) :3

...also, the whole tread actually.