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:
- Create something that you want to render (
Mesh
es,Image
s,InstanceArray
s orText
s). - Create a
Canvas
to render them onto (usually by callingCanvas::from_frame
, to draw directly onto the screen). - (Select a custom shader and/or blend mode if you desire.)
- Queue draw calls by calling the appropriate draw method on
Canvas
(Canvas::draw
,Canvas::draw_<whatever>
). - (Go back to step 3 if you want to add more draw calls with different shaders or blend modes.)
- Submit the draw queue by calling
Canvas::finish
.
A Canvas
represents a single render pass, operating on a certain render target.
You can create Canvas
es 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 Image
s and other drawable objects and the screen
coordinate system / projection matrix through Canvas
.
Structs
- 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 asf32
’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.
Enums
- 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.
Traits
- All types that can be drawn onto a canvas implement the
Drawable
trait.
Functions
- The default shader.
- The default text shader.
- drawDeprecatedDraws the given Drawable object to the screen by calling its draw() method.
- draw_queued_textDeprecatedDraws all of the Texts added via
queue_text
. - queue_textDeprecatedDraws text.
- set_window_iconDeprecatedSets the window icon.
None
for path removes the icon. - set_window_positionDeprecatedSets the window position.
- set_window_titleDeprecatedSets the window title.
- Applies
DrawParam
toRect
. - windowDeprecatedReturns a reference to the Winit window.
Type Definitions
- Describes the format of an encoded image.
- Describes the pixel format of an image.
- Value describing the Z “coordinate” of a draw.