OpenCores
URL https://opencores.org/ocsvn/pdp1/pdp1/trunk

Subversion Repositories pdp1

[/] [pdp1/] [trunk/] [sw/] [src/] [main.rs] - Diff between revs 13 and 14

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 13 Rev 14
Line 1... Line 1...
#[macro_use]
#[macro_use]
extern crate glium;
extern crate glium;
extern crate rand;
extern crate rand;
 
extern crate time;
 
 
fn main() {
fn main() {
    use rand::Rng;
    use rand::Rng;
    let mut rng = rand::thread_rng();
    let mut rng = rand::thread_rng();
    use glium::DisplayBuild;
    use glium::DisplayBuild;
Line 11... Line 12...
        .with_dimensions(1024,1024)
        .with_dimensions(1024,1024)
        .with_title("GLscope")
        .with_title("GLscope")
        .with_vsync()
        .with_vsync()
        .build_glium()
        .build_glium()
        .unwrap();
        .unwrap();
    let mut now: f32 = 20000.0;
    let mut now: f32;
 
 
    // 2D vertex type for plot points
    // 2D vertex type for plot points
    #[derive(Copy, Clone)]
    #[derive(Copy, Clone)]
    struct Vertex {
    struct Vertex {
        position: [f32; 2],
        position: [f32; 2],
        time: f32
        time: f32  // Suggest using microseconds
    }
    }
    implement_vertex!(Vertex, position, time);
    implement_vertex!(Vertex, position, time);
    // Note: need to transform -1023..1023 to -1..1
    // Note: need to transform -1023..1023 to -1..1
    // Could extend PDP-1 display instruction to 18 bit
    // Could extend PDP-1 display instruction to 18 bit
 
 
Line 33... Line 34...
    // I can also plot points, using two shaders.
    // I can also plot points, using two shaders.
    // Those can be blended (additive in this case).
    // Those can be blended (additive in this case).
    // Time to extend the vertices with a timestamp for age?
    // Time to extend the vertices with a timestamp for age?
 
 
    // Set up a random array of points
    // Set up a random array of points
 
    /*
    let mut shape: Vec = Vec::new();
    let mut shape: Vec = Vec::new();
    for t in 0..20000 {
    for t in 0..20000 {
        shape.push(Vertex {
        shape.push(Vertex {
            position: [rng.next_f32()*2.0-1.0,
            position: [rng.next_f32()*2.0-1.0,
                       rng.next_f32()*2.0-1.0],
                       rng.next_f32()*2.0-1.0],
            time: t as f32 });
            time: t as f32 });
    }
    }*/
    let vertex_buffer =
    let vbmax = 20000;
        glium::VertexBuffer::new(&window, &shape).unwrap();
    let mut vbindex = 0;
 
    // TODO: streaming suited vertexbuffer.
 
    // Docs say to use dynamic, persistent might be GL4?
 
    let mut vertex_buffer : glium::VertexBuffer =
 
        glium::VertexBuffer::empty_dynamic(&window, vbmax).unwrap();
    let indices = glium::index::NoIndices(
    let indices = glium::index::NoIndices(
        glium::index::PrimitiveType::Points);
        glium::index::PrimitiveType::Points);
 
 
    let vertex_shader_src = r#"
    let vertex_shader_src = r#"
        #version 140
        #version 140
Line 67... Line 73...
    let fragment_shader_src = r#"
    let fragment_shader_src = r#"
        #version 140
        #version 140
        in float age;
        in float age;
        out vec4 color;
        out vec4 color;
        void main() {
        void main() {
            float intensity = 1e2*exp(-1e-2*age);
            float intensity = 1e1*exp(-8e-6*age);
            color = vec4(intensity, intensity, intensity, 1.0);
            color = vec4(intensity, intensity, intensity, 1.0);
        }
        }
    "#;
    "#;
    let program =
    let program =
       glium::Program::from_source(&window,
       glium::Program::from_source(&window,
Line 84... Line 90...
                source: glium::LinearBlendingFactor::One,
                source: glium::LinearBlendingFactor::One,
                destination: glium::LinearBlendingFactor::One },
                destination: glium::LinearBlendingFactor::One },
            .. Default::default() },
            .. Default::default() },
        .. Default::default()
        .. Default::default()
    };
    };
 
 
 
    let t0 = time::get_time();
 
 
    loop {
    loop {
        for event in window.poll_events() {
        for event in window.poll_events() {
            // Simplest nowait: use poll_events()
            // Simplest nowait: use poll_events()
            match event {
            match event {
                glium::glutin::Event::Closed => {
                glium::glutin::Event::Closed => {
Line 96... Line 105...
                },
                },
                _ => ()
                _ => ()
            }
            }
        }
        }
 
 
 
        now = (time::get_time() - t0).num_microseconds().unwrap()
 
            as f32;
 
 
 
        // Inject new points
 
        {
 
            let mut wvb = vertex_buffer.map_write();
 
            // Add 21 random points per frame
 
            for _ in 0..20 {
 
                wvb.set(vbindex, Vertex {
 
                    position: [rng.next_f32()*2.0-1.0,
 
                               rng.next_f32()*2.0-1.0],
 
                    time: now });
 
                vbindex = (vbindex+1) % vbmax;
 
            }
 
            // TODO: Read points from e.g. stdin
 
            for _ in 0..30 {
 
                let mut str = String::new();
 
                std::io::stdin().read_line(&mut str).unwrap();
 
                // FIXME: Parse line.
 
                let mut words = str.split_whitespace();
 
                let x = words.next().unwrap().parse().unwrap();
 
                let y = words.next().unwrap().parse().unwrap();
 
 
 
                wvb.set(vbindex,
 
                        Vertex {position: [x, y], time: now });
 
                vbindex = (vbindex+1) % vbmax;
 
            }
 
        }
 
 
        // Closing the window closes the program.
        // Closing the window closes the program.
        frame.clear_color(0.0, 0.0, 0.0, 1.0);
        frame.clear_color(0.0, 0.0, 0.0, 1.0);
        frame.draw(&vertex_buffer, &indices, &program,
        frame.draw(&vertex_buffer, &indices, &program,
                   //&glium::uniforms::EmptyUniforms,
                   //&glium::uniforms::EmptyUniforms,
                   &uniform! { now: now },
                   &uniform! { now: now },
                   &drawparams).unwrap();
                   &drawparams).unwrap();
        now += 1e1;
 
        if now > 13.0e3 {
 
            now = 0.0e3;
 
        }
 
 
 
        window.swap_buffers().unwrap();
        window.swap_buffers().unwrap();
    }
    }
}
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.