Canvases and thin lines.

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

Canvases and thin lines.

Post 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.
User avatar
slime
Solid Snayke
Posts: 2932
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Canvases and thin lines.

Post by slime »

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

Re: Canvases and thin lines.

Post 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 ?
Attachments
Game of life.love
(3.81 KiB) Downloaded 53 times
User avatar
slime
Solid Snayke
Posts: 2932
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Canvases and thin lines.

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

Re: Canvases and thin lines.

Post 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?
User avatar
slime
Solid Snayke
Posts: 2932
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Canvases and thin lines.

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

Re: Canvases and thin lines.

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

Re: Canvases and thin lines.

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests