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§
Modules§
Structs§
- Context
- A struct storing the global state which is used for all operations which require access to the GPU.
- Draw
Config - How exactly should a texture be drawn?
- Texture
- A two dimensional texture stored in video memory.
- Window
Surface - A handle which can be used to draw to the window.
Enums§
- Blend
Mode - 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.
- Finalize
Error - The error returned by
Context::finalize_frame
. - Load
Texture Error - The error returned by
Texture::load
. - NewContext
Error - The error returned by
Context::new
. - NewTexture
Error - The error returned by
Texture::new
.
Traits§
- Draw
Target - A trait implemented by types upon which can be drawn.