kriogenia/ferrux_viewport

Ferrux Viewport is an abstraction layer over the Pixels crate to manage the drawing of...

Ferrux Viewport is an abstraction layer over the Winit

FerruX Viewport

Ferrux Viewport is an abstraction layer over the Pixels crate to manage the drawing of figures and entities on a 3D space. It manages the pixel buffer exposing simple operations to draw pixels, lines and figures in the screen. In its current state it only works with Winit.

FerruX Viewport doesn't perform the pespective projection, it just manages the drawing of points already calculated into the normalized 3D space

Usage

Building a viewport

Right now, the only Viewport provided is WinitCanvas (and one mock for testing), which requires a winit Window, which will need itself an EventLoop reference.

let event_loop = winit::event_loop::EventLoop::new();
let window = winit::window::Window::new(&event_loop)?;
let viewport = ferrux_viewport::viewport::ViewportFactory::winit(&window, 100)?;

Running the viewport

The main and recommended flow to use the viewport is:

  • Use the drawing functions like draw_line and draw_triangle.
  • Call the render method to print it on screen.
  • Use reset_frame to clear the current buffer and draw a new frame.

The following example takes the Viewport we built and draws a morphing line into triangles.

let mut i = 0.0;
let step = 0.05;
let mut incrementing = true;

event_loop.run(move |event, _, control_flow| {
  match event {
    Event::MainEventsCleared => {
      i += if incrementing { step } else { -step };
      if i >= 1.0 { incrementing = false } else if i <= 0.0 { incrementing = true }
      window.request_redraw();
    }
    Event::RedrawRequested(_) => {
      viewport.fill_triangle((0.0, 0.0, -0.1), (0.0 + i, -0.5 * i/2.0, -0.2), (0.0 + i, -0.3 * i/2.0, -0.2), 
        &[255, 0, 0, 255]);
      viewport.render().expect("render failed");
      viewport.reset_buffer();
    }
    _ => (),
}

Examples

You can run the current example with

cargo run --package basic_example

About

The FerruX Viewport is a tool developed while creating the FerruXengine, an attempt of 3D graphics engine I was trying to make. I made this viewport as an improvement from my previous tool to manage the use of the Pixels buffer used by the engine (being that the FerruX Canvas).

License

Licensed, at your option, under either of:

  • Apache License, Version 2.0 (LICENSE-APACHE)
  • MIT license (LICENSE-MIT)

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Versions

Find the latest versions by id

Information - Updated Aug 09, 2022

Stars: 0
Forks: 0
Issues: 0

A mid-level 2D graphics library for rust

rgx is a 2D graphics library built on top of Vulkan/

A mid-level 2D graphics library for rust

Safe Rust bindings to the Skia Graphics Library

Safe Rust bindings to the

Safe Rust bindings to the Skia Graphics Library

Vulkano Vulkan Graphics API for Rust

Vulkano is a Rust wrapper around Wgpu-rs or the Vulkan graphics GPU API

Vulkano Vulkan Graphics API for Rust

This is a NES (Nintendo Entertainment System) emulator written in Rust using SDL2 for graphics...

This is a NES (Nintendo Entertainment System) emulator written in Rust using SDL2 for graphics and input

This is a NES (Nintendo Entertainment System) emulator written in Rust using SDL2 for graphics...

Nanachi - pure Rust 2D graphics library

NOTE: Nanachi is still buggy and the API will changed!

Nanachi - pure Rust 2D graphics library

chip8 emulator written in rust, using rust-sdl2 for graphics

Fully implemented all 35 original chip8 opcodes

chip8 emulator written in rust, using rust-sdl2 for graphics

Rust 3D graphics library for the browser

A work-in-progress Rust -&gt; WASM 3D graphics library for the browser built on top of WebGL, aimed at making it dead simple to do graphics

Rust 3D graphics library for the browser

Rust Graphics Crates

This is an opinionated list of modern graphics crates in Rust

Rust Graphics Crates

🕊 ɱ&upsilon;ɠҽ &middot; むげ

Minimal, Modular, Multiplatform Graphics Enginefor Rust and WebAssembly

🕊 ɱ&upsilon;ɠҽ &middot; むげ

A Rust library for rendering SVG Graphics with WASM

This crate provides a fast and effective way to interact with SVG's using WebAssembly

A Rust library for rendering SVG Graphics with WASM

▴ rust-wgpu-triangle

The &quot;Hello world&quot; of graphics programming in Rust + wgpu

▴ rust-wgpu-triangle
Facebook Instagram Twitter GitHub Dribbble
Privacy