Module ggez::graphics

source ·
Expand description

The graphics module performs the perhaps most important task of ggez, which is drawing things onto the screen.

The rough workflow for this is usually as follows:

  1. Create something that you want to render (Meshes, Images, InstanceArrays or Texts).
  2. Create a Canvas to render them onto (usually by calling Canvas::from_frame, to draw directly onto the screen).
  3. (Select a custom shader and/or blend mode if you desire.)
  4. Queue draw calls by calling the appropriate draw method on Canvas (Canvas::draw, Canvas::draw_<whatever>).
  5. (Go back to step 3 if you want to add more draw calls with different shaders or blend modes.)
  6. Submit the draw queue by calling Canvas::finish.

A Canvas represents a single render pass, operating on a certain render target. You can create Canvases that render to an image, instead of directly to the screen, with Canvas::from_image and other related functions. With these you can, for example, render your scene onto an Image held by a Canvas first and then render that Image onto the screen, using a different shader, to do some post-processing.

The module also handles the creation of Images and other drawable objects and the screen coordinate system / projection matrix through Canvas.


  • Describes a blend component of a [BlendState].
  • Describes the blend mode used when drawing images.
  • Canvases are the main method of drawing meshes and text to images in ggez.
  • A RGBA color in the sRGB color space represented as f32’s in the range [0.0-1.0]
  • A struct containing all the necessary info for drawing with parameters.
  • Parameters for the fill tessellator.
  • Font data that can be used to create a new font in GraphicsContext.
  • A concrete graphics context for WGPU rendering.
  • Handle to an image stored in GPU memory.
  • Array of instances for fast rendering of many meshes.
  • A RGBA color in the linear color space, suitable for shoving into a shader.
  • Mesh data stored on the GPU as a vertex and index buffer. Cheap to clone.
  • Builder pattern for constructing meshes.
  • Borrowed mesh data.
  • Pixel scale.
  • A Drawable unit type that maps to a simple 1x1 quad mesh.
  • A simple 2D rectangle.
  • Sampler state that is used when sampling images on the GPU.
  • An image which is sized relative to the screen. This is primarily for canvas images.
  • A custom shader that can be used to render with shader effects.
  • Builder pattern for assembling shaders.
  • Parameters that can be passed to a custom shader, including uniforms, images, and samplers.
  • A builder for ShaderParams
  • Parameters for the tessellator.
  • Drawable text object. Essentially a list of TextFragment. and some cached size information.
  • Parameters of a single piece (“fragment”) of text, including font, color, and size.
  • Describes text alignment along both axes.
  • Vertex format uploaded to vertex buffers.
  • WGPU graphics context objects.


  • Alpha blend factor.
  • Alpha blend operation.
  • Describes the clamping mode of a sampler, used when the shader writes to sample outside of texture boundaries.
  • Specifies whether a mesh should be drawn filled or as an outline.
  • The fill rule defines how to determine what is inside and what is outside of the shape.
  • Describes the filter mode of a sampler, used when magnification or minification of a texture occurs (i.e. scaling).
  • Line cap as defined by the SVG specification.
  • Line join as defined by the SVG specification.
  • Describes text alignment along a single axis.
  • A struct that represents where to put a drawable object.


  • All types that can be drawn onto a canvas implement the Drawable trait.


Type Definitions