[−][src]Crate vxdraw
VxDraw: Simple vulkan renderer
Example - Hello Triangle
To get started, spawn a window and draw a debug triangle!
use vxdraw::{debtri::DebugTriangle, prelude::*, void_logger, Matrix4, ShowWindow, VxDraw}; fn main() { #[cfg(feature = "doctest-headless")] let mut vx = VxDraw::new(void_logger(), ShowWindow::Headless1k); #[cfg(not(feature = "doctest-headless"))] let mut vx = VxDraw::new(void_logger(), ShowWindow::Enable); vx.debtri().add(DebugTriangle::default()); vx.draw_frame(); // Sleep here so the window does not instantly disappear #[cfg(not(feature = "doctest-headless"))] std::thread::sleep(std::time::Duration::new(3, 0)); }
Animation: Rotating triangle
Here's a more interesting example:
use vxdraw::{debtri::DebugTriangle, prelude::*, void_logger, Deg, Matrix4 ShowWindow, VxDraw}; fn main() { #[cfg(feature = "doctest-headless")] let mut vx = VxDraw::new(void_logger(), ShowWindow::Headless1k); #[cfg(not(feature = "doctest-headless"))] let mut vx = VxDraw::new(void_logger(), ShowWindow::Enable); // Spawn a debug triangle, the handle is used to refer to it later let handle = vx.debtri().add(DebugTriangle::default()); for _ in 0..360 { // Rotate the triangle by 1 degree vx.debtri().rotate(&handle, Deg(1.0)); // Draw the scene vx.draw_frame(); // Wait 10 milliseconds #[cfg(not(feature = "doctest-headless"))] std::thread::sleep(std::time::Duration::new(0, 10_000_000)); } }
Logging
VxDraw is quite a lot of machinery, so it is useful for VxDraw to be able to log. To avoid hardcoding a logging dependency in the interface the library provides Logger which is a type that only depends on the standard library. You can build your own "logger bridge" using this.
use vxdraw::{prelude::*, Matrix4, *}; fn main() { let log = Box::new(|lvl: u8, msg| { struct Adapter { pub msg: Box<dyn Fn(&mut std::fmt::Formatter) -> std::fmt::Result + Send + Sync> } impl std::fmt::Display for Adapter { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { (self.msg)(f) } } println!["{} @ {}", lvl, Adapter { msg }]; }); #[cfg(feature = "doctest-headless")] let mut vx = VxDraw::new(void_logger(), ShowWindow::Headless1k); #[cfg(not(feature = "doctest-headless"))] let mut vx = VxDraw::new(void_logger(), ShowWindow::Enable); vx.debtri().add(debtri::DebugTriangle::default()); vx.draw_frame(); // Sleep here so the window does not instantly disappear #[cfg(not(feature = "doctest-headless"))] std::thread::sleep(std::time::Duration::new(3, 0)); }
Modules
blender | Blender specification |
debtri | Methods and types to control debug triangles |
dyntex | Methods and types to control dynamic textures |
prelude | This module contains the most common traits used in |
quads | Methods and types to control quads |
strtex | Methods and types to control streaming textures |
text | Methods and types to control text rendering |
utils | Various utilities and helpers for vxdraw |
Structs
Deg | An angle, in degrees. |
Matrix4 | A 4 x 4, column major matrix |
Rad | An angle, in radians. |
VxDraw | Main structure that holds all vulkan draw states |
Enums
Color | A description of a color |
ShowWindow | Information regarding window visibility |
Functions
void_logger | Create an empty logger bridge |
Type Definitions
Logger | Logger bridge type used when initializing VxDraw |