piston icon indicating copy to clipboard operation
piston copied to clipboard

How do I `zoom` an image using nearest-neightbor scaling?

Open alexispurslane opened this issue 7 years ago • 1 comments

I'm trying to use Piston to make a 2D pixel-art game, and as part of that I need to zoom the textures by 2x. Unfortunately, when I scale the images, Piston uses a standard, blurry, scaling algorithm. What I need is a simpler, sharper scaling algorithm, such as NN. Here's my code:

    let transform = c
        .transform
        .trans(x as f64, y as f64)
        .zoom(2.0);
    image(tile, transform, gl);

Here's what my scaled image looks like (just one tile):

image

alexispurslane avatar Aug 21 '18 01:08 alexispurslane

You can set scaling method when creating texture:

let tex = Texture::from_path(
    factory,
    "tex.png",
    Flip::None,
    &TextureSettings::new().mag(texture::Filter::Nearest)
).unwrap();

omicronns avatar Nov 07 '18 19:11 omicronns