Code: Select all
local gfx = love.graphics
function love.draw()
if not canvas then
canvas = gfx.newCanvas(512, 512)
gfx.setCanvas(canvas)
gfx.setColor(255, 255, 255, 255)
gfx.circle("fill", 128, 128, 128)
gfx.setColor(255, 0, 0, 255)
gfx.circle("fill", 256, 128, 128)
gfx.setCanvas()
end
gfx.setColor(255, 255, 255, 255)
gfx.draw(canvas)
end
This code does the same thing, except for calling canvas:newImageData() after drawing the first circle:
Code: Select all
local gfx = love.graphics
function love.draw()
if not canvas then
canvas = gfx.newCanvas(512, 512)
gfx.setCanvas(canvas)
gfx.setColor(255, 255, 255, 255)
gfx.circle("fill", 128, 128, 128)
-- only difference is this line
local img = canvas:newImageData()
gfx.setColor(255, 0, 0, 255)
gfx.circle("fill", 256, 128, 128)
gfx.setCanvas()
end
gfx.setColor(255, 255, 255, 255)
gfx.draw(canvas)
end
The red circle is gone. I can't draw anything to the canvas after I've called newImageData(). Is this a known limitation, or a bug or a problem with my system?
Edit: It's working as expected when switching to another canvas and back to the original:
Code: Select all
local img = canvas:newImageData()
-- set a dummy canvas
gfx.setCanvas(gfx.newCanvas(512, 512))
-- switch back
gfx.setCanvas(canvas)
-- drawing works again