Crate hoplite

Crate hoplite 

Source
Expand description

§Hoplite

A creative coding framework for Rust that gets out of your way.

Write shaders, render 3D scenes, and build visualizations with a single closure. No boilerplate, no ceremony—just code for the screen.

§Quick Start

use hoplite::*;

fn main() {
    run(|ctx| {
        ctx.default_font(16.0);
        ctx.background_color(Color::rgb(0.1, 0.1, 0.15));
        ctx.enable_mesh_rendering();

        let cube = ctx.mesh_cube();

        move |frame| {
            // Fluent mesh builder API
            frame.mesh(cube)
                .at(0.0, 0.0, -5.0)
                .color(Color::RED)
                .draw();

            frame.text(10.0, 10.0, &format!("FPS: {:.0}", frame.fps()));
        }
    });
}

§Philosophy

  • One closure, one call — Setup and frame logic live in closures. No traits to implement.
  • Hot reload everything — Edit WGSL shaders and watch them update instantly.
  • Escape hatches everywhere — Start simple, access the full wgpu API when needed.
  • Type-safe handlesMeshId and TextureId prevent mix-ups at compile time.

See the repository for full documentation and examples.

Modules§

scene
Scene management for Hoplite.

Structs§

AppConfig
Configuration options for creating a Hoplite application window.
Assets
Asset manager for loading and caching resources.
Camera
A 3D camera with position, orientation, and projection parameters.
Color
RGBA color with components in the range [0.0, 1.0].
Draw2d
Immediate-mode 2D drawing API for sprites, text, and shapes.
EffectNode
Render node for full-screen shader effects.
EffectPass
A fullscreen shader effect pass.
Entity
Lightweight unique ID, or handle, of an entity
FontAtlas
A font atlas containing pre-rasterized glyphs.
FontId
Opaque identifier for a loaded font.
Frame
Context provided each frame for rendering and game logic.
FreelookCamera
A first-person camera controller with seated and unseated modes.
GeometryLoader
A fluent builder for loading and transforming geometry.
GpuContext
Core GPU context holding wgpu resources.
HotEffectNode
Hot-reloadable render node for full-screen shader effects.
HotEffectPass
A hot-reloadable fullscreen effect pass.
HotPostProcessNode
Hot-reloadable render node for screen-space post-processing.
HotPostProcessPass
A hot-reloadable post-processing pass.
HotShader
A shader source that can be hot-reloaded from disk.
HotWorldPostProcessNode
Hot-reloadable render node for world-aware post-processing.
HotWorldPostProcessPass
A hot-reloadable world-space post-processing pass.
Input
Tracks input state for keyboard and mouse across frames.
Mat4
A 4x4 column major matrix.
Mesh
GPU-resident 3D mesh geometry with vertex and index buffers.
MeshBuilder
Builder for configuring and drawing a 3D mesh.
MeshId
Type-safe handle to a mesh stored in the MeshQueue.
MeshLoader
A fluent builder for loading geometry and registering it as a mesh.
MeshNode
Render node for 3D mesh rendering with depth testing.
MeshPass
MeshQueue
Shared storage for meshes, textures, and the per-frame draw queue.
OrbitCamera
A camera controller that orbits around a target point.
PanelBuilder
Builder for drawing panels with backgrounds, borders, and optional titles.
PendingGeometry
Geometry loading state that doesn’t require a GPU reference.
PostProcessNode
Render node for screen-space post-processing effects.
PostProcessPass
A post-processing pass that samples from an input texture.
Quat
A quaternion representing an orientation.
RawGeometry
Raw geometry data before GPU upload.
Ray
A ray in 3D space, used for raycasting and picking.
RayHit
Information about a ray-collider intersection.
Rect
A rectangle in screen-space pixel coordinates.
RenderContext
Execution context passed to each render node during graph traversal.
RenderGraph
A composable render graph that executes a chain of render passes.
RenderGraphBuilder
Builder for constructing render graphs with a fluent API.
RenderMesh
Component for rendering a mesh on an entity.
RenderTarget
An off-screen render target used for intermediate pass results.
SceneSetupContext
Setup context extension for scene-based applications.
SeatedConfig
Configuration for seated mode with view constraints.
SetupContext
Context provided during the setup phase of a Hoplite application.
Sprite
A 2D sprite for UI/HUD rendering.
SpriteId
Index into the sprite storage.
Texture
A GPU texture that can be bound to shaders.
TextureId
Type-safe handle to a texture stored in the MeshQueue.
Transform
A 3D transformation representing position, rotation, and scale.
Vec2
A 2-dimensional vector.
Vec3
A 3-dimensional vector.
Vec4
A 4-dimensional vector.
Vertex3d
A vertex for 3D mesh rendering with position, normal, and texture coordinates.
World
An unordered collection of entities, each having any number of distinctly typed components
WorldPostProcessNode
Render node for world-aware post-processing effects.
WorldPostProcessPass
A post-processing pass with camera uniforms for world-space effects.

Enums§

Collider
A collision shape for picking and hit detection.
FreelookMode
Controls how the freelook camera operates.
GeometryError
Errors that can occur when loading geometry.
KeyCode
Code representing the location of a physical key
MouseButton
Describes a button of a mouse controller.
OrbitMode
Controls how the orbit camera moves.

Traits§

RenderNode
Trait for render graph nodes that can execute rendering operations.

Functions§

run
Run a Hoplite application with default configuration.
run_with_config
Run a Hoplite application with custom window configuration.
run_with_scenes
Run a Hoplite application with multiple scenes.
run_with_scenes_config
Run a scene-based application with custom window configuration.

Type Aliases§

MeshHandle
Alias for MeshId - used in ECS components.
PickResult
Result of a raycast against all colliders in the world.
TextureHandle
Alias for TextureId - used in ECS components.