Crate riddle[−][src]
About Riddle
Riddle is a Rust media library in the vein of SDL, building as far as possible on the most active/standard rust libraries (winit, wgpu, image, etc). Riddle is NOT an engine, or a framework. It is a library devoted to exposing media related features in a unified way while avoiding prescribing program structure [note 1].
The rough feature set is listed here, along with the crates the features are primarily built upen. Riddle is only possible due to the massive efforts of the greater rust community.
- Windowing and System Event Loops, exposed through
riddle::platform
. Useswinit
. - Input State Management, exposed through
riddle::input
. - Image Loading and Basic Graphics Operations, exposed through
riddle::image
. Usesimage
. - Font Loading and Rendering, exposed through
riddle::font
. Usesrusttype
. - Math, exposed through
riddle::math
. Usesmint
for public APIs.glam
is used in other crates. - Audio Loading and Playing. Uses
rodio
. - Basic 2D Renderer, exposed through
riddle::renderer
. Useswgpu
. - Timers and Framerate Tracking, exposed throug
riddle::time
.
This crate depends on an array of crates, each of which implements a specific
feature. All sub-crates can be used independently of the top level riddle
crate, but are best used by adding a dependency on riddle
with appropriate
feature flags configured.
Each crate fully wraps the underlying libraries to allow for a consistent API
to be preserved between releases. Crates also contain extension traits, to
provide direct access to the underlying types. The few exceptions to this,
where types from other crates are exposed through Riddle’s public API are
where those crates have become defacto standards for cross crate integration,
such as mint
, and raw-window-handle
.
Cargo Features
riddle-renderer
- Theriddle-renderer-wgpu
renderer will be enabled. defaultriddle-audio
- Theriddle-audio
subsystem will be enabled. defaultriddle-font
- Theriddle-font
crate will be included, and reexported throughriddle::font
. defaultriddle-mp3
- Enable mp3 support inriddle-audio
.
Getting started
Add a git dependency in your cargo.toml [note 2].
[dependencies.riddle]
version = 0.3.0-dev
git = "https://github.com/riddle-rs/riddle/"
branch = "master"
Place the following in main.rs:
use riddle::{*, platform::*, renderer::*, common::Color}; fn main() -> Result<(), RiddleError> { // Initialize the library let rdl = RiddleLib::new()?; // Create a window and renderer let window = WindowBuilder::new().build(rdl.context())?; let renderer = Renderer::new_from_window(&window)?; // Start the main event loop rdl.run(move |rdl| { match rdl.event() { Event::Platform(PlatformEvent::WindowClose(_)) => rdl.quit(), Event::ProcessFrame => { // Clear the window with black every frame renderer.render(|render_ctx| { render_ctx.clear(Color::BLACK) }).unwrap(); } _ => (), } }) }
Notes
- A necesary exception is the top level
RiddleLib::run
function which must be used ifriddle::platform
is to be used. - Currently Riddle depends on some patches to underlying libraries, which are being maintained in forked git repositories until the changes are integrated upstream. This means Riddle can’t be uploaded to crates.io at the moment.
Re-exports
pub use riddle_common as common; |
pub use riddle_image as image; |
pub use riddle_input as input; |
pub use riddle_math as math; |
pub use riddle_platform_winit as platform; |
pub use riddle_time as time; |
pub use riddle_audio as audio; |
pub use riddle_renderer_wgpu as renderer; |
pub use riddle_font as font; |
Structs
RiddleContext | Riddle main thread context. It can be accessed before the main event loop
is started via |
RiddleLib | Riddle library initializer |
RiddleState | Riddle subsystem state handles |
Enums
Event | |
RiddleError |