Available since LÖVE 0.8.0
It has been renamed from love.graphics.setRenderTarget.
Captures drawing operations to a Canvas.
Sets the render target to a specified Canvas. All drawing operations until the next love.graphics.setCanvas call will be redirected to the Canvas and not shown on the screen.
When using a stencil or depth testing with an active Canvas, the stencil buffer or depth buffer must be explicitly enabled in setCanvas via the variants below.
Note that no canvas should be active when love.graphics.present is called. love.graphics.present is called at the end of love.draw in the default love.run, hence if you activate a canvas using this function, you normally need to deactivate it at some point before love.draw finishes.
love.graphics.setCanvas( canvas, mipmap )
Canvas canvasNothing.
Resets the render target to the screen, i.e. re-enables drawing to the screen.
love.graphics.setCanvas( )
None.
Nothing.
Available since LÖVE 0.9.0
This variant is not supported in earlier versions.
Sets the render target to multiple simultaneous 2D Canvases. All drawing operations until the next love.graphics.setCanvas call will be redirected to the specified canvases and not shown on the screen.
love.graphics.setCanvas( canvas1, canvas2, ... )
Canvas canvas1Canvas canvas2Canvas ...Nothing.
Normally all drawing operations will draw only to the first canvas passed to the function, but that can be changed if a pixel shader is used with the void effect function instead of the regular vec4 effect.
All canvas arguments must have the same widths and heights and the same texture type. Not all computers which support Canvases will support multiple render targets. If love.graphics.isSupported("multicanvas") returns true, at least 4 simultaneously active canvases are supported.
Available since LÖVE 11.0
This variant is not supported in earlier versions.
Sets the render target to the specified layer/slice and mipmap level of the given non-2D Canvas. All drawing operations until the next love.graphics.setCanvas call will be redirected to the Canvas and not shown on the screen.
love.graphics.setCanvas( canvas, slice, mipmap )
Canvas canvasnumber slicenumber mipmap (1)Nothing.
Available since LÖVE 11.0
This variant is not supported in earlier versions.
Sets the active render target(s) and active stencil and depth buffers based on the specified setup information. All drawing operations until the next love.graphics.setCanvas call will be redirected to the specified Canvases and not shown on the screen.
love.graphics.setCanvas( setup )
table setupRenderTargetSetup [1]RenderTargetSetup [2] (nil)RenderTargetSetup ...boolean stencil (false)depthstencil field isn't set.boolean depth (false)depthstencil field isn't set.RenderTargetSetup depthstencil (nil)Nothing.
The RenderTargetSetup parameters can either be a Canvas object, or a table in the following format: {canvas, mipmap=#, layer=#, face=#}
Canvas [1]number mipmap (1)number layer (1)number face (1)function love.load()
-- create canvas
canvas = love.graphics.newCanvas()
-- direct drawing operations to the canvas
love.graphics.setCanvas(canvas)
-- draw colored square to canvas
love.graphics.setColor(0.8, 0.9, 0.4)
love.graphics.rectangle("fill", 0, 0, 100, 100)
-- re-enable drawing to the main screen
love.graphics.setCanvas()
end
function love.draw()
-- draw scaled canvas to screen
love.graphics.setColor(1, 1, 1)
love.graphics.draw(canvas, 200, 100, 0, 0.5, 0.5)
end
-- Allow love.graphics.stencil calls when drawing to the given Canvas.
love.graphics.setCanvas({canvas, stencil=true})
-- Use multiple simultaneous render targets when drawing to several canvases of the Array Texture type,
-- and use a custom depth buffer as well.
canvas1 = love.graphics.newCanvas(128, 128, 4, {type="array"})
canvas2 = love.graphics.newCanvas(128, 128, 8, {type="array"})
depthcanvas = love.graphics.newCanvas(128, 128, {format="depth24", readable=true})
love.graphics.setCanvas({
{canvas1, layer = 3},
{canvas2, layer = 1},
depthstencil = depthcanvas,
})
© 2006–2020 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/love.graphics.setCanvas