Page 1 of 1
'nearest' filter for Framebuffer scaling?
Posted: Thu Dec 30, 2010 11:00 am
by maackle
I'm one of the many who loves nice chunky pixel art, and as we know, filters are the enemy. I know we can use (Image):setFilter to turn this off for image scaling, but I'd love it if Framebuffer could also do this. In other engines I like to render everything to a small framebuffer and then blow it up 2x with no filtering to get nice crisp aliasing. but alas, Framebuffer always applies a linear filter.
Anyone know of a way to do this? Even if I could somehow convert a Framebuffer to an Image (so I could change the filters to 'nearest'), I'd be happy for now, but I couldn't figure out how to do that either. If there's no way to do it, consider this a feature request!
Other than that, just got into LOVE a few days ago and am really loving it!
Re: 'nearest' filter for Framebuffer scaling?
Posted: Thu Dec 30, 2010 12:29 pm
by kikito
Hi there, welcome!
I haven't used framebuffers myself yet, but by reading the wiki, it seems that love.graphics.newImage with the framebuffer's imagedata will work:
Code: Select all
local fb = ... -- your framebuffer
local image = love.graphics.newImage(fb:getImageData())
Re: 'nearest' filter for Framebuffer scaling?
Posted: Thu Dec 30, 2010 1:14 pm
by adrix89
kikito wrote:Hi there, welcome!
I haven't used framebuffers myself yet, but by reading the wiki, it seems that love.graphics.newImage with the framebuffer's imagedata will work:
Code: Select all
local fb = ... -- your framebuffer
local image = love.graphics.newImage(fb:getImageData())
Wouldn't this lead to memory hell if it is in the draw function?
Re: 'nearest' filter for Framebuffer scaling?
Posted: Thu Dec 30, 2010 1:17 pm
by vrld
Creating an ImageData of a Framebuffer is a rather expensive operation. If you do it every frame, you will notice a framerate drop.
Luckily, a framebuffer is not required to scale up the whole scene: Use love.graphics.scale(2,2) and set the filter to 'nearest' on every image. You can do the latter automatically by overwriting love.graphics.newImage:
Code: Select all
local __newImage = love.graphics.newImage -- old function
function love.graphics.newImage(...) -- new function that sets nearest filter
local img = __newImage(...) -- call old function with all arguments to this function
img:setFilter('linear', 'nearest')
return img
end
Re: 'nearest' filter for Framebuffer scaling?
Posted: Thu Dec 30, 2010 1:38 pm
by Eshaktaar
adrix89 wrote:Wouldn't this lead to memory hell if it is in the draw function?
Yes, it does. I tried that, and the application quickly sucked up all the available memory.
vrld wrote:Use love.graphics.scale(2,2) and set the filter to 'nearest' on every image.
Unfortunately, this doesn't work very well if some of the images get scaled, as the individual scaling does not adhere to the "global" scaling defined with love.graphics.scale(2,2). This results in differently sized pixels which looks rather ugly. Also, any particle effects ignore the scaling.
Putting everything into a frame buffer and scaling it up right before drawing is a bit more elegant, I think. If there were a way to set the frame buffer's filter mode, I'd use it as well. There is a feature request in the tracker:
https://bitbucket.org/rude/love/issue/1 ... lter-modes