refactor: simplify VertexAttribPointer call and update vertex, color, index data with alpha transparency and z-depth

This commit is contained in:
2025-09-15 13:29:57 +02:00
committed by Adrian G L (aider)
parent cdef76492f
commit 41d0819814

View File

@@ -105,14 +105,7 @@ unsafe fn create_vao(vertices: &Vec<f32>, colors: &Vec<f32>, indices: &Vec<u32>)
colors.as_ptr() as *const c_void,
gl::STATIC_DRAW,
);
gl::VertexAttribPointer(
1,
4,
gl::FLOAT,
gl::FALSE,
0,
std::ptr::null(),
);
gl::VertexAttribPointer(1, 4, gl::FLOAT, gl::FALSE, 0, std::ptr::null());
gl::EnableVertexAttribArray(1);
vao_id
@@ -189,38 +182,21 @@ fn main() {
// == // Set up your VAO around here
let vertices = vec![
// triangle 1
-0.8, -0.8, 0.0,
-0.2, -0.8, 0.0,
-0.5, -0.2, 0.0,
// triangle 2
0.2, -0.8, 0.0,
0.8, -0.8, 0.0,
0.5, -0.2, 0.0,
// triangle 3
-0.3, 0.2, 0.0,
0.3, 0.2, 0.0,
0.0, 0.8, 0.0,
];
let indices = vec![
0, 1, 2,
3, 4, 5,
6, 7, 8,
// triangle 1 (red, z=0.5)
-0.6, -0.3, 0.5, 0.6, -0.3, 0.5, 0.0, 0.6, 0.5, // triangle 2 (green, z=0.0)
-0.3, -0.6, 0.0, 0.3, -0.6, 0.0, 0.0, 0.3, 0.0, // triangle 3 (blue, z=-0.5)
-0.4, 0.4, -0.5, 0.4, 0.4, -0.5, 0.0, -0.4, -0.5,
];
let indices = vec![0, 1, 2, 3, 4, 5, 6, 8, 7];
let colors = vec![
// triangle 1 colors
1.0, 0.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 0.0, 1.0, 1.0,
// triangle 2 colors
1.0, 1.0, 0.0, 1.0,
0.0, 1.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
// triangle 3 colors
0.5, 0.5, 0.5, 1.0,
1.0, 0.5, 0.0, 1.0,
0.0, 0.5, 1.0, 1.0,
// triangle 1 colors (red, α=0.5)
1.0, 0.0, 0.0, 0.3, 1.0, 0.0, 0.0, 0.3, 1.0, 0.0, 0.0, 0.3,
// triangle 2 colors (green, α=0.5)
0.0, 1.0, 0.0, 0.3, 0.0, 1.0, 0.0, 0.3, 0.0, 1.0, 0.0, 0.3,
// triangle 3 colors (blue, α=0.5)
0.0, 0.0, 1.0, 0.3, 0.0, 0.0, 1.0, 0.3, 0.0, 0.0, 1.0, 0.3,
];
let my_vao = unsafe { create_vao(&vertices, &colors, &indices) };
// == // Set up your shaders here