Crate crow[][src]

Expand description

A pixel perfect 2D graphics library

Examples

use crow::{
    glutin::{
        event::{Event, WindowEvent},
        event_loop::{ControlFlow, EventLoop},
        window::WindowBuilder,
    },
    Context, DrawConfig, Texture,
};

fn main() -> Result<(), crow::Error> {
    let event_loop = EventLoop::new();
    let mut ctx = Context::new(WindowBuilder::new(), &event_loop)?;

    let texture = Texture::load(&mut ctx, "./textures/player.png")?;

    event_loop.run(
        move |event: Event<()>, _window_target: _, control_flow: &mut ControlFlow| match event {
            Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                ..
            } => *control_flow = ControlFlow::Exit,
            Event::MainEventsCleared => ctx.window().request_redraw(),
            Event::RedrawRequested(_) => {
                let mut surface = ctx.surface();
                ctx.clear_color(&mut surface, (0.4, 0.4, 0.8, 1.0));
                ctx.draw(&mut surface, &texture, (100, 150), &DrawConfig::default());
                ctx.present(surface).unwrap();
            }
            _ => (),
        },
    )
}

Re-exports

pub use glutin;
pub use image;

Modules

A collection of useful color matrices.

A collect of useful draw modifiers.

Structs

A struct storing the global state which is used for all operations which require access to the GPU.

How exactly should a texture be drawn?

A two dimensional texture stored in video memory.

A handle which can be used to draw to the window.

Enums

Used in DrawConfig to specify how each pixel should be draw onto the target.

The super type of every error in this crate. If this is used as a return type, the question mark operator can always be used.

The error returned by Context::finalize_frame.

The error returned by Texture::load.

The error returned by Context::new.

The error returned by Texture::new.

Traits

A trait implemented by types upon which can be drawn.