summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs20
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);
}