Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect coordinate system scale when rendering on a surface #623

Closed
sssilver opened this issue Jun 10, 2020 · 0 comments · Fixed by #641
Closed

Incorrect coordinate system scale when rendering on a surface #623

sssilver opened this issue Jun 10, 2020 · 0 comments · Fixed by #641

Comments

@sssilver
Copy link
Contributor

Describe the bug
Coordinate system scale when drawing on a Surface does not match the coordinate system scale of the surface size.

image

To Reproduce
The above image is rendered by the following code:

use quicksilver::{
    geom::{Rectangle, Vector},
    golem::TextureFilter,
    graphics::{Color, Image, PixelFormat, Surface},
    run, Graphics, Input, Result, Settings, Window,
};

fn main() {
    log::set_max_level(log::LevelFilter::Info);
    run(
        Settings {
            title: "Realm",
            ..Settings::default()
        },
        app,
    );
}

async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> {
    let width = 200.0;
    let height = 100.0;

    let mut surface = Surface::new(
        &gfx,
        Image::from_raw(&gfx, None, width as u32, height as u32, PixelFormat::RGB)?,
    )?;

    gfx.fit_to_surface(&surface)?;
    gfx.clear(Color::YELLOW);
    gfx.fill_rect(
        &Rectangle::new_sized(Vector::new(width, height)),
        Color::RED,
    );
    gfx.flush(Some(&surface))?;

    gfx.clear(Color::GREEN);
    gfx.fit_to_window(&window);
    let image = surface.detach().unwrap();
    image.set_magnification(TextureFilter::Nearest).unwrap();
    gfx.draw_image(
        &image,
        Rectangle::new_sized(Vector::new(window.size().x / 2.0, window.size().y / 2.0)),
    );
    gfx.present(&window)?;

    loop {
        while let Some(_) = input.next_event().await {}
    }
}

However, since width and height are passed both to Image::from_raw() size for Surface::new() and toRectangle::new_sized(), my expectation is that the red rectangle would completely, seamlessly fill the yellow surface. Instead, it appears on only the lower left ~1/5th of the surface, while the rest of it remains yellow.

Environment and versions (please complete the following information):

  • Environment: macOS Catalina
  • Rust compiler version: rustc 1.43.1 (8d69840ab 2020-05-04)
  • Quicksilver verison: 0.4.0-alpha0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant