Skip to main content

render_to_image

Function render_to_image 

Source
pub fn render_to_image(width: u32, height: u32) -> Result<Vec<u8>>
Expand description

Renders the current scene to a raw RGBA pixel buffer.

Creates a headless GPU context, renders one frame of the current scene, and returns the pixel data as Vec<u8> in RGBA format (4 bytes per pixel).

The returned buffer has dimensions width * height * 4 bytes. Pixels are ordered row-by-row from top-left to bottom-right.

ยงExample

use polyscope_rs::*;

init().unwrap();
register_point_cloud("pts", vec![Vec3::ZERO, Vec3::X, Vec3::Y]);
let pixels = render_to_image(800, 600).unwrap();
assert_eq!(pixels.len(), 800 * 600 * 4);