diff options
author | Isaac Clayton | 2022-01-20 21:09:57 +0100 |
---|---|---|
committer | Isaac Clayton | 2022-01-20 21:09:57 +0100 |
commit | aa91d62d510613ac4efe70668dd391050ff8c5a0 (patch) | |
tree | ee4df9985c0e0aab7615d979010a550b623706b7 /src | |
parent | 5a4e8560ef7bdf6c9c3b9a0efa3be3ddc224d915 (diff) |
Work on getting rendering context set up
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/render.rs | 50 |
2 files changed, 53 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 10e7850..f0b0ccb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ mod quad; mod ctx; mod step; +mod render; fn main() { - println!("Hello, world!"); + println!("Warming up..."); + render::run(); } diff --git a/src/render.rs b/src/render.rs new file mode 100644 index 0000000..8389ab9 --- /dev/null +++ b/src/render.rs @@ -0,0 +1,50 @@ +use std::io; +use std::io::Write; + +use vulkano as vk; +use vk::instance::{Instance, InstanceExtensions, PhysicalDevice}; + +/// Reads a single line after prompting the player. +pub fn read(prompt: &str) -> String { + print!("{}", prompt); + io::stdout().flush().expect("unable to prompt user"); + + let mut input = String::new(); + io::stdin() + .read_line(&mut input) + .expect("unable to read user input"); + + return input.trim().to_string(); +} + +pub fn select_device(instance: &Instance) -> Option<device> { + // get all the devices + let devices = PhysicalDevice::enumerate(&instance).to_vec(); + + // easy choice + if devices.is_empty() { + println!("No devices detected >:("); + return None; + } else if devices.len() == 1 { + println!("Using only device present"); + return Some(devices[1]); + } + + // leave the choice up to the user + println!("Detected the following devices:"); + for (i, device) in devices.iter().enumerate() { + println!("({}) {}", i, device); + } + + // not really forgiving haha + let number = usize::from(read("Which device would you like to use: ")); + let device = devices.get(number); + device +} + +pub fn run() { + let instance = Instance::new(None, &InstanceExtensions::none(), None) + .expect("failed to create instance"); + + let device = select_device(&instance); +} |