function love.load()
canvas = love.graphics.newCanvas()
love.graphics.setCanvas(canvas)
canvas:clear()
love.graphics.setColor(85, 34, 159, 255)
love.graphics.rectangle('fill', 0, 0, 400, 400)
end
function love.draw()
love.graphics.draw(canvas)
end
This code produces a black screen and the rectangle isn't there, but if I add the function setCanvas() at the end of the load() function it seems to work.So why do I need to set the render target back to the screen before the load() function ends?
function love.load()
canvas = love.graphics.newCanvas(800,600) -- I would recommend setting a known canvas size.
love.graphics.setCanvas(canvas)
canvas:clear()
love.graphics.setColor(85, 34, 159, 255)
love.graphics.rectangle('fill', 0, 0, 400, 400)
end
function love.draw()
love.graphics.setCanvas() -- Set the draw target back to the screen, You can do it in love.load as well.
love.graphics,setColor() -- Set the drawing color back to white
love.graphics.draw(canvas)
end
The Problem is that you never set the active canvas back to the screen so you end up drawing the canvas to the canvas and nothing to the screen.
The default [wiki]love.run[/wiki] causes the currently active canvas (which normally ends up being the main screen) to be cleared directly before love.draw is called. If you keep your own canvas active until love.draw, then it will be cleared instead of the screen.