1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/sokol/sapp/screenshot.c.v

43 lines
800 B
V
Raw Normal View History

module sapp
[heap]
pub struct Screenshot {
width int
height int
size int
mut:
pixels &byte
}
[manualfree]
pub fn screenshot_window() &Screenshot {
img_width := width()
img_height := height()
img_size := img_width * img_height * 4
img_pixels := unsafe { &byte(malloc(img_size)) }
C.v_sapp_gl_read_rgba_pixels(0, 0, img_width, img_height, img_pixels)
return &Screenshot{
width: img_width
height: img_height
size: img_size
pixels: img_pixels
}
}
// free - free *only* the Screenshot pixels.
[unsafe]
pub fn (mut ss Screenshot) free() {
unsafe {
free(ss.pixels)
ss.pixels = &byte(0)
}
}
// destroy - free the Screenshot pixels,
// then free the screenshot data structure itself.
[unsafe]
pub fn (mut ss Screenshot) destroy() {
unsafe { ss.free() }
unsafe { free(ss) }
}