// This time we might return an error, so we use a Result
This time we might return an error, so we use a Result
This time we might return an error so we use a Result
async fn app(window: Window, mut gfx: Graphics, mut input: Input) -> Result<()> {
    let image = Image::load(&gfx, "image.png").await?;
    gfx.clear(Color::WHITE);
    // Set the blend pipeline
    // Use the default blend equation (which is adding the two colors)
    // Blend via the alpha of the source pixels, which means transparent objects show what's
    // underneath
    gfx.set_blend_mode(Some(BlendMode {
        equation: Default::default(),
        function: BlendFunction::Same {
            source: BlendFactor::Color {
                input: BlendInput::Source,
                channel: BlendChannel::Alpha,
                is_inverse: false,
            },
            destination: BlendFactor::Color {
                input: BlendInput::Source,
                channel: BlendChannel::Alpha,
                is_inverse: true,
            },
        },
        global_color: [0.0; 4],
    }));
    // Draw the example image with a red rectangle over it
    let region = Rectangle::new(Vector::new(200.0, 200.0), image.size());
    gfx.draw_image(&image, region);
    gfx.fill_rect(&region, Color::RED.with_alpha(0.5));
    // Set the blend pipeline again
    // Now, just use the source pixel and ignore the destination pixel, regardless of alpha
    gfx.set_blend_mode(Some(BlendMode {
        equation: Default::default(),
        function: BlendFunction::Same {
            source: BlendFactor::One,
            destination: BlendFactor::Zero,
        },
        global_color: [0.0; 4],
    }));
    let region = Rectangle::new(Vector::new(400.0, 300.0), image.size());
    gfx.draw_image(&image, region);
    gfx.fill_rect(&region, Color::RED.with_alpha(0.5));
    gfx.present(&window)?;
    loop {
        while let Some(_) = input.next_event().await {}
    }
}
async fn app ( window : Window , mut gfx : Graphics , mut input : Input ) -> Result < ( ) > { let image = Image :: load ( & gfx , " " ) . await ? ; gfx . clear ( Color :: WHITE ) ; // Set the blend pipeline // Use the default blend equation (which is adding the two colors) // Blend via the alpha of the source pixels, which means transparent objects show what's // underneath gfx . set_blend_mode ( Some ( BlendMode { equation : Default :: default ( ) , function : BlendFunction :: Same { source : BlendFactor :: Color { input : BlendInput :: Source , channel : BlendChannel :: Alpha , is_inverse : false , } , destination : BlendFactor :: Color { input : BlendInput :: Source , channel : BlendChannel :: Alpha , is_inverse : true , } , } , global_color : [ 0.0 ; 4 ] , } ) ) ; // Draw the example image with a red rectangle over it let region = Rectangle :: new ( Vector :: new ( 200.0 , 200.0 ) , image . size ( ) ) ; gfx . draw_image ( & image , region ) ; gfx . fill_rect ( & region , Color :: RED . with_alpha ( 0.5 ) ) ; // Set the blend pipeline again // Now, just use the source pixel and ignore the destination pixel, regardless of alpha gfx . set_blend_mode ( Some ( BlendMode { equation : Default :: default ( ) , function : BlendFunction :: Same { source : BlendFactor :: One , destination : BlendFactor :: Zero , } , global_color : [ 0.0 ; 4 ] , } ) ) ; let region = Rectangle :: new ( Vector :: new ( 400.0 , 300.0 ) , image . size ( ) ) ; gfx . draw_image ( & image , region ) ; gfx . fill_rect ( & region , Color :: RED . with_alpha ( 0.5 ) ) ; gfx . present ( & window ) ? ; loop { while let Some ( _ ) = input . next_event ( ) . await { } } }
This time we might return an error, so we use a Result
This time we might return an error so we use a Result
window
Window
gfx
Graphics
input
Input