#Pixel-perfect Text2dBundle

16 messages · Page 1 of 1 (latest)

median obsidian
#

I've got a 320x180 game that's rendered to a texture (yay 0.8) and then scaled (in int steps) to fit the window size. Part of that are also Text2dBundles, but the text is really blurry. I'm doing smt. wrong?

 let txt_e = cmd
        .spawn_bundle(Text2dBundle {
            text: Text::from_section(
                format!("{count}x"),
                TextStyle {
                    font: fonts.tooltip.clone(),
                    font_size: 16.0,
                    color: Color::NONE,
                },
            )
            .with_alignment(TextAlignment::BOTTOM_CENTER),
            transform: Transform::from_xyz(0., 6., 0.),
            ..default()
        });
feral cliff
median obsidian
#

I'm scaling the already rendered texture with nearest filtering though

#

So I think the scaling is the same as with the pixelart

median obsidian
median obsidian
#

even without the scaling the text is misaligned

median obsidian
#

I switched from a render texture to bevy_pixel_camera, which uses its own projection, which will give me back native resolution, but snap sprites into int positions and scale them properly

#

but the text was still slightly blurry/anti-aliased

#

I hacked by multiplying the font size by a factor and then scaling it down by the same factor

fn on_text_2d_added(mut added_q: Query<(&mut Text, &mut Transform), Added<Text2dSize>>) {
    let factor = 20.;
    for (mut txt, mut t) in added_q.iter_mut() {
        t.scale = Vec2::splat(1. / factor).extend(1.);
        for s in txt.sections.iter_mut() {
            s.style.font_size *= factor;
        }
    }
}
#

@feral cliff
Any idea if that's as intended?
(sorry about the ping)

#

I guess the text rendering has some AA?

copper orbit
#

At this sort of scale you probably want to just use a bitmap font

#

Still looks kinda wrong admittedly, even accounting for few pixels

median obsidian
#

the scale hack gives me this, which is alright

copper orbit
#

Huh that does look good, neat!