From e58a3573816e1af6a9637e126bc84e144f6d1630 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Sun, 8 Dec 2024 18:45:49 +0100 Subject: [PATCH] Add 4 triangle --- src/renderer/app.rs | 2 +- src/renderer/render_context.rs | 5 +-- src/renderer/scene.rs | 60 ++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/renderer/app.rs b/src/renderer/app.rs index 438f946..55c6a31 100644 --- a/src/renderer/app.rs +++ b/src/renderer/app.rs @@ -12,7 +12,7 @@ use vulkano::sync::GpuFuture; use winit::application::ApplicationHandler; use winit::event::WindowEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; -use winit::window::{Window, WindowId}; +use winit::window::WindowId; use crate::renderer::render_context::RenderContext; use crate::renderer::{window_size_dependent_setup, Scene}; diff --git a/src/renderer/render_context.rs b/src/renderer/render_context.rs index cd2bc24..6ae9301 100644 --- a/src/renderer/render_context.rs +++ b/src/renderer/render_context.rs @@ -1,11 +1,8 @@ use std::sync::Arc; use vulkano::device::Device; -use vulkano::image::{Image, ImageUsage}; +use vulkano::image::ImageUsage; use vulkano::image::view::ImageView; -use vulkano::pipeline::graphics::subpass::PipelineRenderingCreateInfo; use vulkano::pipeline::graphics::viewport::Viewport; -use vulkano::pipeline::GraphicsPipeline; -use vulkano::render_pass::{Framebuffer, RenderPass}; use vulkano::swapchain::{Surface, Swapchain, SwapchainCreateInfo}; use vulkano::sync; use vulkano::sync::GpuFuture; diff --git a/src/renderer/scene.rs b/src/renderer/scene.rs index 174ba7e..f982963 100644 --- a/src/renderer/scene.rs +++ b/src/renderer/scene.rs @@ -164,17 +164,60 @@ impl Scene { // We now create a buffer that will store the shape of our triangle. let vertices = [ + // Triangle en haut à gauche MyVertex { - position: [-0.5, -0.25], - color: [1.0, 0.0, 0.0], + position: [-0.5, -0.75], // Coin supérieur gauche + color: [1.0, 0.0, 0.0], // Couleur rouge }, MyVertex { - position: [0.0, 0.5], - color: [0.0, 1.0, 0.0], + position: [-0.75, -0.25], // Coin supérieur + color: [0.0, 1.0, 0.0], // Couleur verte }, MyVertex { - position: [0.25, -0.1], - color: [0.0, 0.0, 1.0], + position: [-0.25, -0.25], // Coin supérieur droit + color: [0.0, 0.0, 1.0], // Couleur bleue + }, + + // Triangle en bas à gauche + MyVertex { + position: [-0.5, 0.25], // Coin inférieur gauche + color: [0.5, 0.5, 0.5], // Couleur gris + }, + MyVertex { + position: [-0.75, 0.75], // Coin inférieur + color: [0.2, 0.8, 0.2], // Couleur vert clair + }, + MyVertex { + position: [-0.25, 0.75], // Coin inférieur droit + color: [0.8, 0.2, 0.2], // Couleur rouge clair + }, + + // Triangle en haut à droite + MyVertex { + position: [0.5, -0.75], // Coin gauche supérieur + color: [1.0, 1.0, 0.0], // Couleur jaune + }, + MyVertex { + position: [0.25, -0.25], // Coin gauche + color: [0.0, 1.0, 1.0], // Couleur cyan + }, + MyVertex { + position: [0.75, -0.25], // Coin gauche inférieur + color: [1.0, 0.0, 1.0], // Couleur magenta + }, + + // Triangle en bas à droite + MyVertex { + position: [0.5, 0.25], // Coin droit supérieur + color: [0.1, 0.5, 0.8], // Couleur bleu clair + }, + MyVertex { + position: [0.25, 0.75], // Coin droit + color: [0.8, 0.6, 0.1], // Couleur or + }, + MyVertex { + position: [0.75, 0.75], // Coin droit inférieur + color: [0.3, 0.4, 0.6], // Couleur bleu foncé }, ]; let vertex_buffer = Buffer::from_iter( @@ -205,6 +248,9 @@ impl Scene { .unwrap(); // We add a draw command. - unsafe { builder.draw(self.vertex_buffer.len() as u32, 1, 0, 0) }.unwrap(); + let vertex_count = self.vertex_buffer.len() as u32; + let instance_count = vertex_count / 3; + + unsafe { builder.draw(vertex_count, instance_count, 0, 0) }.unwrap(); } } \ No newline at end of file