[SOLVED] What exactly does Canvas:renderTo do?

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
Sasha264
Citizen
Posts: 71
Joined: Mon Sep 08, 2014 7:57 am

[SOLVED] What exactly does Canvas:renderTo do?

Post by Sasha264 » Sat Jun 20, 2020 10:08 am

Good day! :crazy:
As wiki says https://love2d.org/wiki/Canvas:renderTo

Code: Select all

canvas:renderTo(func)
do this:

Code: Select all

love.graphics.setCanvas(canvas)
func()
love.graphics.setCanvas()
Is it correct?
In my experience it does something like this:

Code: Select all

local oldCanvas = love.graphics.getCanvas()
love.graphics.setCanvas(canvas)
func()
love.graphics.setCanvas(oldCanvas)
Wait a minute, maybe even something like this:

Code: Select all

local oldCanvases = { love.graphics.getCanvas() }
love.graphics.setCanvas(canvas)
func()
love.graphics.setCanvas(unpack(oldCanvases))
Oh, and since love 11 here is some mipmaps + stencils + setup wrapper + something more that you can do with
https://love2d.org/wiki/love.graphics.setCanvas

So, the final question: renderTo restores every aspect of current canvases setup after use?
If so, then how to do that 'manually' if I don't use renderTo?
Last edited by Sasha264 on Sun Jun 21, 2020 5:55 pm, edited 1 time in total.

User avatar
ReFreezed
Party member
Posts: 139
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: What exactly does Canvas:renderTo do?

Post by ReFreezed » Sat Jun 20, 2020 7:50 pm

You can use love.graphics.push("all") before changing the canvas, and then love.graphics.pop() to restore the previous one. I'm assuming the wiki just needs to be updated with a more accurate example.
Tools: Hot Particles, LuaPreprocess
Games: Momento Temporis: Light from the Deep, Momento Temporis: Arena, Energize!
"If each mistake being made is a new one, then progress is being made."

User avatar
Sasha264
Citizen
Posts: 71
Joined: Mon Sep 08, 2014 7:57 am

Re: What exactly does Canvas:renderTo do?

Post by Sasha264 » Sun Jun 21, 2020 5:54 pm

Push can push all! That is brilliant! Exactly what I need :awesome:

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests