Difference between revisions of "love.graphics.setCanvas"

m (Linkified stuff)
m (Updated example)
Line 25: Line 25:
  
 
== Examples ==
 
== Examples ==
=== Drawing to a framebuffer ===
+
=== Drawing to a canvas ===
 
<source lang="lua">
 
<source lang="lua">
-- create canvas
+
function love.load()
canvas = love.graphics.newCanvas()
+
    -- create canvas
 +
    canvas = love.graphics.newCanvas()
  
-- draw colored square to canvas
+
    -- direct drawing operations to the canvas
love.graphics.setCanvas(canvas)
+
    love.graphics.setCanvas(canvas)
love.graphics.setColor(230,240,120)
 
love.graphics.rectangle('fill',0,0,100,100)
 
love.graphics.setCanvas()
 
  
-- draw scaled canvas to screen
+
    -- draw colored square to canvas
love.graphics.setColor(255,255,255)
+
    love.graphics.setColor(230,240,120)
love.graphics.clear()
+
    love.graphics.rectangle('fill',0,0,100,100)
love.graphics.draw(canvas, 200,100, 0, .5,.5)
+
 
 +
    -- 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
 
</source>
 
</source>
  

Revision as of 17:59, 11 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.

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