Texture:renderTo

Available since LÖVE 12.0
It has been moved from Canvas:renderTo.

Render to the Texture using a function. The Texture must have been created with the canvas capability.

This is a shortcut to love.graphics.setCanvas:

texture:renderTo( func )

is similar to

local prevcanvas = love.graphics.getCanvas()
love.graphics.setCanvas( canvas )
func()
love.graphics.setCanvas( prevcanvas )

Function

Synopsis

Texture:renderTo( func, ... )

Arguments

function func
A function performing drawing operations.
any ...
Additional arguments to call the function with.

Returns

Nothing.

Function

Synopsis

Canvas:renderTo( index, func, ... )

Arguments

number index
An index to a layer (for array textures and volume textures) or an index to a cubemap face (for cubemap textures).
function func
A function performing drawing operations.
any ...
Additional arguments to call the function with.

Returns

Nothing.

Examples

Using an anonymous function for drawing to a canvas Texture

This example randomly draws a bunch of red lines from the top left corner of the screen to the bottom.

local canvas = love.graphics.newCanvas()
function love.update()
    canvas:renderTo(function()
        love.graphics.setColor(love.math.random(), 0, 0);
        love.graphics.line(0, 0, love.math.random(0, love.graphics.getWidth()), love.math.random(0, love.graphics.getHeight()));
    end);
end

function love.draw()
    love.graphics.setColor(1, 1, 1);
    love.graphics.draw(canvas);
end

See Also

Other Languages