[][src]Struct quicksilver::graphics::Graphics

pub struct Graphics { /* fields omitted */ }

The struct that handles sending draw calls to the GPU

The basic flow of using Graphics is a loop of Graphics::clear, draw, and Graphics::present.

When drawing, keep in mind the projection and transformation. The projection is set by [Graphics::set_projection], and usually Transform::orthographic. It is a transformation applied to every single vertex, and it's advised to keep it constant as much as possible. The transformation is used to rotate, scale, or translate a handful of draw calls, and is set by Graphics::set_transform.

For best performance, try to reduce unnecessary state changes. Sources of state changes include changing the image you're drawing, changing the projection, or changing the type of geomety you're drawing.

Implementations

impl Graphics[src]

pub fn into_raw_context(self) -> Context[src]

Turn this high-level graphics object into a low-level graphics context

It is by design that this is a one-way operation. In order for the graphics API to be safe, Quicksilver takes full control of the context and all shaders. If you want to use custom shaders or rendering setups, you can no longer use the high-level graphics API.

The context returned is the context from the golem rendering library, which is the library Quicksilver's graphics stack is built on. The main advantage you gain is custom shaders, as well as being able to manage multiple different GPU buffers. See the golem crate for more details.

pub fn clear(&mut self, color: Color)[src]

Clear the screen to the given color

pub fn set_view(&mut self, transform: Transform)[src]

Set the view matrix, which is applied to all vertices on the GPU

Most of the time, you won't need this at all. However, if you want to apply a change to a great many objects (screen shake, rotations, etc.) setting the view matrix is a good way to do that.

pub fn set_transform(&mut self, transform: Transform)[src]

Set the transformation matrix, which is applied to all vertices on the CPU

Use this to rotate, scale, or translate individual draws or small groups of draws.

pub fn screen_to_camera(&self, window: &Window, position: Vector) -> Vector[src]

Project a point from the screen to the world

Use this when checking the mouse position against rendered objects, like a game or UI. The given point is scaled from the window to the size of the virtual camera (see set_camera_size) and the inverse of the view (see set_view).

pub fn set_camera_size(&mut self, size: Vector)[src]

Set the size of the virtual camera

Regardless of the size of the actual window, the draw functions all work on a virtual camera size. By default, this is the initial size in your Settings. If you start at 400x300, a 400x300 Rectangle will fill the drawable area. If the Window is doubled in size, a 400x300 Rectangle will still fill the drawable area. This function changes the size of the 'virtual camera.'

If you want to position a camera at an arbitrary point within world space, or apply rotations or scaling, use set_view.

pub fn set_resize_handler(&mut self, resize: ResizeHandler)[src]

Change how to respond to the window resizing

The default method of handling resizes is ResizeHandler::Fit, which maximizes the area drawn on screen while maintaining aspect ratio. There are a variety of other ResizeHandler options to choose from.

pub fn set_blend_mode(&mut self, blend_mode: Option<BlendMode>)[src]

Set the blend mode, which determines how pixels mix when drawn over each other

Pass None to disable blending entirely

pub fn draw_elements(
    &mut self,
    vertices: impl Iterator<Item = Vertex>,
    elements: impl Iterator<Item = Element>,
    image: Option<&Image>
)
[src]

Draw a collection of vertices

Elements determines how to interpret the vertices. While it is convenient to mix-and-match within a single call, be aware that this can incur a performance penalty.

If any of the provided vertices reference an image, they will use the provided image.

pub fn draw_point(&mut self, pos: Vector, color: Color)[src]

Draw a single, pixel-sized point

pub fn draw_mesh(&mut self, mesh: &Mesh)[src]

Draw a mesh, which is shorthand for passing the Mesh's data to Graphics::draw_elements

pub fn fill_polygon(&mut self, points: &[Vector], color: Color)[src]

Draw a filled-in polygon of a given color

The provided points must form a clockwise or counter-clockwise set of points in a convex polygon

pub fn stroke_path(&mut self, points: &[Vector], color: Color)[src]

Draw a series of lines that connect the given points, in order

pub fn stroke_polygon(&mut self, points: &[Vector], color: Color)[src]

Draw an outline of a polygon of a given color

The provided points must form a clockwise or counter-clockwise set of points in a convex polygon

pub fn fill_rect(&mut self, rect: &Rectangle, color: Color)[src]

Draw a filled-in rectangle of a given color

pub fn stroke_rect(&mut self, rect: &Rectangle, color: Color)[src]

Outline a rectangle with a given color

pub fn fill_circle(&mut self, circle: &Circle, color: Color)[src]

Draw a filled-in circle of a given color

pub fn stroke_circle(&mut self, circle: &Circle, color: Color)[src]

Outline a circle with a given color

pub fn draw_image(&mut self, image: &Image, location: Rectangle)[src]

Drawn an image to the given area, stretching if necessary

pub fn draw_image_tinted(
    &mut self,
    image: &Image,
    location: Rectangle,
    tint: Color
)
[src]

Drawn a tinted image to the given area, stretching if necessary

The tint is applied by multiplying the color components at each pixel. If the Color has (r, g, b, a) of (1.0, 0.5, 0.0, 1.0), all the pixels will have their normal red value, half their green value, and no blue value.

pub fn draw_subimage(
    &mut self,
    image: &Image,
    region: Rectangle,
    location: Rectangle
)
[src]

Draw a given part of an image to the screen, see Graphics::draw_image

pub fn draw_subimage_tinted(
    &mut self,
    image: &Image,
    region: Rectangle,
    location: Rectangle,
    tint: Color
)
[src]

Draw a given part of a tinted image to the screen, see Graphics::draw_image_tinted

pub fn flush_surface(
    &mut self,
    surface: &Surface
) -> Result<(), QuicksilverError>
[src]

Draw to a Surface

pub fn flush_window(&mut self, window: &Window) -> Result<(), QuicksilverError>[src]

Draw to the Window, without writing those changes to the screen

pub fn present(&mut self, win: &Window) -> Result<(), QuicksilverError>[src]

Send the draw data to the GPU and paint it to the Window

On desktop, this will block until drawing has completed. If vsync is enabled, it will block until the frame completes. Call this at the end of your frame.

Auto Trait Implementations

impl !RefUnwindSafe for Graphics

impl !Send for Graphics

impl !Sync for Graphics

impl Unpin for Graphics

impl !UnwindSafe for Graphics

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, 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.