feat: render a large grid of point-particles as billboards with program point size enabled

This commit is contained in:
2025-09-18 10:53:44 +02:00
parent 74342b5d1a
commit 5d643ddb4e

View File

@@ -163,6 +163,7 @@ fn main() {
gl::Disable(gl::MULTISAMPLE);
gl::Enable(gl::BLEND);
gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
gl::Enable(gl::PROGRAM_POINT_SIZE);
gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS);
gl::DebugMessageCallback(Some(util::debug_callback), ptr::null());
@@ -238,6 +239,22 @@ fn main() {
];
let billboard_vao = unsafe { create_vao(&billboard_vertices, &billboard_colors, &billboard_indices) };
// Generate a grid of pointparticles
let grid_size = 200;
let mut particle_vertices = Vec::with_capacity(grid_size * grid_size * 3);
let mut particle_colors = Vec::with_capacity(grid_size * grid_size * 4);
for i in 0..grid_size {
for j in 0..grid_size {
let x = (i as f32 / grid_size as f32 - 0.5) * 20.0;
let y = (j as f32 / grid_size as f32 - 0.5) * 20.0;
let z = -5.0;
particle_vertices.extend_from_slice(&[x, y, z]);
particle_colors.extend_from_slice(&[1.0, 1.0, 1.0, 1.0]);
}
}
let particle_vao = unsafe { create_vao(&particle_vertices, &particle_colors, &Vec::new()) };
let particle_count = (grid_size * grid_size) as i32;
// == // Set up your shaders here
// Basic usage of shader helper:
@@ -375,6 +392,12 @@ fn main() {
std::ptr::null(),
);
// Draw pointparticles
let transform_particles = projection * view * glm::identity();
gl::UniformMatrix4fv(transform_loc, 1, gl::FALSE, transform_particles.as_ptr());
gl::BindVertexArray(particle_vao);
gl::DrawArrays(gl::POINTS, 0, particle_count);
// Draw billboard (camera-facing quad)
let translation_bill = glm::translation(&glm::vec3(0.0, 0.0, -2.0));
let inv_rot_y = glm::rotation(cam_yaw, &glm::vec3(0.0, 1.0, 0.0));