Difference between revisions of "Canvas:renderTo"
(Created page with "{{newin|0.8.0|080|type=function}} Render to the Canvas using a function. This is a shortcut to love.graphics.setCanvas: <source lang="lua"> canvas:renderTo( func ) <...") |
(Update which versions certain variants and parameters were added in.) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | {{newin|[[0.8.0]]|080|type=function}} | + | {{newin|[[0.8.0]]|080|type=function|text=It has been renamed from [[Framebuffer:renderTo]]}} |
Render to the [[Canvas]] using a function. | Render to the [[Canvas]] using a function. | ||
Line 8: | Line 8: | ||
is the same as | is the same as | ||
<source lang="lua"> | <source lang="lua"> | ||
+ | local prevcanvas = love.graphics.getCanvas() | ||
love.graphics.setCanvas( canvas ) | love.graphics.setCanvas( canvas ) | ||
func() | func() | ||
− | love.graphics.setCanvas() | + | love.graphics.setCanvas( prevcanvas ) |
</source> | </source> | ||
Line 16: | Line 17: | ||
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
− | Canvas:renderTo( func ) | + | Canvas:renderTo( func, ... ) |
</source> | </source> | ||
=== Arguments === | === Arguments === | ||
{{param|function|func|A function performing drawing operations.}} | {{param|function|func|A function performing drawing operations.}} | ||
+ | {{New feature|11.5| | ||
+ | {{param|any|...|Additional arguments to call the function with.}} | ||
+ | }} | ||
+ | === Returns === | ||
+ | Nothing. | ||
+ | |||
+ | == Function == | ||
+ | {{newin|[[11.0]]|type=variant}} | ||
+ | === Synopsis === | ||
+ | <source lang="lua"> | ||
+ | Canvas:renderTo( index, func, ... ) | ||
+ | </source> | ||
+ | === Arguments === | ||
+ | {{param|number|index|An index to a layer (for array textures and volume textures) or an index to a cubemap face (for cubemap textures).}} | ||
+ | {{param|function|func|A function performing drawing operations.}} | ||
+ | {{New feature|11.5| | ||
+ | {{param|any|...|Additional arguments to call the function with.}} | ||
+ | }} | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
Line 25: | Line 44: | ||
== Examples == | == Examples == | ||
=== Using an anonymous function for drawing to a Canvas === | === Using an anonymous function for drawing to a Canvas === | ||
+ | This example randomly draws a bunch of red lines from the top left corner of the screen to the bottom. | ||
<source lang="lua"> | <source lang="lua"> | ||
− | canvas:renderTo(function() | + | local canvas = love.graphics.newCanvas() |
− | + | function love.update() | |
− | love.graphics. | + | canvas:renderTo(function() |
− | end | + | 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 | ||
</source> | </source> | ||
Latest revision as of 13:31, 30 April 2024
Available since LÖVE 0.8.0 |
It has been renamed from Framebuffer:renderTo. |
Render to the Canvas using a function.
This is a shortcut to love.graphics.setCanvas:
canvas:renderTo( func )
is the same as
local prevcanvas = love.graphics.getCanvas()
love.graphics.setCanvas( canvas )
func()
love.graphics.setCanvas( prevcanvas )
Contents
Function
Synopsis
Canvas:renderTo( func, ... )
Arguments
function func
- A function performing drawing operations.
Available since LÖVE 11.5
any ...
- Additional arguments to call the function with.
Returns
Nothing.
Function
Available since LÖVE 11.0 |
This variant is not supported in earlier versions. |
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.
Available since LÖVE 11.5
any ...
- Additional arguments to call the function with.
Returns
Nothing.
Examples
Using an anonymous function for drawing to a Canvas
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
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info