Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the example a bit #105

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/hello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ cargo run --features=window-sdl2
To run with web-sys:

```shell
cargo +nightly build --target wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown
mkdir -p generated
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/hello.wasm --out-dir generated --no-modules
wasm-bindgen ../../target/wasm32-unknown-unknown/debug/hello.wasm --out-dir generated --target web
cp index.html generated
```

Expand Down
8 changes: 4 additions & 4 deletions examples/hello/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<script src="./hello.js"></script>
<script>
window.addEventListener("load", async () => {
await wasm_bindgen("./hello_bg.wasm");
});
<script type="module">
import init from "./hello.js";

init();
</script>
</body>
</html>
9 changes: 1 addition & 8 deletions examples/hello/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
use glow::*;

#[cfg(all(target_arch = "wasm32", feature = "web-sys"))]
use wasm_bindgen::prelude::*;

#[cfg(all(target_arch = "wasm32", feature = "stdweb"))]
use std_web::{
traits::*,
unstable::TryInto,
web::{document, html_element::*},
};

#[cfg(all(target_arch = "wasm32", feature = "stdweb"))]
use webgl_stdweb::WebGL2RenderingContext;

#[cfg_attr(all(target_arch = "wasm32", feature = "web-sys"), wasm_bindgen(start))]
pub fn wasm_main() {
main();
}

fn main() {
unsafe {
// Create a context from a WebGL2 context on wasm32 targets
Expand Down