Difference between revisions of "love.graphics.setCanvas"

m (Updated example)
(Added setCanvases(canvas1, canvas2, ...) variant)
Line 23: Line 23:
 
=== Notes ===
 
=== Notes ===
 
Resets the render target to the screen, i.e. re-enables drawing to the screen.
 
Resets the render target to the screen, i.e. re-enables drawing to the screen.
 +
 +
== Function ==
 +
{{newin|[[0.9.0]]|090|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.setCanvas( canvas1, canvas2, ... )
 +
</source>
 +
=== Arguments ===
 +
{{param|Canvas|canvas1|The first render target.}}
 +
{{param|Canvas|canvas2|The second render target.}}
 +
=== Returns ===
 +
Nothing.
 +
=== Notes ===
 +
Sets the render target to multiple simultaneous [[Canvas]]es. All drawing operations until the next ''love.graphics.setCanvas'' call will be redirected to the specified canvases and not shown on the screen.
 +
 +
All canvas arguments must have the same widths and heights and the same [[TextureMode|texture type]]. Normally the same thing will be drawn on each canvas, but that can be changed if a [[Shader|pixel shader]] is used with the [[love.graphics.newShader#Pixel_Shader_Function|"effects"]] function instead of the regular <code>effect</code>.
 +
 +
Not all computers which support Canvases will support multiple render targets. Use [[love.graphics.isSupported]] to check.
  
 
== Examples ==
 
== Examples ==

Revision as of 01:46, 22 August 2013

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

Function

Synopsis

love.graphics.setCanvas( canvas )

Arguments

Canvas canvas
The new target.

Returns

Nothing.

Notes

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.

Function

Synopsis

love.graphics.setCanvas( )

Arguments

None.

Returns

Nothing.

Notes

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

Function

Available since LÖVE 0.9.0
This variant is not supported in earlier versions.

Synopsis

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

Arguments

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

Returns

Nothing.

Notes

Sets the render target to multiple simultaneous Canvases. All drawing operations until the next love.graphics.setCanvas call will be redirected to the specified canvases and not shown on the screen.

All canvas arguments must have the same widths and heights and the same texture type. Normally the same thing will be drawn on each canvas, but that can be changed if a pixel shader is used with the "effects" function instead of the regular effect.

Not all computers which support Canvases will support multiple render targets. Use love.graphics.isSupported to check.

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