[][src]Struct crow::Context

pub struct Context { /* fields omitted */ }

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

Examples

use crow::{
    glutin::{Event, EventsLoop, WindowBuilder, WindowEvent},
    Context, DrawConfig, Texture,
};

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

    let texture = Texture::load(&mut ctx, "path/to/texture.png").expect("Unable to load texture");
    let mut surface = ctx.window_surface();

    let mut fin = false;
    loop {
        ctx.events_loop().poll_events(|event| match event {
            Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                ..
            } => fin = true,
            _ => (),
        });

        ctx.clear_color(&mut surface, (0.4, 0.4, 0.8, 1.0))?;
        ctx.draw(&mut surface, &texture, (100, 150), &DrawConfig::default())?;

        ctx.finalize_frame()?;

        if fin {
            break;
        }
    }

    Ok(())
}

Methods

impl Context[src]

pub fn new(
    window: WindowBuilder,
    events_loop: EventsLoop
) -> Result<Self, ErrDontCare>
[src]

Creates a new Context. It is not possible to have more than one Context at a time.

To create a new Context after a previous context was used, The previous context has to be dropped using the method Context::unlock_unchecked(). This is a workaround and will probably be fixed in a future release.

pub fn window_dimensions(&self) -> (u32, u32)[src]

pub fn window_width(&self) -> u32[src]

pub fn window_height(&self) -> u32[src]

pub fn resize_window(&mut self, width: u32, height: u32)[src]

pub fn window_surface(&self) -> WindowSurface[src]

Returns a handle to the window surface which can be used in Context::draw to draw to the window.

pub fn draw<T>(
    &mut self,
    target: &mut T,
    source: &Texture,
    position: (i32, i32),
    config: &DrawConfig
) -> Result<(), ErrDontCare> where
    T: DrawTarget
[src]

Draws the source onto target.

To draw to the window, use Context::window_surface as a target.

pub fn debug_line<T>(
    &mut self,
    target: &mut T,
    from: (i32, i32),
    to: (i32, i32),
    color: (f32, f32, f32, f32)
) -> Result<(), ErrDontCare> where
    T: DrawTarget
[src]

Draws the a line going from from to to onto target with the given color.

To draw this line to the window, use Context::window_surface as a target.

pub fn debug_rectangle<T>(
    &mut self,
    target: &mut T,
    lower_left: (i32, i32),
    upper_right: (i32, i32),
    color: (f32, f32, f32, f32)
) -> Result<(), ErrDontCare> where
    T: DrawTarget
[src]

Draws the bounding box of an axis-aligned rectangle specified by its lower_left and upper_right corner.

In case lower_left is to the right or above upper_right, the two points will be flipped.

To draw this rectangle to the window, use Context::window_surface as a target.

pub fn clear_color<T>(
    &mut self,
    target: &mut T,
    color: (f32, f32, f32, f32)
) -> Result<(), ErrDontCare> where
    T: DrawTarget
[src]

Clears the given DrawTarget, setting each pixel to color

pub fn take_screenshot(&mut self) -> RgbaImage[src]

Stores the current state of the window in an image. This function is fairly slow and should not be used carelessly.

It is currently not possible to screenshot a part of the screen.

pub fn window(&self) -> &Window[src]

Returns the inner window.

Examples

use crow::{Context, glutin::{EventsLoop, WindowBuilder}};

let context = Context::new(WindowBuilder::new().with_title("Starting"), EventsLoop::new())
    .expect("Unable to create a context");

context.window().set_title("Running");

pub fn events_loop(&mut self) -> &mut EventsLoop[src]

pub fn finalize_frame(&mut self) -> Result<(), ErrDontCare>[src]

Presents the current frame to the screen and prepares for the next frame.

pub unsafe fn unlock_unchecked(self)[src]

Drops this context while allowing the initialization of a new one afterwards.

Safety

This method may lead to undefined behavior if a struct, for example a Texture, which was created using the current context, is used with the new context.

Trait Implementations

impl Debug for Context[src]

Auto Trait Implementations

impl !RefUnwindSafe for Context

impl !Send for Context

impl !Sync for Context

impl Unpin for Context

impl !UnwindSafe for Context

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SetParameter for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.