Difference between revisions of "love.graphics.setCanvas"

m
(Add paragraph about interaction with love.graphics.present)
Line 3: Line 3:
 
== Function ==
 
== Function ==
 
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.
 
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.
 +
 +
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.
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">

Revision as of 23:38, 20 January 2019

Available since LÖVE 0.8.0
It has been renamed from love.graphics.setRenderTarget.

Captures drawing operations to a Canvas.

Function

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.

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.

Synopsis

love.graphics.setCanvas( canvas, mipmap )

Arguments

Canvas canvas
The new target.
Available since LÖVE 11.0
number mipmap (1)
The mipmap level to render to, for Canvases with mipmaps.

Returns

Nothing.

Function

Resets the render target to the screen, i.e. re-enables drawing to the screen.

Synopsis

love.graphics.setCanvas( )

Arguments

None.

Returns

Nothing.

Function

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.

Synopsis

love.graphics.setCanvas( canvas1, canvas2, ... )

Arguments

Canvas canvas1
The first render target.
Canvas canvas2
The second render target.
Canvas ...
More canvases.

Returns

Nothing.

Notes

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.

Function

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.

Synopsis

love.graphics.setCanvas( canvas, slice, mipmap )

Arguments

Canvas canvas
The new render target.
number slice
For cubemaps this is the cube face index to render to (between 1 and 6). For Array textures this is the array layer. For volume textures this is the depth slice. 2D canvases should use a value of 1.
number mipmap (1)
The mipmap level to render to, for Canvases with mipmaps.

Returns

Nothing.

Examples

Drawing to a canvas

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(230,240,120)
    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(255,255,255)
    love.graphics.draw(canvas, 200,100, 0, .5,.5)
end

See Also


Other Languages