piston
piston copied to clipboard
How do I `zoom` an image using nearest-neightbor scaling?
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):
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();