amethyst / bracket-lib

The Roguelike Toolkit (RLTK), implemented for Rust.
MIT License
1.53k stars 111 forks source link

Sprites artifacts with scaling #220

Open scambier opened 3 years ago

scambier commented 3 years ago

I'm trying to add sprites to my game, and there is a texture problem: depending on the sprites' size and/or the window scaling, pixels surrounding the sprite are sometimes drawn on screen.

As an example, here is the "eye" sprite, with its surrounding pixels:

image

But the in-game rendering sometimes trim pixels on a side, and sometimes add pixels from neighbour sprites image

The BTerm is built like that:

    let context = BTermBuilder::new()
        .with_title("Roguelike Tutorial")
        .with_tile_dimensions(16, 16)
        .with_simple_console(80, 50, "16x16-sb-ascii.png")
        .with_font("16x16-sb-ascii.png", 16, 16)
        .with_sprite_console(16 * 80, 16 * 50, 0)
        .with_sprite_sheet(
            SpriteSheet::new("resources/MRMOTEXT_rexpaintx2.png")
            .add_sprite(Rect::with_size(144, 352, 16, 16))
        )
        .with_vsync(false)
        .build()?;

Both PNGs have 16x16px tiles/sprites. I tried different settings to fix this issue but to no avail.

Edit: same issue when the spritesheet is used as a font file: image

scambier commented 3 years ago

Certainly a duplicate of #178

thebracket commented 3 years ago

There are still the occasional artifacts, but the merging of #239 should alleviate things a lot. Let me know how it looks now. It looks pretty sharp on my tests.

scambier commented 3 years ago

I can still reproduce the issue.

Here's an imgur gallery, to not spam this post with multiple screenshots: https://imgur.com/a/oLS1b5U

I'm on Windows 10, with a Ryzen 5 and GTX 1060

thebracket commented 3 years ago

I can't get the nasty lines to appear with the latest merge. It's a bit more sane about scaling now, and I realized I'd messed up the viewport commands in GL.

scambier commented 3 years ago

Yep, artifacts have disappeared!

There's still that issue with the squished aspect ratio, should I file another issue so we can close this one?

thebracket commented 3 years ago

We can leave it in here. It occurs to me that I completely forgot to apply the same border setup to the sprite console. I'll get that done, hopefully today (my day is a tad crazy)!

thebracket commented 3 years ago

Ignore that commit message. I accidentally put a branch in the wrong place.

thebracket commented 3 years ago

Meant to tag commit https://github.com/amethyst/bracket-lib/commit/5170417eca792ebadc0d59772961d5cf40cecbb5 for here. The "sprites" example now doesn't pull in a tiny chunk of the neighboring sprite.

I think I may need to rework the sprites layer quite a bit in the future, it's kinda half-baked right now.