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

Rendering to surface is upside down #631

Closed
jgarvin opened this issue Jun 22, 2020 · 2 comments · Fixed by #641
Closed

Rendering to surface is upside down #631

jgarvin opened this issue Jun 22, 2020 · 2 comments · Fixed by #641
Labels
bug Some API breaks the contract it establishes subsystem-graphics

Comments

@jgarvin
Copy link

jgarvin commented Jun 22, 2020

Describe the bug
If I render text to a surface, then render the surface to the screen, the text is flipped upside down. Happens in linux and stdweb. Possible this is a duplicate of #623, but he only mentions scale not the image being flipped.

To Reproduce

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

fn main() {
    run(
        Settings {
            size: Vector::new(1920.0, 1080.0),
            title: "Square Example",
            ..Settings::default()
        },
        app,
    );
}

async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> {
    // Clear the screen to a blank, white color
    gfx.clear(Color::WHITE);
    // Paint a blue square with a red outline in the center of our screen
    // It should have a top-left of (350, 100) and a size of (150, 100)
    let rect = Rectangle::new(Vector::new(350.0, 100.0), Vector::new(100.0, 100.0));
    let ttf = VectorFont::load("font.ttf").await?;
    
    let mut font = ttf.to_renderer(&gfx, 72.0)?;
    gfx.fill_rect(&rect, Color::BLUE);
    gfx.stroke_rect(&rect, Color::RED);
    // Send the data to be drawn
    dbg!("{:?}", window.size());

    let mut surface = Surface::new(
        &gfx,
        Image::from_raw(&gfx, None, 512, 512, PixelFormat::RGBA)?,
    )?;
    
    // // Set the render area to the surface size
    gfx.fit_to_surface(&surface)?;
    // // Draw a circle inside a rectangle
    gfx.fill_rect(
        &Rectangle::new(Vector::new(350.0, 100.0), Vector::new(100.0, 100.0)),
        Color::RED,
    );
    font.draw(
        &mut gfx,
        "Hello world!\nHello Quicksilver!",
        Color::BLACK,
        Vector::new(100.0, 100.0),
    )?;
    gfx.fill_circle(&Circle::new(Vector::new(400.0, 150.0), 50.0), Color::BLACK);
    // Flush to the surface, which draws to the image
    gfx.flush(Some(&surface))?;
    
    gfx.fit_to_window(&window);
    let image = surface.detach().expect("The image failed to detach");
    gfx.draw_image(&image, Rectangle::new_sized(Vector::new(400.0, 300.0)));
    gfx.draw_image(
        &image,
        Rectangle::new(Vector::new(400.0, 300.0), Vector::new(400.0, 300.0)),
    );
    
    gfx.present(&window)?;
    loop {
        while let Some(_) = input.next_event().await {}
    }
}

Environment and versions (please complete the following information):
Environment: Ubuntu 19.10, Chrome Version 81.0.4044.138 (Official Build) (64-bit)
Rust compiler version: rustc 1.44.0 (49cae5576 2020-06-01)
Quicksilver verison: quicksilver = "0.4.0-alpha0.5"

@ryanisaacg
Copy link
Owner

That is indeed a bug, and not a duplicate.

@ryanisaacg ryanisaacg added bug Some API breaks the contract it establishes subsystem-graphics labels Jun 22, 2020
@ryanisaacg ryanisaacg changed the title Rendering text to surface is upside down Rendering to surface is upside down Aug 1, 2020
@ryanisaacg
Copy link
Owner

This issue came up because text is most obvious, but it turns out everything is upside-down when rendering to a Surface. Oops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Some API breaks the contract it establishes subsystem-graphics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants