The code below shows the difference between the two. By default it just draws everything every frame but if you comment out the first line of .draw and let the if chain run it will use the framebuffer and come out really dark.
Code: Select all
function love.load()
font = love.graphics.newFont(20)
love.graphics.setFont(font);
end
function love.draw()
drawBackground()
--[[
if background ~= nil then
love.graphics.draw(background, 0, 0)
else
renderGameBackground()
end
--]]
end
function drawBackground()
local a = 0;
for i = 1, 10 do
love.graphics.setColor(255, 255, 255, 150)
if i < 10 then
love.graphics.print(a*2, 5, (i*50)+15)
love.graphics.print(a*2, 795 - font:getWidth(a*2), (i*50)+15)
else
love.graphics.print(a*2, 5, (i*50)+27)
love.graphics.print(a*2, 795 - font:getWidth(a*2), (i*50)+27)
end
if i < 6 then
a = a + 1
else
a = a - 1
end
if i == 10 then love.graphics.setColor(255, 0, 0, 255); i = 10.5 end
love.graphics.line(0, 50+(i*50), 800, 50+(i*50))
end
love.graphics.setColor(255, 255, 255, 255)
end
function renderGameBackground()
local backGroundBuffer = love.graphics.newFramebuffer()
backGroundBuffer:renderTo(function()
drawBackground()
end)
background = love.graphics.newImage(backGroundBuffer:getImageData())
end