Default to fullscreen
Description
Instead of displaying individual cubes, we now want to render larger worlds. However, viewing it through the default winit window feels a bit cramped.
This change updates the window builder to go fullscreen mode by default. However, it includes a command-line flag to continue running it in windowed mode if you prefer.
To pass in command-line arguments when running with cargo, you need to specify double-dashes first:
cargo run -- -w
cargo run -- --windowed
You can also run the binary directly after compiling it:
cargo build
./target/debug/iridium -w
Or for the optimized version:
cargo build --release
./target/release/iridium -w
Commands
git clone git@github.com:atsheehan/iridium
cd iridium
git checkout 54773c5f1a345ddfdc6dc50ccf7c20abb9032af6
cargo run --release
Code Changes
Modified src/main.rsGitHub
@@ -10,8 +10,10 @@1010 };
1111
1212 fn main() {
13+ let options = get_options();
14+
1315 let event_loop = EventLoop::new().unwrap();
14- let mut renderer = Renderer::new(&event_loop);
16+ let mut renderer = Renderer::new(&event_loop, options.windowed);
1517
1618 event_loop
1719 .run(move |event, window_target| match event {
@@ -58,3 +60,13 @@5860 })
5961 .unwrap();
6062 }
63+
64+ struct GameOptions {
65+ windowed: bool,
66+ }
67+
68+ fn get_options() -> GameOptions {
69+ let args: Vec<String> = std::env::args().collect();
70+ let windowed = args.iter().any(|arg| arg == "-w" || arg == "--windowed");
71+ GameOptions { windowed }
72+ }
@@ -10,8 +10,10 @@10 };
11
12 fn main() {
13 let event_loop = EventLoop::new().unwrap();
14- let mut renderer = Renderer::new(&event_loop);
15
16 event_loop
17 .run(move |event, window_target| match event {
@@ -58,3 +60,13 @@58 })
59 .unwrap();
60 }
@@ -10,8 +10,10 @@10 };
11
12 fn main() {
13+ let options = get_options();
14+
15 let event_loop = EventLoop::new().unwrap();
16+ let mut renderer = Renderer::new(&event_loop, options.windowed);
17
18 event_loop
19 .run(move |event, window_target| match event {
@@ -58,3 +60,13 @@60 })
61 .unwrap();
62 }
63+
64+ struct GameOptions {
65+ windowed: bool,
66+ }
67+
68+ fn get_options() -> GameOptions {
69+ let args: Vec<String> = std::env::args().collect();
70+ let windowed = args.iter().any(|arg| arg == "-w" || arg == "--windowed");
71+ GameOptions { windowed }
72+ }
Modified src/render.rsGitHub
@@ -15,7 +15,7 @@1515 use raw_window_handle::HasRawWindowHandle;
1616 use winit::{
1717 event_loop::EventLoop,
18- window::{Window, WindowBuilder, WindowId},
18+ window::{Fullscreen, Window, WindowBuilder, WindowId},
1919 };
2020
2121 use crate::math::{RandomNumberGenerator, Vec3};
@@ -33,8 +33,16 @@3333 }
3434
3535 impl Renderer {
36- pub(crate) fn new(event_loop: &EventLoop<()>) -> Self {
37- let window_builder = WindowBuilder::new().with_title("iridium");
36+ pub(crate) fn new(event_loop: &EventLoop<()>, windowed: bool) -> Self {
37+ let fullscreen_option = if windowed {
38+ None
39+ } else {
40+ Some(Fullscreen::Borderless(None))
41+ };
42+
43+ let window_builder = WindowBuilder::new()
44+ .with_title("iridium")
45+ .with_fullscreen(fullscreen_option);
3846
3947 let config_template = ConfigTemplateBuilder::default();
4048 let (window, config) = DisplayBuilder::new()
@@ -15,7 +15,7 @@15 use raw_window_handle::HasRawWindowHandle;
16 use winit::{
17 event_loop::EventLoop,
18- window::{Window, WindowBuilder, WindowId},
19 };
20
21 use crate::math::{RandomNumberGenerator, Vec3};
@@ -33,8 +33,16 @@33 }
34
35 impl Renderer {
36- pub(crate) fn new(event_loop: &EventLoop<()>) -> Self {
37- let window_builder = WindowBuilder::new().with_title("iridium");
38
39 let config_template = ConfigTemplateBuilder::default();
40 let (window, config) = DisplayBuilder::new()
@@ -15,7 +15,7 @@15 use raw_window_handle::HasRawWindowHandle;
16 use winit::{
17 event_loop::EventLoop,
18+ window::{Fullscreen, Window, WindowBuilder, WindowId},
19 };
20
21 use crate::math::{RandomNumberGenerator, Vec3};
@@ -33,8 +33,16 @@33 }
34
35 impl Renderer {
36+ pub(crate) fn new(event_loop: &EventLoop<()>, windowed: bool) -> Self {
37+ let fullscreen_option = if windowed {
38+ None
39+ } else {
40+ Some(Fullscreen::Borderless(None))
41+ };
42+
43+ let window_builder = WindowBuilder::new()
44+ .with_title("iridium")
45+ .with_fullscreen(fullscreen_option);
46
47 let config_template = ConfigTemplateBuilder::default();
48 let (window, config) = DisplayBuilder::new()