Darker image from framebuffer
Posted: Sat Feb 12, 2011 12:16 am
I'm trying to use a framebuffer in my game so I can draw something that would normally take a lot of draw operations in only one. The problem is that whenever I draw the imagedata created by the framebuffer it always comes out really dark. I've tried toying around with the setColors but I can't seem to figure out what's causing it.
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.
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