Difference between revisions of "love.graphics.newFramebuffer"

(Add canvas emulation example)
m (Fixed absolute link.)
 
(15 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{newin|[[0.7.0]]}}
+
{{newinoldin|[[0.7.0]]|070|[[0.8.0]]|080|type=function|text=It has been renamed to [[love.graphics.newCanvas]]}}
 
 
 
Creates a new framebuffer object for offscreen rendering.
 
Creates a new framebuffer object for offscreen rendering.
 
+
{{notice|Versions prior to 0.8.0 have Framebuffers that are susceptible to [[PO2_Syndrome|power of 2 syndrome]].}}
 +
{{newobjectnotice}}
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
Line 23: Line 23:
 
=== Returns ===
 
=== Returns ===
 
{{param|Framebuffer|framebuffer|A new framebuffer with specified width and height.}}
 
{{param|Framebuffer|framebuffer|A new framebuffer with specified width and height.}}
=== Notes ===
 
Specifying a size different from the window size will not resize the canvas but the resulting image itself. To resize the canvas you have to use [[love.graphics.scale]].
 
 
== Notes ==
 
It is tempting to think of a Framebuffer as a canvas. And though you can create one that is larger or smaller than the screen, it does not act like one, meaning you cannot draw things that lie outside of the window dimensions. Instead all content drawn to the buffer will be scaled according to framebuffer_width/screen_width in x-direction and framebuffer_height/screen_height in y-direction.
 
 
You can emulate a canvas by using [[love.graphics.scale]] before drawing to the buffer:
 
<source lang="lua">
 
function love.load()
 
    framebuffer = love.graphics.newFramebuffer(FB_WIDTH, FB_HEIGHT)
 
    -- more stuff
 
end
 
 
function love.draw()
 
    love.graphics.setRenderTarget(framebuffer)
 
    love.graphics.push()
 
    love.graphics.scale(love.graphics.getWidth()/FB_WIDTH, love.graphics.getHeight()/FB_HEIGHT)
 
    -- draw things like drawing to a canvas
 
    love.graphics.pop()
 
    love.graphics.setRenderTarget(framebuffer)
 
    -- present the framebuffer
 
    love.graphics.draw(framebuffer, 0,0)
 
end
 
</source>
 
  
 
== See Also ==
 
== See Also ==
Line 53: Line 29:
 
* [[love.graphics.setRenderTarget]]
 
* [[love.graphics.setRenderTarget]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Creates a new [[Framebuffer]]
+
[[Sub-Category::Object Creation| ]]
}}
+
{{#set:Description=Creates a new [[Framebuffer]].}}
 +
== Other Languages ==
 +
{{i18n|love.graphics.newFramebuffer}}

Latest revision as of 03:53, 6 September 2016

Available since LÖVE 0.7.0 and removed in LÖVE 0.8.0
It has been renamed to love.graphics.newCanvas.

Creates a new framebuffer object for offscreen rendering.

O.png Versions prior to 0.8.0 have Framebuffers that are susceptible to power of 2 syndrome.  


O.png This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused!  



Function

Synopsis

framebuffer = love.graphics.newFramebuffer( )

Arguments

None.

Returns

Framebuffer framebuffer
A new framebuffer with width/height equal to the window width/height.

Function

Synopsis

framebuffer = love.graphics.newFramebuffer( width, height )

Arguments

number width
The desired width of the framebuffer.
number height
The desired height of the framebuffer.

Returns

Framebuffer framebuffer
A new framebuffer with specified width and height.

See Also


Other Languages