Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/schabby/go-wasm-webgl

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/schabby/go-wasm-webgl

  • v0.0.0-20210220125738-2c98b5386dd4
  • Source
  • Go
  • Socket score

Version published
Created
Source

wasp: WebGL2 utility lib in Go on WASM

A small, stingy and light-weight (= little functionality) webgl2 layer in Go for WASM.

Wasp comes with a small set of convenience structs and functions that easy the work with WebGL2. The main concepts are the following.

  • shader.go: Common shader functionality such as loading, compiling shader sources as well as caching attributes and uniforms.
  • webglapp.go: A setup for a fullpage WebGL2 application with requestAnimationFrame, mouse events and resize callbacks. Reduces common boilerplate code on the application level.
  • mesh.go: a simple data structure for manipulating triangle meshes and uploading to WebGL2 as interleaved VertexArrayObjects.
  • webgl/renderingcontext.go: Wrapper for WebGl2RenderingContext in JavaScript for typesafety and convenience.

Check out the examples in the examples folder for further research.

Examples

There are currently three examples that demonstrate the usage of Wasp.

Simple Cube Example

The simple cube example in examples/simplecube.go shows a colored, rotating cube. It uses a very basic shader without lighting.

Wasp example showing simple rotating cube

Simple Sphere Example

The simple sphere example in examples/simplesphere.go shows a colored sphere without lighting.

Wasp example showing simple colored sphere

Simple Lighting Example

The example in examples/simplelighting.go shows spheres with classical lighting shading.

Wasp simple light shading example

Simple Texture Example

The example in examples/simpletexture.go shows a crate with a textured mapped on its faces.

Wasp simple texturing example

How to build the examples:

While not strictly necessary, it may help to have some prior knowledge on WASM with Go. There are plenty of great tutorials out there which help you understand how Go and WASM work together.

On the terminal of your choice, move into the project directory and run

GOOS=js GOARCH=wasm go build -o examples/hellocube.wasm examples/hellocube.go 

This will compile the cube example into a wasm file in examples/hellocube.wasm where it will be picked up by the javascript loader in examples/hellocube.html.

Make sure that examples also contains wasm_exec.js which is shiped along the standard Go installation, such that you may just need to copy it over cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./examples.

To run the example, you need any webserver to serve the static content in the examples directory (HTML files and WASM files.). Any http server will do, but you may want to run [goexec][https://github.com/shurcooL/goexec]

 goexec 'http.ListenAndServe(`:8080`, http.FileServer(http.Dir(`.`)))'

in the examples directory. Side note: goexecis not on my PATH environment variable, such that I need to call it will the full path

~/go/bin/goexec 'http.ListenAndServe(`:8080`, http.FileServer(http.Dir(`.`)))'

Then, open a browser and request http://localhost:8080/hellocube.html which will load the page with the embedded WASM code, init the WebGL2 rendering context and show a rotating cube.

You may want to check out the browsers built-on console to see any logging output.

FAQs

Package last updated on 20 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc