1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Automatically generate screenshots for all examples (#2379)

This commit is contained in:
Emil Ernerfeldt
2022-12-04 17:27:40 +01:00
committed by GitHub
parent b774159fc8
commit 48666e1d7a
60 changed files with 206 additions and 30 deletions

View File

@@ -74,23 +74,25 @@ impl eframe::App for MyApp {
self.take_screenshot = false;
if let Some(gl) = frame.gl() {
let mut buf = vec![0u8; screen_size_px[0] as usize * screen_size_px[1] as usize * 4];
let [w, h] = screen_size_px;
let mut buf = vec![0u8; w as usize * h as usize * 4];
let pixels = glow::PixelPackData::Slice(&mut buf[..]);
unsafe {
gl.read_pixels(
0,
0,
screen_size_px[0] as i32,
screen_size_px[1] as i32,
w as i32,
h as i32,
glow::RGBA,
glow::UNSIGNED_BYTE,
pixels,
);
}
// Flip vertically:
let mut rows: Vec<Vec<u8>> = buf
.into_iter()
.chunks(screen_size_px[0] as usize * 4)
.chunks(w as usize * 4)
.into_iter()
.map(|chunk| chunk.collect())
.collect();