tutorial 1 finished

pull/1/head
Ben Hansen 5 years ago
commit 8ecb859b9f

3
.gitignore vendored

@ -0,0 +1,3 @@
node_modules/
target/
.vscode/

1370
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,4 @@
[workspace]
members = [
"code"
]

@ -0,0 +1,24 @@
[package]
name = "code"
version = "0.1.0"
authors = ["Ben Hansen <bhbenjaminhansen@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "tutorial1-window"
path = "src/beginner/tutorial1-window.rs"
[[bin]]
name = "tutorial2-device"
path = "src/beginner/tutorial2-device.rs"
[dependencies]
image = "0.22"
raw-window-handle = "0.3"
winit = "0.20.0-alpha3"
[dependencies.wgpu]
version = "0.3"
features = ["vulkan"]

@ -0,0 +1,38 @@
use winit::{
event::*,
event_loop::{EventLoop, ControlFlow},
window::{WindowBuilder},
};
fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.build(&event_loop)
.unwrap();
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
ref event,
window_id,
} if window_id == window.id() => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input,
..
} => {
match input {
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
}
}
_ => *control_flow = ControlFlow::Wait,
}
_ => *control_flow = ControlFlow::Wait,
}
});
}

@ -0,0 +1,7 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}

@ -0,0 +1,25 @@
module.exports = {
themeConfig: {
displayAllHeaders: true,
sidebar: [
'/',
{
title: 'Beginner',
path: '/beginner/',
collapsable: false,
children: [
'/beginner/',
'/beginner/tutorial1-window',
],
},
{
title: 'Intermediate',
path: '/intermediate/',
collapsable: false,
children: [
'/intermediate/',
],
},
]
}
}

@ -0,0 +1 @@
# Introduction

@ -0,0 +1,6 @@
# What we're covering
## Just the basics
To make things simpler for everyone, this section of the guide will just cover things like setup wgpu with a window, creating the swapchain, using the render pipeline, creating and using buffers, basic texturing, and basic lighting.
Let's get started!

@ -0,0 +1,70 @@
# Dependencies and the window
## Boring, I know
Some of you reading this are very experienced with opening up windows in Rust and probably have your favorite windowing library, but we 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.
## 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.
```toml
[dependencies]
image = "0.22"
raw-window-handle = "0.3"
winit = "0.20.0-alpha3"
[dependencies.wgpu]
version = "0.3"
features = ["vulkan"]
```
## Why vulkan?
You need to specify what rendering backend you're using through [Cargo features](https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section) in order to run a program with wgpu. You can manu I'm specifying [vulkan](https://www.khronos.org/vulkan/), because I'm on [linux](https://www.linuxmint.com/). You're welcome to use [metal](https://developer.apple.com/metal/), or `DirectX 11/12` using `"metal"`, `"dx11"`, or `"dx12"` respectively.
## What's with the "alpha" stuff?
The wgpu examples use this version of [winit](https://github.com/rust-windowing/winit), so I elected to do the same. *Note: I'll update this once the changes to winit become fully released.*
## The code
There's not much going on here yet, so I'm just going to post the code in full. Just paste this into you're `main.rs` or equivalent.
```rust
use winit::{
event::*,
event_loop::{EventLoop, ControlFlow},
window::{WindowBuilder},
};
fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.build(&event_loop)
.unwrap();
event_loop.run(move |event, _, control_flow| {
match event {
Event::WindowEvent {
ref event,
window_id,
} if window_id == window.id() => match event {
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::KeyboardInput {
input,
..
} => {
match input {
KeyboardInput {
state: ElementState::Pressed,
virtual_keycode: Some(VirtualKeyCode::Escape),
..
} => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
}
}
_ => *control_flow = ControlFlow::Wait,
}
_ => *control_flow = ControlFlow::Wait,
}
});
}
```
All this does is create a window, and keep it open until until user closes it, or presses escape. Next tutorial we'll actually start using wgpu!

@ -0,0 +1 @@
# Coming Soon!

10156
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,19 @@
{
"name": "learn-wgpu",
"version": "1.0.0",
"description": "Learning wgpu with Rust",
"main": "index.js",
"directories": {
"doc": "docs"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
},
"author": "",
"license": "ISC",
"devDependencies": {
"vuepress": "^1.2.0"
}
}
Loading…
Cancel
Save