I'm trying to develop a game where you can take photos of your environment. Is it possible to take a screenshot of just a specific area of the screen and work with it as an image object? Could I submit a patch to add optional screen area parameters to love.graphics.newScreenshot() or will it be too slow for use in the game?
Would I be better off drawing everything to a canvas first, draw the canvas to the screen, and when a picture is taken, save a scissored version of that canvas as the picture object?
Screenshot just a specific area?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Screenshot just a specific area?
----------------------------------------
Sluicer Games
Sluicer Games
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Screenshot just a specific area?
You could use love.graphics.newScreenshot and [wiki]ImageData:paste[/wiki], although that might not be as ideal as a native solution in LÖVE.
Keep in mind that such a solution won't improve performance though, because the main cost of newScreenshot (and Canvas:getImageData) is the fact that they have to cause the GPU and CPU to synchronize (the GPU is normally one or more whole frames 'behind' the CPU.)
Keep in mind that such a solution won't improve performance though, because the main cost of newScreenshot (and Canvas:getImageData) is the fact that they have to cause the GPU and CPU to synchronize (the GPU is normally one or more whole frames 'behind' the CPU.)
Re: Screenshot just a specific area?
Does the love.graphics.setScissor work with screenshots? It says it restricts all drawing calls, so possibly also screenshot?clofresh wrote:I'm trying to develop a game where you can take photos of your environment. Is it possible to take a screenshot of just a specific area of the screen and work with it as an image object? Could I submit a patch to add optional screen area parameters to love.graphics.newScreenshot() or will it be too slow for use in the game?
Would I be better off drawing everything to a canvas first, draw the canvas to the screen, and when a picture is taken, save a scissored version of that canvas as the picture object?
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Screenshot just a specific area?
The scissor affects love.graphics.clear / Canvas:clear, but not love.graphics.newScreenshot / Canvas:getImageData.
Re: Screenshot just a specific area?
Ah, didn't even need scissor. I just created 2 canvases, one the size of the screen and the other the size of the screenshot area you want, then draw a translated version of the screen canvas onto the screenshot canvas and it will do the clipping for you.
I'm assuming that it's cheaper to keep around image objects than canvas objects, though I'm not sure if that's true. Also if the conversion from canvas to image becomes slow, it might be worth doing it in a background thread.
Code: Select all
function love.load()
screen = love.graphics.newCanvas(love.graphics.getDimensions())
end
function love.draw()
love.graphics.setCanvas(screen)
drawStuff()
love.graphics.setCanvas()
love.graphics.draw(screen)
if snap == nil then
local snapCanvas = love.graphics.newCanvas(snapWidth, snapHeight)
love.graphics.setCanvas(snapCanvas)
love.graphics.translate(-snapX, -snapY)
love.graphics.draw(screen)
love.graphics.setCanvas()
snap = love.graphics.newImage(snapCanvas:getImageData())
else
love.graphics.draw(snap)
end
screen:clear()
end
----------------------------------------
Sluicer Games
Sluicer Games
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Screenshot just a specific area?
Images and Canvases are both OpenGL textures under the hood. Keeping one OpenGL texture around is pretty much always cheaper than creating multiple.clofresh wrote:I'm assuming that it's cheaper to keep around image objects than canvas objects, though I'm not sure if that's true.
Drawing the scene to a canvas and then keeping that canvas around and drawing it when you need is better than creating ImageData from the canvas (which stalls the GPU) and then creating an Image from that ImageData (an unnecessary operation because the Canvas already has the exact same data.)
Unfortunately you can't use love.graphics functions or objects in background threads.clofresh wrote:Also if the conversion from canvas to image becomes slow, it might be worth doing it in a background thread.
Re: Screenshot just a specific area?
Ah ok, good to know. Thanks slime!
----------------------------------------
Sluicer Games
Sluicer Games
Who is online
Users browsing this forum: Semrush [Bot] and 198 guests