Crate crow

Source
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§

color
A collection of useful color matrices.
target
A collect of useful draw modifiers.

Structs§

Context
A struct storing the global state which is used for all operations which require access to the GPU.
DrawConfig
How exactly should a texture be drawn?
Texture
A two dimensional texture stored in video memory.
WindowSurface
A handle which can be used to draw to the window.

Enums§

BlendMode
Used in DrawConfig to specify how each pixel should be draw onto the target.
Error
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.
FinalizeError
The error returned by Context::finalize_frame.
LoadTextureError
The error returned by Texture::load.
NewContextError
The error returned by Context::new.
NewTextureError
The error returned by Texture::new.

Traits§

DrawTarget
A trait implemented by types upon which can be drawn.