Skip to content

Text rasterization is based on world units instead of pixels #1890

@janikrabe

Description

@janikrabe

Bevy version

  • v0.5.0
  • v0.6.0
  • v0.7.0

Operating system & version

Linux/Wayland

What you did

Modify the camera in the text2d example to use a scale of 0.1:

use bevy::prelude::*;
use bevy::render::camera::{DepthCalculation, OrthographicProjection};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands
        .spawn_bundle(OrthographicCameraBundle::new_2d())
        .insert(OrthographicProjection {
            near: 0.0,
            far: 1000.0,
            scale: 0.1,
            depth_calculation: DepthCalculation::ZDifference,
            ..Default::default()
        });
    commands.spawn_bundle(Text2dBundle {
        text: Text::with_section(
            "Hello.",
            TextStyle {
                font: asset_server.load("fonts/FiraSans-Bold.ttf"),
                font_size: 25.0,
                color: Color::WHITE,
            },
            TextAlignment {
                vertical: VerticalAlign::Center,
                horizontal: HorizontalAlign::Center,
            },
        ),
        ..Default::default()
    });
}

What you expected to happen

The text should rasterize properly with no visible artifacts.

What actually happened

The text is rasterized to 10x10 pixel squares (1/scale).

raster

Additional information

This can also be seen with ScalingMode::FixedHorizontal when the scale does not match the window's width:

// ...
.insert(OrthographicProjection {
    near: 0.0,
    far: 1000.0,
    window_origin: WindowOrigin::Center,
    scaling_mode: ScalingMode::FixedHorizontal,
    scale: 100.0,
    depth_calculation: DepthCalculation::ZDifference,
    ..Default::default()
});
// ...

(The same applies to ScalingMode::FixedVertical, of course.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenA-TextRendering and layout for charactersA-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions