summary refs log tree commit diff
path: root/gpu_display/examples/simple_open.rs
blob: f1b57218409d29fb71c9cb328c80f36673fe2eb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use gpu_display::GpuDisplay;

fn main() {
    let mut disp = GpuDisplay::open_x(None::<&str>).unwrap();
    let surface_id = disp.create_surface(None, 1280, 1024).unwrap();

    let mem = disp.framebuffer(surface_id).unwrap();
    for y in 0..1024 {
        let mut row = [0u32; 1280];
        for x in 0..1280 {
            let b = ((x as f32 / 1280.0) * 256.0) as u32;
            let g = ((y as f32 / 1024.0) * 256.0) as u32;
            row[x] = b | (g << 8);
        }
        mem.as_volatile_slice()
            .offset(1280 * 4 * y)
            .unwrap()
            .copy_from(&row);
    }
    disp.flip(surface_id);

    while !disp.close_requested(surface_id) {
        disp.dispatch_events();
    }
}