(I see this thread is from 2019 but I just tripped over a similiar problem with canvases and TLFres and the thread does not seem fully solved)
TLFres uses a translate-function:
function TLfres.beginRendering(width, height, centered)
lgTranslate((w - width * scale) * 0.5, (h - height * scale) * 0.5)
That translate is still active when drawing into the canvases, but we do not want that. The actual screen might get letterbox-bars from TLFres so coordinates need to shift. But the coordinates of the canvas do not need to shift: (0,0) must still be at top-left.
Here is how I solved it:
Code: Select all
function showView (view,x,y)
LG.setColor(1, 1, 1, 1)
LG.setLineWidth (2)
LG.rectangle('line', x, y, viewWidth, viewHeight) --frame
LG.setBlendMode("alpha", "premultiplied")
LG.draw (view,x,y)
LG.setBlendMode("alpha")
end
Code: Select all
function drawView (view)
LG.push () --THE FIX
LG.origin () --THE FIX
LG.setCanvas(view)
--white testcircles to mark top-left and bottom-right corner of view-window
LG.setColor(1, 1, 1, 1)
LG.circle("fill", 0,0, 20, 6)
LG.circle("fill", viewWidth,viewHeight, 20, 6)
--drawing actual content of view-window
LG.setColor(0, 0, 1, 1)
LG.circle("fill", math.random(0,viewWidth), math.random(0,viewHeight), 20, 5)
love.graphics.setColor(1, 0, 0, 1)
LG.circle("fill", math.random(0,viewWidth), math.random(0,viewHeight), 20, 5)
LG.pop () --THE FIX
LG.setCanvas()
end
Things looked okay as in 1.png
However, when I enabled TLFrs, the graphics inside the canvas were wrong as in 2.png
love.graphics.origin() undoes the translate of TLFres. But we still want that translate for drawing other stuff so it gets wrapped into push&pop. Note the lines with --FIX comment