v2 / vlib / sokol / sapp / screenshot.c.v
42 lines · 38 sloc · 820 bytes · 227dbc7d4a3943fe8f1541f595b6ef9851bef552
Raw
1module sapp
2
3@[heap]
4pub struct Screenshot {
5 width int
6 height int
7 size int
8mut:
9 pixels &u8 = unsafe { nil }
10}
11
12@[manualfree]
13pub fn screenshot_window() &Screenshot {
14 img_width := width()
15 img_height := height()
16 img_size := img_width * img_height * 4
17 img_pixels := unsafe { &u8(malloc(img_size)) }
18 C.v_sapp_gl_read_rgba_pixels(0, 0, img_width, img_height, img_pixels)
19 return &Screenshot{
20 width: img_width
21 height: img_height
22 size: img_size
23 pixels: img_pixels
24 }
25}
26
27// free - free *only* the Screenshot pixels.
28@[unsafe]
29pub fn (mut ss Screenshot) free() {
30 unsafe {
31 free(ss.pixels)
32 ss.pixels = &u8(nil)
33 }
34}
35
36// destroy - free the Screenshot pixels,
37// then free the screenshot data structure itself.
38@[unsafe]
39pub fn (mut ss Screenshot) destroy() {
40 unsafe { ss.free() }
41 unsafe { free(ss) }
42}
43