Expand description
This Rust crate makes it easy to render 2D and 3D graphics.
§Example
// This example draws a cube in the center of the window,
// rotating and coloring it based on the time that has passed.
use duku::Camera;
use duku::Duku;
use duku::Hsb;
use duku::Light;
use duku::Result;
use std::time::Instant;
fn main() -> Result<()> {
// create duku context and window
let (mut duku, window) = Duku::windowed(500, 500)?;
// create 3D camera with 90 fov
let camera = Camera::perspective(90);
// create directional light
let light = Light::directional("#ffffff", [-1.0, -1.0, 1.0]);
// start timer for rotation and color
let timer = Instant::now();
// start window loop
window.while_open(move |_| {
// start drawing on window
duku.draw(Some(&camera), |t| {
// setup scene
t.background("#ababab");
t.light(light);
// get elapsed time since start
let elapsed = timer.elapsed().as_secs_f32();
// transform scene
let angle = elapsed * 45.0;
t.rotate_x(angle);
t.rotate_y(angle);
t.translate_z(2.0);
// draw cube
let hue = (elapsed * 60.0) as u16;
t.tint(Hsb::new(hue, 70, 80));
t.cube([1.0, 1.0, 1.0]);
});
});
Ok(())
}More usage examples can be found here.
Modules§
- window
- Optional feature
windowmodule for simple window creation.
Structs§
- Camera
- The view into a scene.
- Canvas
- Texture that can be rendered to.
- Char
Data - Character data and metrics.
- Cubemap
- Texture representation of an environment.
- Cubemap
Sides - 6 square sides of the cubemap.
- Duku
- The renderer context.
- Duku
Builder - The render context builder.
- Font
- Font for text drawing.
- Font
Data - Font data and metrics.
- Gradient
- Color gradient.
- Handle
- A handle to a rendering resource.
- Hsb
- Color bytes in HSB with alpha.
- Light
- Light used in shadowing calculations.
- Mat4
- 4x4 Matrix.
- Material
- Material parameters to use in a shader.
- Mesh
- Shape collection for rendering
- Model
- Collection of meshes and materials.
- Model
Node - One node of the model.
- Quat
- Compact 3D rotation representation.
- Rgb
- Color bytes in RGB with alpha.
- Rgbf
- Color floats in RGB with alpha.
- Shader
- Program that runs on the GPU.
- Stats
- The stats of the current target’s render.
- Target
- Active render target.
- Texture
- Image that can be sampled in a shader.
- Vec2
- 2-component Vector.
- Vec3
- 3-component Vector.
- Vec4
- 4-component Vector.
- Window
Handle - Handle to a OS window.
Enums§
- Border
Mode - Border positioning mode.
- Color
Space - Color value representation mode.
- Error
- Crate’s
Errortype. - Filter
- Filtering mode for texture sampling.
- Format
- Image’s pixel format.
- Light
Type - Type of a light.
- Mips
- Texture mipmapping mode.
- Msaa
- Multi Sample Anti-Aliasing mode.
- Pcf
- Shadow softening used when sampling.
- Projection
- The projection type of a camera
- Shape
Mode - Shape positioning mode.
- VSync
- VSync setting for rendering.
- Wrap
- Wrapping mode for texture sampling.
Traits§
- Mix
- Trait to get color values in-between two.
Type Aliases§
- Read
Guard - RAII structure used to release the read access
- Result
- Crate’s
Resulttype. - Write
Guard - RAII structure used to release the write access