Verdant is a work-in-progress. Parts of the API may change at any time.
See boids.rs
See clock.rs
See paint.rs
Verdant is a rendering and windowing library for Rust, inspired by Processing, made to be accessible.
Built on top of wgpu and winit, Verdant focuses on a clean, expressive, and easy-to-use API that makes common rendering tasks easy and mistakes difficult.
Finally, a foundational rendering library that is easy to use.
use verdant::{Renderer, RendererResult, WindowEvent, canvas::RenderSurface, rgb, shapes::{Drawable, Rect}};
fn main() -> RendererResult<()> {
// initialize the renderer and create a window
let mut renderer = Renderer::new()?;
let window_id = renderer.create_window("verdant hello world", 800, 600);
// main drawing loop
// `is_running` returns true while there is at least one window open
while renderer.is_running() {
// poll for events...
for (id, event) in renderer.poll() {
// ...and handle window closing
if event == WindowEvent::CloseRequested {
renderer.close_window(id);
}
}
// start drawing by getting a window
if let Some(window) = renderer.get_window(window_id) {
// clearing the background to a neutral color
window.background(rgb(0.15, 0.15, 0.15));
// and drawing a circle
window.fill(rgb(0.8, 0.3, 0.3));
window.ellipse(400., 300., 100., 100.);
}
// and finishing off the frame by flushing all draw commands to the GPU
renderer.flush()?;
}
Ok(())
}Verdant aims to be performant and powerful, while still remaining lightweight and nice to use.
Verdant is a rendering/windowing library. It is not a game engine or a UI framework, it does not handle audio, it does not handle physics.
It is a foundation you can build those things on top of.
Almost all Verdant primitives are rendered using SDFs (signed-distance-fields). This allows for your graphics to have perfect anti-aliasing and rounding, at any scale, while remaining efficient.
Most graphics libraries start with a single window and treat additional windows as an advanced feature. Verdant easily and cleanly supports multiple windows, built into the API since day one.
See multi_window.rs
Most graphics libraries have functions like push_state and pop_state.
This is powerful, but it can lead to mistakes where state is leaked out of the context where you need it.
Verdant prevents this by providing scoped state through closures.
See scoped_state.rs
Verdant doesn't force you to stick to a state machine API or a more "retained" builder pattern API, instead allowing you to choose between either one.
// imperative, state-machine API
window.fill(Color::RED);
window.rect(500., 250., 250., 250.);
// more "declarative", builder pattern API
Rect::at(250., 500.)
.size(250., 250.)
.fill(Color::BLUE)
.draw(window);You can use the imperative, stateful API for quick prototyping or things that change every frame, or you can pick the declarative, builder API for things that hold state between frames.
See drawing.rs
Verdant provides both a basic text API and a rich text API, allowing you to mix fonts, colors, sizes, and styles, all in a single function call.
See rich_text.rs
Verdant allows you to render to off-screen surfaces just as easily as rendering to a window. It even lets you render a canvas to itself, allowing for recursive effects!
Verdant allows you to define a logical rendering space, independent of the physical window size. This allows you to create scalable applications without having to manually handle aspect-ratio math.
See views.rs
Verdant lets you choose how outlines and corner radii scale. They can behave like physical geometry, remain at a constant pixel size, or respond independently to transforms and view scaling. This makes it easy to build everything from scalable interfaces to interactive visualizations without sacrificing visual consistency.
See scaling_modes.rs
(The window has been resized to be much larger than the original size, on the left the outlines and corner radii scale with the window, and on the right they stay at a constant pixel size)
Add this to your Cargo.toml:
[dependencies]
verdant = "0.6"Currently, Verdant only supports desktop, though web/mobile support is planned soon.
By default, Verdant includes granular features to control what gets built. If you don't need asset loading and/or text and want a lighter dependency tree, you can disable them:
[dependencies]
verdant = { version = "0.6", default-features = false, features = ["vulkan", "dx12", "metal"] }If you want legacy OpenGL support:
[dependencies]
verdant = { version = "0.6", default-features = false, features = ["vulkan", "dx12", "metal", "gles"] }It also has granular features for different image formats:
[dependencies]
verdant = { version = "0.6", default-features = false, features = ["vulkan", "dx12", "metal", "image-png", "image-jpeg", "image-webp"] }By default, image-png and image-jpeg are enabled.
To try out the examples locally, clone the repository and run them using Cargo:
git clone https://github.com/grimtin10/verdant.git
cd verdant
cargo run --example boids --release
cargo run --example clock --releaseFor any feedback on the API or for feature requests, please go to the issues page.
Verdant is licensed under MPL-2.0.
Applications built with Verdant may be distributed under any license. Only modifications to Verdant itself are required to remain MPL-licensed.