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:
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
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?
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.