'nearest' filter for Framebuffer scaling?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
maackle
Prole
Posts: 1
Joined: Thu Dec 30, 2010 10:51 am

'nearest' filter for Framebuffer scaling?

Post 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!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: 'nearest' filter for Framebuffer scaling?

Post 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())
When I write def I mean function.
User avatar
adrix89
Party member
Posts: 135
Joined: Fri Oct 15, 2010 10:58 am

Re: 'nearest' filter for Framebuffer scaling?

Post 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?
I use Workflowy but you can check out Dynalist as its the better offer.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: 'nearest' filter for Framebuffer scaling?

Post 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
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Eshaktaar
Prole
Posts: 3
Joined: Wed Jan 13, 2010 12:45 pm
Contact:

Re: 'nearest' filter for Framebuffer scaling?

Post 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
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 79 guests