Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 214a6f1fd7 | |||
| ca239bbd15 | |||
| a4b1f252ad | |||
| 5e9af0aca7 |
@@ -3,17 +3,9 @@
|
|||||||
in layout(location=0) vec3 position;
|
in layout(location=0) vec3 position;
|
||||||
in layout(location=1) vec4 aColor;
|
in layout(location=1) vec4 aColor;
|
||||||
out vec4 vColor;
|
out vec4 vColor;
|
||||||
|
uniform mat4 transform;
|
||||||
mat4 transform;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
transform = mat4(
|
|
||||||
1.0, 0.0, 0.0, 0.0,
|
|
||||||
0.0, 1.0, 0.0, 0.0,
|
|
||||||
0.0, 0.0, 1.0, 0.0,
|
|
||||||
0.0, 0.0, 0.0, 1.0
|
|
||||||
);
|
|
||||||
|
|
||||||
gl_Position = transform * vec4(position, 1.0f);
|
gl_Position = transform * vec4(position, 1.0f);
|
||||||
vColor = aColor;
|
vColor = aColor;
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/main.rs
18
src/main.rs
@@ -236,6 +236,8 @@ fn main() {
|
|||||||
.attach_file("./shaders/simple.frag")
|
.attach_file("./shaders/simple.frag")
|
||||||
.link()
|
.link()
|
||||||
};
|
};
|
||||||
|
// get uniform location for the matrix (named `transform` in your vertex shader)
|
||||||
|
let transform_loc = unsafe { simple_shader.get_uniform_location("transform") };
|
||||||
|
|
||||||
// Used to demonstrate keyboard handling for exercise 2.
|
// Used to demonstrate keyboard handling for exercise 2.
|
||||||
let mut _arbitrary_number = 0.0; // feel free to remove
|
let mut _arbitrary_number = 0.0; // feel free to remove
|
||||||
@@ -298,6 +300,22 @@ fn main() {
|
|||||||
|
|
||||||
// == // Issue the necessary gl:: commands to draw your scene here
|
// == // Issue the necessary gl:: commands to draw your scene here
|
||||||
simple_shader.activate();
|
simple_shader.activate();
|
||||||
|
// build and send the transform matrix (start from identity)
|
||||||
|
let mut transform: glm::Mat4 = glm::identity();
|
||||||
|
// cycle through each transform parameter (a,b,c,d,e,f) over time
|
||||||
|
let cycle_duration = 2.0;
|
||||||
|
let idx = ((elapsed / cycle_duration).floor() as usize) % 6;
|
||||||
|
let v = elapsed.sin();
|
||||||
|
match idx {
|
||||||
|
0 => transform[(0,0)] = v, // a
|
||||||
|
1 => transform[(0,1)] = v, // b
|
||||||
|
2 => transform[(0,3)] = v, // c
|
||||||
|
3 => transform[(1,0)] = v, // d
|
||||||
|
4 => transform[(1,1)] = v, // e
|
||||||
|
5 => transform[(1,3)] = v, // f
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
gl::UniformMatrix4fv(transform_loc, 1, gl::FALSE, transform.as_ptr());
|
||||||
gl::BindVertexArray(my_vao);
|
gl::BindVertexArray(my_vao);
|
||||||
gl::DrawElements(
|
gl::DrawElements(
|
||||||
gl::TRIANGLES,
|
gl::TRIANGLES,
|
||||||
|
|||||||
Reference in New Issue
Block a user