diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-17 21:21:55 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-17 21:21:55 -0300 |
commit | be18a9a0503fa09318b5d99452a3407a92db4366 (patch) | |
tree | 839dd18a79e4a583945c21d0b10ccbded90c4268 | |
parent | 70b5188de306b70cdf8a397dd4e0ee31f07050c8 (diff) | |
download | bezier-be18a9a0503fa09318b5d99452a3407a92db4366.tar.gz bezier-be18a9a0503fa09318b5d99452a3407a92db4366.zip |
Add new points to the bezier curve interactively
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 2c5dbcc..f01526b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ fn shader_from_source(source: &CStr, shader_type: GLenum) -> GLuint { } } -fn compile_bezier_shader(c: Bezier) -> GLuint { +fn compile_bezier_shader(c: &Bezier) -> GLuint { let vertex_shader_source = b" #version 410 core layout (location = 0) in vec3 aPos; @@ -121,17 +121,13 @@ fn compile_bezier_shader(c: Bezier) -> GLuint { gl::LinkProgram(shader_program); gl::DeleteShader(vertex_shader); gl::DeleteShader(fragment_shader); + gl::UseProgram(shader_program); } shader_program } fn main() { let mut curve = Bezier::new(); - curve.push(200, 200); - curve.push(300, 800); - curve.push(800, 100); - curve.push(1300, 800); - curve.push(1400, 200); let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); @@ -185,10 +181,10 @@ fn main() { gl::EnableVertexAttribArray(0); } - let shader_program = compile_bezier_shader(curve); - let mut event_pump = sdl_context.event_pump().unwrap(); 'running: loop { + let x = event_pump.mouse_state().x(); + let y = event_pump.mouse_state().y(); for event in event_pump.poll_iter() { match event { Event::Quit { .. } @@ -196,13 +192,19 @@ fn main() { keycode: Some(Keycode::Escape), .. } => break 'running, + Event::KeyDown { + keycode: Some(Keycode::A), + .. + } => { + curve.push(x, window_h as i32 - y); + compile_bezier_shader(&curve); + }, _ => {} } } unsafe { gl::Clear(gl::COLOR_BUFFER_BIT); - gl::UseProgram(shader_program); gl::DrawArrays(gl::TRIANGLES, 0, 6); } |