Page 3 of 6
Re: How to use Framebuffer:renderTo() properly
Posted: Fri Nov 19, 2010 11:10 pm
by Robin
Jasoco wrote:How would I use this to:
Copy the contents of the main visible screen to a separate buffer
Manipulate the pixels of the separate newly copied buffer, say make all the pixels greyscale
Then use that separate buffer as an image to paste onto the main screen
?
That second part indeed sounds like something a shader would do.
Jasoco wrote:Well, mostly the first and third steps. Can I copy from one frame to another? Then can I take another and use it as image data?
That's mainly what I want. Or just how do I draw to another buffer and use that buffer on my main screen? I don't understand the code provided. Anyone have a working example .love file?
If I understand you correctly, you want to do something like:
Code: Select all
love.graphics.setRenderTarget(fb2)
love.graphics.draw(fb1, 0, 0)
love.graphics.setRenderTarget()
does that sound right to you?
Re: How to use Framebuffer:renderTo() properly
Posted: Fri Nov 19, 2010 11:22 pm
by Jasoco
Are fb1 and fb2 names for each buffer? Because it looks like what I want.
Re: How to use Framebuffer:renderTo() properly
Posted: Fri Nov 19, 2010 11:31 pm
by Robin
Jasoco wrote:Are fb1 and fb2 names for each buffer? Because it looks like what I want.
Jup.
Alternative syntax (that does exactly the same):
Code: Select all
fb2:renderTo(function() love.graphics.draw(fb1, 0, 0) end)
Re: How to use Framebuffer:renderTo() properly
Posted: Sat Nov 20, 2010 12:22 am
by Jasoco
So they're just called fb1 and fb2? How many can we have, or how can we find that out if it depends on our video card?
Re: How to use Framebuffer:renderTo() properly
Posted: Sat Nov 20, 2010 1:28 am
by Robin
Jasoco wrote:So they're just called fb1 and fb2? How many can we have, or how can we find that out if it depends on our video card?
I get to about 526 or something, it probably depends on the video card.
And no, those names are arbitrary. I assume somewhere earlier in the code it says:
Code: Select all
fb1 = love.graphics.newFramebuffer()
fb2 = love.graphics.newFramebuffer()
Re: How to use Framebuffer:renderTo() properly
Posted: Wed Dec 08, 2010 5:15 pm
by TechnoCat
Now that 0.7.0 is released and framebuffers are window dimension independent.
Here is a framebuffer example. They are very cool.
Code: Select all
function love.load()
enabled = false
image = love.graphics.newImage("image.png")
translate = {x=0, y=0}
scene = {}
scene.width = 2048
scene.height = 2048
--Iniitialize framebuffer
fb = love.graphics.newFramebuffer(scene.width, scene.height)
--Create random objects placed everywhere
imageSet = {}
for i = 1, 10000 do
local entry = {}
entry.x = math.random(scene.width-128)
entry.y = math.random(scene.height-128)
imageSet[i] = entry
end
--Draw them to the framebuffers
-- This is my preferable method
love.graphics.setRenderTarget(fb)
for _,v in ipairs(imageSet) do
love.graphics.draw(image, v.x, v.y)
end
love.graphics.setRenderTarget()
--]]
--[[ This is the other method
fb:renderTo(
function()
for _,v in ipairs(imageSet) do
love.graphics.draw(image, v.x, v.y)
end
end
)
--]]
end
function love.update(dt)
if love.keyboard.isDown("left") then
translate.x = translate.x + 1000*dt
elseif love.keyboard.isDown("right") then
translate.x = translate.x - 1000*dt
end
if love.keyboard.isDown("up") then
translate.y = translate.y + 1000*dt
elseif love.keyboard.isDown("down") then
translate.y = translate.y - 1000*dt
end
end
function love.draw()
love.graphics.push()
love.graphics.translate(translate.x, translate.y)
if enabled then
love.graphics.draw(fb, 0, 0)
else
for _,v in ipairs(imageSet) do
love.graphics.draw(image, v.x, v.y)
end
end
love.graphics.pop()
fps = love.timer.getFPS()
if enabled then
love.graphics.setCaption(fps.." Framebuffer rendering enabled",0,0)
else
love.graphics.setCaption(fps.." Framebuffer rendering disabled",0,0)
end
end
function love.keypressed(k)
if k==" " then
enabled = not enabled
end
end
Re: How to use Framebuffer:renderTo() properly
Posted: Tue Dec 28, 2010 10:03 pm
by tentus
TechnoCat wrote:Now that 0.7.0 is released and framebuffers are window dimension independent.
Here is a framebuffer example. They are very cool.
Code: Select all
function love.load()
enabled = false
image = love.graphics.newImage("image.png")
translate = {x=0, y=0}
scene = {}
scene.width = 2048
scene.height = 2048
--Iniitialize framebuffer
fb = love.graphics.newFramebuffer(scene.width, scene.height)
--Create random objects placed everywhere
imageSet = {}
for i = 1, 10000 do
local entry = {}
entry.x = math.random(scene.width-128)
entry.y = math.random(scene.height-128)
imageSet[i] = entry
end
--Draw them to the framebuffers
-- This is my preferable method
love.graphics.setRenderTarget(fb)
for _,v in ipairs(imageSet) do
love.graphics.draw(image, v.x, v.y)
end
love.graphics.setRenderTarget()
--]]
--[[ This is the other method
fb:renderTo(
function()
for _,v in ipairs(imageSet) do
love.graphics.draw(image, v.x, v.y)
end
end
)
--]]
end
function love.update(dt)
if love.keyboard.isDown("left") then
translate.x = translate.x + 1000*dt
elseif love.keyboard.isDown("right") then
translate.x = translate.x - 1000*dt
end
if love.keyboard.isDown("up") then
translate.y = translate.y + 1000*dt
elseif love.keyboard.isDown("down") then
translate.y = translate.y - 1000*dt
end
end
function love.draw()
love.graphics.push()
love.graphics.translate(translate.x, translate.y)
if enabled then
love.graphics.draw(fb, 0, 0)
else
for _,v in ipairs(imageSet) do
love.graphics.draw(image, v.x, v.y)
end
end
love.graphics.pop()
fps = love.timer.getFPS()
if enabled then
love.graphics.setCaption(fps.." Framebuffer rendering enabled",0,0)
else
love.graphics.setCaption(fps.." Framebuffer rendering disabled",0,0)
end
end
function love.keypressed(k)
if k==" " then
enabled = not enabled
end
end
I get an OpenGL error on my work machine (line 11, which creates the fb). I'm assuming that means that this POS machine cannot do framebuffers at all?
Re: How to use Framebuffer:renderTo() properly
Posted: Wed Dec 29, 2010 9:56 pm
by Robin
Maybe it's just too large? Try removing the arguments to newFramebuffer, see if that works.
Re: How to use Framebuffer:renderTo() properly
Posted: Wed Dec 29, 2010 11:00 pm
by TechnoCat
Robin wrote:Maybe it's just too large? Try removing the arguments to newFramebuffer, see if that works.
Well, chances are if you can't do a big buffer, removing the arguments and making an 800x600 size framebuffer will lead to even more problems, try 512x512.
Re: How to use Framebuffer:renderTo() properly
Posted: Thu Dec 30, 2010 5:39 am
by tentus
I did before posting (sorry I didn't mention that). Same result. I could whip up a screenshot if that would help?