URL
https://opencores.org/ocsvn/pdp1/pdp1/trunk
Subversion Repositories pdp1
Compare Revisions
- This comparison shows the changes necessary to convert path
/pdp1/trunk/sw
- from Rev 12 to Rev 13
- ↔ Reverse comparison
Rev 12 → Rev 13
/Cargo.toml
0,0 → 1,8
[package] |
name = "glscope" |
version = "0.1.0" |
authors = ["Yann Vernier <yann@vernier.se>"] |
|
[dependencies] |
glium = "0.16.0" |
rand = "0.3" |
/src/main.rs
0,0 → 1,114
#[macro_use] |
extern crate glium; |
extern crate rand; |
|
fn main() { |
use rand::Rng; |
let mut rng = rand::thread_rng(); |
use glium::DisplayBuild; |
let builder = glium::glutin::WindowBuilder::new(); |
let window = builder |
.with_dimensions(1024,1024) |
.with_title("GLscope") |
.with_vsync() |
.build_glium() |
.unwrap(); |
let mut now: f32 = 20000.0; |
|
// 2D vertex type for plot points |
#[derive(Copy, Clone)] |
struct Vertex { |
position: [f32; 2], |
time: f32 |
} |
implement_vertex!(Vertex, position, time); |
// Note: need to transform -1023..1023 to -1..1 |
// Could extend PDP-1 display instruction to 18 bit |
|
// TODO: Set up OpenGL stuff to draw something |
//window.make_current().expect("Couldn't make context current"); |
let mut frame = window.draw(); |
use glium::Surface; |
// So far, so good. I can clear the image. |
// I can also plot points, using two shaders. |
// Those can be blended (additive in this case). |
// Time to extend the vertices with a timestamp for age? |
|
// Set up a random array of points |
let mut shape: Vec<Vertex> = Vec::new(); |
for t in 0..20000 { |
shape.push(Vertex { |
position: [rng.next_f32()*2.0-1.0, |
rng.next_f32()*2.0-1.0], |
time: t as f32 }); |
} |
let vertex_buffer = |
glium::VertexBuffer::new(&window, &shape).unwrap(); |
let indices = glium::index::NoIndices( |
glium::index::PrimitiveType::Points); |
|
let vertex_shader_src = r#" |
#version 140 |
in vec2 position; |
in float time; |
out float age; |
uniform float now; |
void main() { |
age = now-time; |
if (age >= 0) { |
gl_Position = vec4(position, 0.0, 1.0); |
} |
} |
"#; |
|
// TODO: falloff, blending? |
// Should use a uniform to indicate current time |
// Possibly add a timestamp per lit dot? |
let fragment_shader_src = r#" |
#version 140 |
in float age; |
out vec4 color; |
void main() { |
float intensity = 1e2*exp(-1e-2*age); |
color = vec4(intensity, intensity, intensity, 1.0); |
} |
"#; |
let program = |
glium::Program::from_source(&window, |
vertex_shader_src, |
fragment_shader_src, |
None).unwrap(); |
let drawparams = glium::DrawParameters { |
blend: glium::Blend { |
color: glium::BlendingFunction::Addition { |
source: glium::LinearBlendingFactor::One, |
destination: glium::LinearBlendingFactor::One }, |
.. Default::default() }, |
.. Default::default() |
}; |
loop { |
for event in window.poll_events() { |
// Simplest nowait: use poll_events() |
match event { |
glium::glutin::Event::Closed => { |
frame.finish().unwrap(); |
return; |
}, |
_ => () |
} |
} |
|
// Closing the window closes the program. |
frame.clear_color(0.0, 0.0, 0.0, 1.0); |
frame.draw(&vertex_buffer, &indices, &program, |
//&glium::uniforms::EmptyUniforms, |
&uniform! { now: now }, |
&drawparams).unwrap(); |
now += 1e1; |
if now > 13.0e3 { |
now = 0.0e3; |
} |
|
window.swap_buffers().unwrap(); |
} |
} |