https://github.com/zeozeozeo/ebitengine-imgui-go
Ebitengine rendering backend for the pure Go ImGui port
https://github.com/zeozeozeo/ebitengine-imgui-go
ebitengine gamedev golang imgui pure-go wasm webassembly
Last synced: 6 months ago
JSON representation
Ebitengine rendering backend for the pure Go ImGui port
- Host: GitHub
- URL: https://github.com/zeozeozeo/ebitengine-imgui-go
- Owner: zeozeozeo
- License: unlicense
- Created: 2022-11-27T12:04:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-22T19:12:57.000Z (6 months ago)
- Last Synced: 2024-11-22T20:20:22.891Z (6 months ago)
- Topics: ebitengine, gamedev, golang, imgui, pure-go, wasm, webassembly
- Language: Go
- Homepage: https://zeozeozeo.github.io/ebitengine-imgui-go/internal/example
- Size: 5.03 MB
- Stars: 21
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ebitengine rendering backend for the [pure Go imgui port](https://github.com/Splizard/imgui)
This uses a [fork](https://github.com/zeozeozeo/imgui) of the version by [Splizard](https://github.com/Splizard), which adds some minor changes to it.
[](https://zeozeozeo.github.io/ebitengine-imgui-go/internal/example)
# [Live demo](https://zeozeozeo.github.io/ebitengine-imgui-go/internal/example)
# [Example](https://github.com/zeozeozeo/ebitengine-imgui-go/blob/main/internal/example/main.go)
# Benefits of not using CGo
- Cross-compilation
- WebAssembly
- Pure Go :D# Building the example for WebAssembly
1. Clone the repository
2. Navigate into the example directory: `cd internal/example` (on Linux)
3. 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
```4. 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 .
```5. Create this HTML file
```html
// 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);
});
```6. 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):
```
```