Search code examples
javalibgdxtexturesinterpolation

LIBGDX Smooth pixelart rendering (is this possible?)


When I load a 16x16 pixelart image into my game and render it (upscaled in the spritebatch) it all looks fine. But when you make the window smaller the textures also get smaller (thats good) and their pixels get larger and smaller when moving (not good). Is there any way to make a small interpolation between the pixels? I tried texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); but that makes the whole texture blury. I saw the online game diep.io which has a great execution on this (grid lines) and I wondered if I could do something similar in my game with libgdx.

My textures:

different sized pixels

diep.io example

(Big frame)

enter image description here

(small frame)

enter image description here


Solution

  • I managed to find a simple way to do this. The idea with the fbo was good and I thought about it a lot.

    My solution is to just render everything to a FrameBuffer that is double the size of the frame (works best) and then downscale it to fit the frame. I basically let the downscale algorithm to the thing :).

    Thank you Thenfour. Your comment really helped me on my thoughts even if my solution is a bit different.

    Here is what I achieved:

    no scale:

    enter image description here

    scale x2:

    enter image description here

    scale x8:

    enter image description here

    I think the double sized scale looks the smoothest so I'll go with that one.