25 breaking releases

Uses old Rust 2015

0.28.0 Mar 15, 2021
0.27.0 May 30, 2020
0.26.0 Oct 17, 2019
0.24.0 Jun 2, 2019
0.3.1 Jul 20, 2015

#19 in Visualization

Download history 2/week @ 2020-12-24 37/week @ 2020-12-31 13/week @ 2021-01-07 11/week @ 2021-01-14 16/week @ 2021-01-21 16/week @ 2021-01-28 10/week @ 2021-02-04 127/week @ 2021-02-11 40/week @ 2021-02-18 17/week @ 2021-02-25 10/week @ 2021-03-04 28/week @ 2021-03-11 14/week @ 2021-03-18 150/week @ 2021-03-25 7/week @ 2021-04-01 41/week @ 2021-04-08

105 downloads per month
Used in 3 crates

MIT license

20KB
256 lines

gfx_debug_draw Build Status

Library for batched renderering of lines and text in 3D space, using gfx-rs.

Documentation

Usage

// Initializing...

// Create gfx_text::Renderer to be used by the DebugRenderer
let text_renderer = {
    let factory = piston_window.device.borrow_mut().spawn_factory(); // gfx::Factory
    gfx_text::new(factory).unwrap() // can optionally configure text renderer here (font, color)
};

let mut debug_renderer = DebugRenderer::new(
    piston_window.device.borrow_mut().spawn_factory(), // gfx::Factory
    text_renderer,
	64, // Initial size of vertex buffers
).ok().unwrap();

...

// In render loop...

// Draw red line from origin along x-axis
debug_renderer.draw_line(
	[0.0, 0.0, 0.0], // Start position
	[5.0, 0.0, 0.0], // End position
	[1.0, 0.0, 0.0, 1.0], // Line color
);

// Draw an 'X' on the x-axis, at the end of the line drawn above.
debug_renderer.draw_text_at_position(
	"X", // String to draw
	[6.0, 0.0, 0.0], // World-space position to draw at
	[1.0, 0.0, 0.0, 1.0], // Text color
);

// Draw salmoney-colored text 10 pixels down and right from the top left corner of the screen
debug_renderer.draw_text_on_screen(
	"Hello World!", // Text to draw
	[10, 10], // Pixel coordinates relative to top-left corner of screen
	[1.0, 0.4, 0.4, 0.7] // Text color
);

// Draw a yellow position marker
debug_renderer.draw_marker(
    [1.0, 2.0, 3.0],  // Position
    0.5, // Size
    [1.0, 1.0, 0.0, 1.0] // Color
);

// Render the final batch of all lines and text currently present in the vertex/index buffers

debug_renderer.render(
	stream, // &mut gfx::Stream
	camera_projection, // Current camera projection matrix
);

Draw commands can also be queued up with static methods, which is useful when you want to debug something in a context where you have no access to the DebugRenderer instance.

fn foobar() {
   ...
   let x: Vector3<f32> = some_expression;
   // Visually debug the value of `x` with a red position marker:
   gfx_debug_draw::draw_marker(x, 1.0, [1.0, 0.0, 0.0, 1.0]);
   ...
}

Dependencies

~7.5MB
~137K SLoC