| Crates.io | mingl |
| lib.rs | mingl |
| version | 0.3.0 |
| created_at | 2024-09-10 07:07:37.773907+00 |
| updated_at | 2025-08-09 18:35:20.585886+00 |
| description | Minimal graphics library with abstract rendering backend and WebGL support |
| homepage | https://github.com/Wandalen/cgtools/tree/master/module/min/mingl |
| repository | https://github.com/Wandalen/cgtools |
| max_upload_size | |
| id | 1370115 |
| size | 115,023 |
Agnostic graphics library providing abstract rendering backend utilities
A versatile graphics abstraction layer designed to work across different rendering backends. Provides essential utilities for camera controls, data conversion, and graphics primitives that can be used with WebGL, Metal, Vulkan, or other graphics APIs.
Add to your Cargo.toml:
mingl = { workspace = true, features = ["camera_orbit_controls"] }
use mingl::camera_orbit_controls::{Camera, OrbitControls};
fn setup_camera() {
// Create orbital camera controller
let mut camera = Camera::new()
.position([0.0, 0.0, 5.0])
.target([0.0, 0.0, 0.0])
.up([0.0, 1.0, 0.0]);
let mut controls = OrbitControls::new()
.distance(10.0)
.rotation_speed(0.5)
.zoom_speed(0.1);
// Update camera based on input
let delta_time = 0.016; // 60fps
controls.update(&mut camera, delta_time);
// Get view and projection matrices
let view_matrix = camera.view_matrix();
let (aspect_ratio, fov, near, far) = (16.0/9.0, 45.0, 0.1, 100.0);
let proj_matrix = camera.projection_matrix(aspect_ratio, fov, near, far);
}
use mingl::convert::{IntoVector, IntoBytes};
fn data_conversion_examples() {
// Convert numeric types to vectors
let float_data: Vec<f32> = vec![1.0, 2.0, 3.0, 4.0];
let vector = float_data.into_vector();
// Convert 2D arrays
let positions = [
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.5, 1.0, 0.0],
];
let vertex_buffer = positions.into_bytes();
// Handle different numeric types
let indices: Vec<u16> = vec![0, 1, 2];
let index_buffer = indices.into_bytes();
}
| Component | Purpose | Key Methods |
|---|---|---|
Camera |
3D camera management | position(), look_at(), view_matrix() |
OrbitControls |
Interactive camera controls | update(), distance(), rotation_speed() |
ToVector |
Type conversion trait | to_vector() |
ToBytes |
Buffer conversion trait | to_bytes() |
| Type | Vector Support | Bytes Support | Use Case |
|---|---|---|---|
f32 |
✅ | ✅ | Vertex positions, colors |
i8/i16/i32 |
✅ | ✅ | Signed integer data |
u8/u16/u32 |
✅ | ✅ | Indices, unsigned data |
[T; N] |
✅ | ✅ | Fixed-size arrays |
Vec<T> |
✅ | ✅ | Dynamic arrays |
use mingl::camera_orbit_controls::*;
// Configure orbital camera
let (x, y, z) = (0.0, 0.0, 5.0);
let (tx, ty, tz) = (0.0, 0.0, 0.0);
let (ux, uy, uz) = (0.0, 1.0, 0.0);
let camera = Camera::new()
.position([x, y, z])
.target([tx, ty, tz])
.up([ux, uy, uz])
.fov(60.0)
.near(0.1)
.far(100.0);
// Setup orbit controls
let controls = OrbitControls::new()
.distance(10.0) // Distance from target
.rotation_speed(1.0) // Rotation sensitivity
.zoom_speed(0.2) // Zoom sensitivity
.min_distance(1.0) // Closest zoom
.max_distance(50.0) // Farthest zoom
.enable_damping(true); // Smooth movement
use mingl::camera_orbit_controls::*;
struct CustomController {
sensitivity: f32,
momentum: Vec3,
}
impl CameraController for CustomController {
fn update(&mut self, camera: &mut Camera, input: &InputState, dt: f32) {
// Custom camera control logic
if input.mouse_down(MouseButton::Left) {
let delta = input.mouse_delta();
camera.rotate_around_target(delta.x * self.sensitivity, delta.y * self.sensitivity);
}
}
}
use mingl::convert::*;
// Batch convert vertex data efficiently
fn process_mesh_data(vertices: &[[f32; 3]], normals: &[[f32; 3]], uvs: &[[f32; 2]]) -> Vec<u8> {
let mut buffer = Vec::new();
// Interleave vertex attributes for optimal GPU access
for i in 0..vertices.len() {
buffer.extend_from_slice(&vertices[i].into_bytes());
buffer.extend_from_slice(&normals[i].into_bytes());
buffer.extend_from_slice(&uvs[i].into_bytes());
}
buffer
}
use mingl::camera_orbit_controls::*;
use mingl::convert::*;
use web_sys::{WebGl2RenderingContext, WebGlBuffer};
fn setup_webgl_scene(gl: &WebGl2RenderingContext) {
let camera = Camera::new().position([0.0, 0.0, 5.0]);
// Convert vertex data for WebGL
let vertices = vec![[0.0, 1.0, 0.0], [-1.0, -1.0, 0.0], [1.0, -1.0, 0.0]];
let vertex_buffer = vertices.into_bytes();
// Upload to GPU
let buffer = gl.create_buffer().unwrap();
gl.bind_buffer(WebGl2RenderingContext::ARRAY_BUFFER, Some(&buffer));
gl.buffer_data_with_u8_array(WebGl2RenderingContext::ARRAY_BUFFER, &vertex_buffer, WebGl2RenderingContext::STATIC_DRAW);
}
The library uses trait-based abstractions to ensure compatibility across different graphics backends while maintaining zero-cost abstractions where possible.
Strong typing prevents common graphics programming errors like incorrect buffer formats or incompatible data conversions.
All conversions and operations are designed to minimize CPU overhead and memory allocations in performance-critical rendering loops.