Some of you reading this are very experienced with opening up windows in Rust and probably have your favorite windowing library, but this guide is designed for everybody, so it's something that we need to cover. Luckily, if you don't need to read this if you know what you're doing. One thing that you do need to know is that whatever windowing solution you use needs to support the [raw-window-handle](https://github.com/rust-windowing/raw-window-handle) crate.
Some of you reading this are very experienced with opening up windows in Rust and probably have your favorite windowing library, but this guide is designed for everybody, so it's something that we need to cover. Luckily, you don't need to read this if you know what you're doing. One thing that you do need to know is that whatever windowing solution you use needs to support the [raw-window-handle](https://github.com/rust-windowing/raw-window-handle) crate.
## What crates are we using?
For the beginner stuff, we're going to keep things very simple, we'll add things as we go, but I've listed the relevant `Cargo.toml` bits below.
@ -14,7 +14,7 @@ wgpu = "0.5.0"
futures = "0.3.4"
```
If you're on Windows, you can specify Vulkan as you desired backend by removing the `wgpu = "0.5.0"` and adding the following.
If you're on Windows, you can specify Vulkan as your desired backend instead of DirectX by removing the `wgpu = "0.5.0"` and adding the following.
``` toml
[dependencies.wgpu]
@ -33,7 +33,7 @@ There's not much going on here yet, so I'm just going to post the code in full.
For convenience we're going to pack all the fields into a struct, and create some methods on that.
```rust
@ -43,7 +42,7 @@ impl State {
I'm glossing over `State`s fields, but they'll make more sense as I explain the code behind the methods.
## new()
## State::new()
The code for this is pretty straight forward, but let's break this down a bit.
```rust
@ -144,7 +143,7 @@ let mut state = block_on(State::new(&window));
```
## resize()
If we want to support resizing in our application, we're going to need to recreate the `swap_chain` everytime the window's size changes. That's the reason we stored the `hidpi_factor`, the logical `size`, and the `sc_desc` used to create the swapchain. With all of these, the resize method is very simple.
If we want to support resizing in our application, we're going to need to recreate the `swap_chain` everytime the window's size changes. That's the reason we stored the physical `size` and the `sc_desc` used to create the swapchain. With all of these, the resize method is very simple.
@ -234,7 +233,7 @@ We don't have anything to update yet, so leave the method empty.
```rust
fn update(&mut self) {
// remove `unimplemented!()`
}
```
@ -331,7 +330,7 @@ Some of you may be able to tell what's going on just by looking at it, but I'd b
}
```
A `RenderPassDescriptor` only has two fields: `color_attachments` and `depth_stencil_attachment`. The `color_attachements` describe where we are going to draw our color too.
A `RenderPassDescriptor` only has two fields: `color_attachments` and `depth_stencil_attachment`. The `color_attachements` describe where we are going to draw our color to.
We'll use `depth_stencil_attachment` later, but we'll set it to `None` for now.