From 5d643ddb4efa2b5eb1cd8e123ef0dd59b85eed42 Mon Sep 17 00:00:00 2001 From: Adrian G L Date: Thu, 18 Sep 2025 10:53:44 +0200 Subject: [PATCH] feat: render a large grid of point-particles as billboards with program point size enabled --- src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main.rs b/src/main.rs index d2a8c69..d739398 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 point‐particles + 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 point‐particles + 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));