[SOLVED] Multiple polygons not being drawn to a canvas

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.
User avatar
CrackedP0t
Citizen
Posts: 69
Joined: Wed May 07, 2014 4:01 am
Contact:

[SOLVED] Multiple polygons not being drawn to a canvas

Post by CrackedP0t »

With this LÖVE file, only the last polygon is drawn.

Why is that, and what can I do to draw all of them to the same canvas?

main.lua for your convenience:

Code: Select all

function love.load()
	canvas = love.graphics.newCanvas(100, 100 * math.sin(1/3 * math.pi))
end

function love.draw()	
	love.graphics.setCanvas(canvas)
	canvas:clear()
	
	local drawWidth = canvas:getWidth()
	local drawHeight = canvas:getHeight()
	
	local middleY = 3/5
	
	love.graphics.setColor(255, 0, 0)
	love.graphics.polygon("fill",
		0.5 * drawWidth, middleY * drawHeight,
		1.0 * drawWidth, 1.0 * drawHeight,
		0.0 * drawWidth, 1.0 * drawHeight)
	
	love.graphics.setColor(0, 255, 0)
	love.graphics.polygon("fill",
		0.5 * drawWidth, middleY * drawHeight,
		0.5 * drawWidth, 0.0 * drawHeight,
		1.0 * drawWidth, 1.0 * drawHeight)
	
	love.graphics.setColor(0, 0, 255)
	love.graphics.polygon("fill",
		0.5 * drawWidth, middleY * drawHeight,
		0.5 * drawWidth, 0.0 * drawHeight,
		0.0 * drawWidth, 1.0 * drawHeight)
		
	love.graphics.setCanvas()
	
	love.graphics.draw(canvas)
end
Attachments
canvas.love
(833 Bytes) Downloaded 145 times
Last edited by CrackedP0t on Fri Jun 26, 2015 6:00 pm, edited 1 time in total.
/人 ◕‿‿◕ 人\
Here, have an umlaut. Ö
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Multiple polygons not being drawn to a canvas

Post by bartbes »

They're all drawn, they're just drawn on top of each other.
User avatar
CrackedP0t
Citizen
Posts: 69
Joined: Wed May 07, 2014 4:01 am
Contact:

Re: Multiple polygons not being drawn to a canvas

Post by CrackedP0t »

bartbes wrote:They're all drawn, they're just drawn on top of each other.
How can I make them all visible?
/人 ◕‿‿◕ 人\
Here, have an umlaut. Ö
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Multiple polygons not being drawn to a canvas

Post by bartbes »

They.. kind of are? They're all just solid polygons exactly overlapping. What would you want to have happen?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Multiple polygons not being drawn to a canvas

Post by bobbyjones »

CrackedP0t move one of them around
User avatar
CrackedP0t
Citizen
Posts: 69
Joined: Wed May 07, 2014 4:01 am
Contact:

Re: Multiple polygons not being drawn to a canvas

Post by CrackedP0t »

bartbes wrote:They.. kind of are? They're all just solid polygons exactly overlapping. What would you want to have happen?
They're not, though. If you comment out the blue polygon, you'll see the green one to the right. Also, if you draw them to the normal screen rather than a canvas, they draw properly.
/人 ◕‿‿◕ 人\
Here, have an umlaut. Ö
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Multiple polygons not being drawn to a canvas

Post by Nixola »

Set the color to white before drawing the canvas.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Multiple polygons not being drawn to a canvas

Post by Positive07 »

Well you are doing something like this:

Code: Select all

love.graphics.setColor(255,0,0)
love.graphics.rectangle(100,100,100,100)
love.graphics.setColor(0,255,0)
love.graphics.rectangle(100,100,100,100)
What color would the square be?

Check the snippet you posted, the points of the polygons are the same for all of them! If you dont believe me, make the alpha value of each setColor equal to 50.

This is true unless the code you attached in the code block is different to that in the .love file (which I cant test because I'm not in Linux at the moment)
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Multiple polygons not being drawn to a canvas

Post by Nixola »

As I said, the issue is you're not setting the color back to white before drawing the canvas to your screen. The polygons, at least inside the .love file, don't have the same points and setting the color before drawing the canvas actually works.
EDIT: they're not drawn in the same position in the code he posted either.
That said, you should only draw to the canvas just once, not every frame, or there is really no point in using one.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Multiple polygons not being drawn to a canvas

Post by zorg »

Nixola wrote:That said, you should only draw to the canvas just once, not every frame, or there is really no point in using one.
I kinda disagree; i mean, i can use 3 canvases, and update one once every xth frame, one every yth frame, and one every frame, granted i have a reason to. I'm just saying, canvases can be useful when you are redrawing them every frame as well. (Only thing coming to my mind are layers for background and objects, though that can be accomplished with spritebatches as well...)
woo 2*10^2th post
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: Bing [Bot] and 14 guests