Expand description
🐕 Bevy Keith is a 2D graphics library exposing an immediate-mode style API.
§Quick start
The central component is the Canvas
, which attached to a 2D Camera
stores the drawing commands enqueued each frame, then renders them.
To draw on a Canvas
, you typically use the RenderContext
helper.
From there you typically:
- create a
Shape
, likeRect
orRoundedRect
; - create a
Brush
via e.g.RenderContext::solid_brush()
; - fill the shape with the brush via
RenderContext::fill()
.
fn draw(mut query: Query<&mut Canvas>) {
let mut canvas = query.single_mut();
canvas.clear();
let mut ctx = canvas.render_context();
let brush = ctx.solid_brush(RED.into());
ctx.fill(Rect::from_center_size(Vec2::ZERO, Vec2::ONE), &brush);
}
§⚠️ Disclaimer
🐕 Bevy Keith is still under development. Some known limitations include:
- [Feat] Currently
Canvas
only reasonably works with a 2D orthographic camera. Other type of projections may work but are untested. - [Feat] Only solid-color brushes are currently supported; no patterns or gradients.
- [Feat] The
Canvas
is rendered to Bevy’s 2D main transparent pass; this means in particular that the Bevy UI, which is rendered later, will be rendered on top, so you cannot easily mix Bevy UI and this crate. - [Feat] Text rendering uses pre-rasterized textured glyphs. SDF-based text would fit better and would offer extra features like text outlining, which are currently hard to implement with pre-rasterizing.
- [Feat] All
Canvas
are currently full-screen, with an origin centered on the screen.Canvas::rect
is ignored; insteadOrthographicProjection::area
is used. - [Perf] Images are not batched with text, so generate extra draw calls.
§Features
🐕 Bevy Keith contains a renderer based on Signed Distance Fields (SDFs), which are mathematical descriptions of shapes to draw. This is unlike more standard renderers, like the built-in Bevy PBR renderer, which work with triangle-based meshes. An SDF representation is similar to vector graphics, and offers the advantage that the shape can be arbitrarily zoomed in and out without any loss of precision or aliasing. SDFs also enable various features like outlining and glow on any kind of shape (TODO; not yet implemented).
Currently, text rendering uses pre-rasterized glyphs stored in a texture atlas, and therefore can suffer from aliasing if zoomed in too much.
Re-exports§
pub use canvas::Canvas;
pub use canvas::Primitive;
pub use canvas::TileConfig;
pub use render_context::ImageScaling;
pub use render_context::RenderContext;
pub use text::CanvasTextId;
pub use text::KeithTextPipeline;
pub use shapes::*;
Modules§
- canvas
- A canvas represents the drawing surface storing draw commands.
- prelude
- render_
context - Rendering context exposing convenience functions to draw into a
Canvas
. - shapes
- Definition of the various shapes available to draw on a
Canvas
. - text
- Text management module.
Structs§
- Keith
Plugin - Main Keith plugin.
Enums§
- Keith
System - System sets for Keith.