module
Version:
v0.0.0-...-deef603
Opens a new window with list of versions in this module.
Published: Nov 22, 2024
License: Unlicense
Opens a new window with license information.
README
¶
Ebitengine rendering backend for the pure Go imgui port
This uses a fork of the version by Splizard, which adds some minor changes to it.
Benefits of not using CGo
- Cross-compilation
- WebAssembly
- Pure Go :D
Building the example for WebAssembly
-
Clone the repository
-
Navigate into the example directory: cd internal/example
(on Linux)
-
Build the example:
On Linux:
env GOOS=js GOARCH=wasm go build -o example.wasm main.go
On Windows Powershell:
$Env:GOOS = 'js'
$Env:GOARCH = 'wasm'
go build -o yourgame.wasm github.com/yourname/yourgame
Remove-Item Env:GOOS
Remove-Item Env:GOARCH
-
Copy wasm_exec.js
into the current directory:
On Linux:
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
On Windows Powershell:
$goroot = go env GOROOT
cp $goroot\misc\wasm\wasm_exec.js .
-
Create this HTML file
<!DOCTYPE html>
<script src="wasm_exec.js"></script>
<script>
// Polyfill
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
WebAssembly.instantiateStreaming(
fetch("example.wasm"),
go.importObject
).then((result) => {
go.run(result.instance);
});
</script>
-
Start a local HTTP server and open the page in your browser
If you want to embed the game into another page, use iframes (assuming that main.html
is the name of the above HTML file):
<!DOCTYPE html>
<iframe src="main.html" width="640" height="480" allow="autoplay"></iframe>
Directories
¶
internal
|
|
|
|
|
|
Click to show internal directories.
Click to hide internal directories.