Skip to content

A lightweight immediate-mode 2D rendering library for Rust, built on wgpu and Metal.

License

Notifications You must be signed in to change notification settings

kumarUjjawal/libforge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libforge

Tennis Game Demo

libforge is an easy-to-use 2D graphics library for Rust, built on top of wgpu for cross-platform GPU-accelerated rendering.

Core Features

  • Immediate-mode rendering - Simple draw calls, no complex setup
  • Game-ready - Physics, sprites, animations
  • Texture support - Load from bytes, sprite sheets, sub-textures
  • GPU-accelerated - Powered by wgpu (Metal/Vulkan/DX12/WebGL)
  • Cross-platform - macOS, iOS, Windows, Linux, Web
  • Minimal dependencies - Just wgpu, winit, and a few utilities

Features

  • Primitives: draw_rect(), draw_circle(), draw_line()
  • Textures: load_texture_from_bytes(), draw_texture(), draw_subtexture()
  • Sprite Animation: SpriteAnimation, draw_sprite_animation()
  • Alpha Blending: Full transparency support
  • Color Tinting: Modify texture colors on the fly
  • Immediate Mode: No complex state management

Basic Example

use libforge::{Color, LibContext, Rect};
use std::sync::Arc;
use winit::{event_loop::EventLoop, window::Window};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let event_loop = EventLoop::new()?;
    let window = Arc::new(event_loop.create_window(Window::default_attributes())?);
    
    let mut ctx = LibContext::new_from_window(window.clone())?;
    
    // Load a texture
    let texture = ctx.load_texture_from_bytes(
        "my_image",
        include_bytes!("my_image.png")
    )?;
    
    // Render loop
    ctx.begin_frame(Some(Color([0.1, 0.1, 0.15, 1.0])));
    
    // Draw a rectangle
    ctx.draw_rect(
        Rect { x: 100.0, y: 100.0, w: 200.0, h: 150.0 },
        Color([1.0, 0.5, 0.2, 1.0])
    );
    
    // Draw a circle
    ctx.draw_circle(300.0, 200.0, 50.0, 32, Color([0.3, 0.7, 1.0, 1.0]));
    
    // Draw a texture
    ctx.draw_texture(
        texture,
        Rect { x: 400.0, y: 100.0, w: 256.0, h: 256.0 },
        Color([1.0, 1.0, 1.0, 1.0])
    );
    
    ctx.end_frame()?;
    
    Ok(())
}

Build

# Build library
cargo build

# Build with optimizations
cargo build --release

Run Tests

# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Run specific test
cargo test texture_loading

Run Examples

# Simple shapes demo
cargo run --example bouncing_shapes

# Tennis game 
cargo run --example tennis_game

# Texture loading
cargo run --example simple_texture

More Examples

Explore all examples in the examples/ directory:

Rendering Basics

Texture Features

Animating

Technology Stack

  • wgpu - Cross-platform GPU API (supports Metal, Vulkan, DX12, WebGL)
  • winit - Cross-platform windowing
  • image - Image loading (PNG, JPEG, etc.)
  • glam - Math library
  • WGSL - WebGPU Shading Language (automatically compiled to platform shaders)

Platform Support

Platform Backend Status
macOS Metal Fully Supported
iOS Metal Supported (touch input via winit)
Windows DX12/Vulkan UnTested
Linux Vulkan UnTested
Android Vulkan Untested
Web WebGPU/WebGL Untested

License

See LICENSE file for details.

About

A lightweight immediate-mode 2D rendering library for Rust, built on wgpu and Metal.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published