2018-09-20 16:20:42 -07:00
|
|
|
# WebGL Example
|
2018-09-15 23:28:15 -07:00
|
|
|
|
2018-09-20 16:20:42 -07:00
|
|
|
[View full source code][code]
|
|
|
|
|
|
|
|
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/webgl
|
2018-09-15 23:28:15 -07:00
|
|
|
|
2018-09-20 16:20:42 -07:00
|
|
|
This example draws a triangle to the screen using the WebGL API.
|
2018-09-15 23:28:15 -07:00
|
|
|
|
|
|
|
## `Cargo.toml`
|
|
|
|
|
|
|
|
The `Cargo.toml` enables features necessary to obtain and use a WebGL
|
|
|
|
rendering context.
|
|
|
|
|
|
|
|
```toml
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/webgl/Cargo.toml}}
|
2018-09-15 23:28:15 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
## `src/lib.rs`
|
|
|
|
|
|
|
|
This source file handles all of the necessary logic to obtain a rendering
|
|
|
|
context, compile shaders, fill a buffer with vertex coordinates, and draw a
|
|
|
|
triangle to the screen.
|
|
|
|
|
|
|
|
```rust
|
2018-09-20 16:20:42 -07:00
|
|
|
{{#include ../../../examples/webgl/src/lib.rs}}
|
2018-09-15 23:28:15 -07:00
|
|
|
```
|