nadir-render
The 2D renderer of the Nadir engine: y-sorted, batched sprites, tile layers drawn in chunks, a pixel-perfect camera, and the texture and atlas assets, drawn with nadir-gfx.
It is part of Nadir, a 2D engine for
top-down games on Windows, macOS and Linux, written in Rust with no
third-party crates. Games use it through
nadir_engine, which re-exports it
as nadir::render; depend on it directly to use it on its own. In a game
of the engine, App makes the Renderer and draws each frame, the
entities' sprites fill the frame's RenderFrame, and the game's tile
layers are the world resource TileLayers.
Status
Version 0.1: the API will change before 1.0.
Built:
- sprites, sorted by layer and then by the y of their pivot (their feet, by default) or a fixed depth, and drawn in instanced batches by texture;
- mirrored and rotated sprites, tinted in linear light;
- tile layers of square cells, drawn in chunks of 32 × 32 cells, only those in view, with animated and mirrored tiles, among the sprites at a layer and depth of their own;
- pixel-perfect mode: the world drawn into an image of a fixed virtual resolution, scaled up into the window by a whole factor, with bars around it, and the mapping between screen and world for the mouse;
- the
Textureasset, a QOI file uploaded to the GPU, and theAtlasasset, a cooked atlas's sprites, frames and clips.
Not yet:
- bitmap text (roadmap M7.1) and debug draw (M7.6);
- UI sprites, post effects, camera rotation, and the smooth-camera and native-resolution modes;
- shader hot reload (M5.8) and the Metal shaders (M10.3).
Usage
[]
= "0.1"
= "0.1"
= "0.1"
= "0.1"
The renderer draws with a nadir_gfx::Device, finds textures in a
nadir_assets::AssetServer, and takes nadir-core's math and color types.
This draws one sprite into a render target on an offscreen device:
use ;
use ;
use ;
use ;
A tile layer is a grid of cells, each empty or a tile of its tile set. The
renderer draws the layers a frame names, from the TileLayers it is given:
use Handle;
use ;
use ;
/// A field of 64 × 64 grass tiles, 16 world units a side, with one
/// animated tile: tiles 8 to 11 of the tile set, a quarter second each.
/// Draws the field in layer 0, behind every sprite there.
Features
headless-test builds the crate's own tests that draw on an offscreen
OpenGL context, for the workspace's CI. A user does not need it.
Platforms
The renderer draws wherever nadir-gfx has a device: on Linux today. On
Windows and macOS there is no OpenGL context yet (roadmap M2.6 and M2.7),
so no device to draw with. Everything that needs no GPU, such as the frame,
the tile layers, the atlas and the SpriteBatcher, works on all three.
Documentation
- API reference: https://docs.rs/nadir-render
- Design: https://github.com/jabbott-iii/Nadir/blob/main/docs/subsystems/render.md
- The engine: https://github.com/jabbott-iii/Nadir