2 releases

0.0.2 May 25, 2023
0.0.1 May 24, 2023

#354 in Multimedia

21 downloads per month

MIT license

10KB
237 lines

gl-capture

Latest Version Docs License

Library for capturing screenshots in OpenGL.

See examples/basic.rs for a complete example.

let img = unsafe { gl_capture::capture() };
// img.size: (u32, u32)
// img.data: Vec<capture_gl::Rgb>
// Now use e.g. `png` or `image` crate to save the image data to a file

Alternatively, use capture_into() to reuse the same image data, instead of reallocating on every call.

let mut img = gl_capture::RgbImageData::new(size);
unsafe {
    gl_capture::capture_into(&mut img);
}
// img.size: (u32, u32)
// img.data: Vec<capture_gl::Rgb>

Also supports other formats, e.g. RgbaImageData, BgrImageData, BgraImageData.

When manually using gl::ReadPixels(), instead it is also possible to use read_pixels() or read_pixels_ptr(), which performs some additional checks and setup.

let format = gl_capture::CaptureFormat::Rgb;
let mut data = format.allocate_pixel_data(size);

unsafe {
    gl_capture::read_pixels((0, 0), size, format, &mut data);
}

Dependencies

~120KB