Skip to content

Commit

Permalink
Updated intergration to be compatible with wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Aug 18, 2023
1 parent 3dda18c commit 91ea34b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The __[`main`]__ file contains all the code of the example.

You can run it with `cargo run`:
```
cargo run --package integration_wgpu
cargo run --package integration
```

### How to run this example with WebGL backend
Expand All @@ -23,9 +23,9 @@ NOTE: Currently, WebGL backend is is still experimental, so expect bugs.
cargo install wasm-bindgen-cli https
# 1. cd to the current folder
# 2. Compile wasm module
cargo build -p integration_wgpu --target wasm32-unknown-unknown
cargo build -p integration --target wasm32-unknown-unknown
# 3. Invoke wasm-bindgen
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/integration_wgpu.wasm --out-dir . --target web --no-typescript
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/integration.wasm --out-dir . --target web --no-typescript
# 4. run http server
http
# 5. Open 127.0.0.1:8000 in browser
Expand Down
Binary file added examples/integration/arial.ttf
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/integration/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
mod controls;
mod scene;

use std::borrow::Cow;

use controls::Controls;
use scene::Scene;

use iced_renderer::core::text::Renderer as _;
use iced_wgpu::graphics::Viewport;
use iced_wgpu::{wgpu, Backend, Renderer, Settings};
use iced_winit::core::mouse;
Expand All @@ -26,6 +29,8 @@ use web_sys::HtmlCanvasElement;
#[cfg(target_arch = "wasm32")]
use winit::platform::web::WindowBuilderExtWebSys;

pub const ARIAL_FONT_BYTES: &[u8] = include_bytes!("../arial.ttf");

pub fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(target_arch = "wasm32")]
let canvas_element = {
Expand Down Expand Up @@ -150,6 +155,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
format,
));

renderer.load_font(Cow::from(ARIAL_FONT_BYTES));
let mut state = program::State::new(
controls,
viewport.logical_size(),
Expand Down

0 comments on commit 91ea34b

Please sign in to comment.