Pass uniform for elapsed

This commit is contained in:
ScorpionX90
2025-09-17 11:30:46 +02:00
parent d5bdf814bd
commit cd5d327cec
10 changed files with 16 additions and 9 deletions

View File

@@ -40,3 +40,6 @@ OpenGL does a simple interpolation between the vertex colors, and assigns a colo
![](./images/transparent_triangles.png)
Here we have drawn three partially overlapping triangles drawn in the order "red - green - blue" with red having the highest z-index (furthest back), followed by green and finally blue. All triangles are rendered with alpha = 0.4
TODO TASK 2B)

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -2,18 +2,19 @@
layout(location=0) in vec3 position;
layout(location=1) in vec4 vertex_colors;
uniform float elapsed;
out vec4 fragment_colors;
// this matrix mirrors over the x-axis and the y-axis simultaneously
const mat4 flip = mat4(
vec4(-1.0f, 0.0f, 0.0f, 0.0f), // column 0
vec4( 0.0f, -1.0f, 0.0f, 0.0f), // column 1
vec4( 0.0f, 0.0f, 1.0f, 0.0f), // column 2
vec4( 0.0f, 0.0f, 0.0f, 1.0f) // column 3
);
void main()
{
gl_Position = flip * vec4(position, 1.0f);
// this matrix mirrors over the x-axis and the y-axis simultaneously
mat4 ID_MAT = mat4(
vec4( 1.0f, 0.0f, 0.0f, 0.0f), // column 0
vec4( 0.0f, elapsed, 0.0f, 0.0f), // column 1
vec4( 0.0f, 0.0f, 1.0f, 0.0f), // column 2
vec4( 0.0f, 0.0f, 0.0f, 1.0f) // column 3
);
gl_Position = ID_MAT * vec4(position, 1.0f);
fragment_colors = vertex_colors;
}

View File

@@ -217,6 +217,7 @@ fn main() {
let vao_id = unsafe { create_vao(&vertices, &indices, &colors) };
// == // Set up your shaders here
// Basic usage of shader helper:
@@ -296,7 +297,9 @@ fn main() {
// Clear the color and depth buffers
gl::ClearColor(0.035, 0.046, 0.078, 1.0); // night sky
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
let loc = simple_shader.get_uniform_location("elapsed");
gl::Uniform1f(loc, elapsed.sin());
gl::DrawElements(gl::TRIANGLES, indices.len() as i32, gl::UNSIGNED_INT, ptr::null());
}