## Canvases and thin lines.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

### Canvases and thin lines.

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.

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.
slime
Solid Snayke
Posts: 2930
Joined: Mon Aug 23, 2010 6:45 am
Contact:

### Re: Canvases and thin lines.

Make sure to use the 'premultiplied' blend mode when drawing the Canvas to the screen.
veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

### Re: Canvases and thin lines.

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 ?
Attachments
Game of life.love
slime
Solid Snayke
Posts: 2930
Joined: Mon Aug 23, 2010 6:45 am
Contact:

### Re: Canvases and thin lines.

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.
veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

### Re: Canvases and thin lines.

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?
slime
Solid Snayke
Posts: 2930
Joined: Mon Aug 23, 2010 6:45 am
Contact:

### Re: Canvases and thin lines.

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())?
veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

### Re: Canvases and thin lines.

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?
zorg
Party member
Posts: 3073
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Canvases and thin lines.

veethree wrote:But why?
This post has a neat image that i think explains it (i think)