[][src]Module coffee::graphics

Draw your game with an explicit 2D graphics API.

Graphics in Coffee focus on simplicity while reducing global state. Operations like matrix transformations, off-screen rendering and draw calls have always an explicit scope. In Coffee, you do not have to remember to pop a transformation from the matrix stack, reset the render target, reset the screen coordinates, etc. There are no global functions!

Basic concepts

The graphics module revolves around three concepts: graphics processors, targets, and resources.

Graphics processors

A Gpu represents a link between your game and a graphics processor. It is necessary to perform any kind of graphical operation, like loading resources and drawing.

As of now, you will only have one Gpu available at a given time. However, in the future, the graphics module may allow recording graphical operations concurrently.

Targets

A Target represents a drawable target on a specific Gpu. A Transformation can be applied to them.

Any kind of draw operation needs an explicit Target. For example, Image::draw needs a reference to a Target as the last argument.

Currently, there are two ways to obtain a Target: either from a Frame or a Canvas, using the as_target method.

Resources

A resource is the source of some drawable object. In Coffee, there is no Resource or Drawable type/trait. Resources are represented by different types like Image, Font, TextureArray, etc.

Getting started

You should probably start your Game::draw implementation by clearing the provided Frame:

use coffee::graphics::{Color, Frame, Window};
use coffee::{Game, Timer};

impl Game for MyGame {
    // ...

    fn draw(&mut self, frame: &mut Frame, _timer: &Timer) {
        frame.clear(Color::BLACK);

        // Use your resources here...
        // self.image.draw(Sprite { ... }, &mut frame.as_target());
    }
}

You can load your resources during Game::load. Check out the different types in this module to get a basic understanding of which kind of resources are supported.

Re-exports

pub use texture_array::TextureArray;

Modules

texture_array

Build, load, and use texture arrays.

Structs

Batch

A collection of quads that will be drawn all at once using the same Image.

Canvas

An off-screen rendering target.

Color

An RGBA color in the sRGB color space.

Font

A collection of text with the same font.

Frame

The next frame of your game.

Gpu

A link between your game and a graphics processor.

Image

A loaded image.

Mesh

A set of shapes that can be drawn.

Quad

A textured quad.

Rectangle

A generic rectangle.

Sprite

A quad describing the portion of a resource in absolute coordinates.

Target

A rendering target.

Text

A section of text.

Transformation

A 2D transformation matrix.

Window

An open window.

WindowSettings

A window configuration.

Enums

CursorIcon

Describes the appearance of the mouse cursor.

HorizontalAlignment

The horizontal alignment of some resource.

Shape

A geometric figure.

VerticalAlignment

The vertical alignment of some resource.

Traits

IntoQuad

Turn a type into a quad.

Type Definitions

Point

A 2D point.

Vector

A 2D vector.