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

Structs§

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

Enums§

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

Traits§

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

Functions§

default_shader
The default shader.
default_text_shader
The default text shader.
drawDeprecated
Draws the given Drawable object to the screen by calling its draw() method.
draw_queued_textDeprecated
Draws all of the Texts added via queue_text.
queue_textDeprecated
Draws text.
set_window_iconDeprecated
Sets the window icon. None for path removes the icon.
set_window_positionDeprecated
Sets the window position.
set_window_titleDeprecated
Sets the window title.
transform_rect
Applies DrawParam to Rect.
windowDeprecated
Returns a reference to the Winit window.

Type Aliases§

ImageEncodingFormat
Describes the format of an encoded image.
ImageFormat
Describes the pixel format of an image.
ZIndex
Value describing the Z “coordinate” of a draw.