Skip to main content
OpenGame hosts a WebAssembly game as a static folder: index.html, the .wasm module and the JavaScript that loads it. That covers a module with a loader you wrote, a C or C++ game compiled with Emscripten, and Rust, Zig or Go compiled to wasm, including Bevy and Ebitengine games. OpenGame does not compile anything: you build, and upload the build.

Choose the engine ID

opengame init detects most of these from your project. Pass --engine to choose one yourself: In the build, opengame check and the server recognize Emscripten from its runtime code and the .wasm it built, threaded or not, and from its MINIMAL_RUNTIME loader, as well as Rust’s wasm-bindgen glue and Go’s wasm_exec.js. A Zig build carries no signature of its own, so a module its page loads itself is named WebAssembly. Hosting is the same either way.

Starters

The OpenGame repository has a starter for each language, under templates/. Each builds with node build.mjs into dist/, and needs its compiler on your PATH.

Load the SDK

Every language here reaches the SDK through window.OpenGame. Ship opengame-global.js and its .LEGAL.txt notice in the build, and load the script before the module, as Platform services shows:
A build with threads also gets the SDK at /_og/sdk.js from OpenGame. A build without threads gets no added script, so ship a copy.

Raw WebAssembly

Write index.html and a loader, and call the SDK from JavaScript:
index.html
The imports are yours to name. Keep game.wasm beside index.html, or fetch it by a path relative to the page.

C and C++ with Emscripten

Build with Emscripten, with its environment active:
  • Output: Emscripten writes index.html, index.js and index.wasm, plus any .data file the build preloads. Upload the whole folder.
  • Libraries: build each native library with Emscripten too. A desktop library does not link into a web build.
  • Main loop: pass your frame function to emscripten_set_main_loop, so each frame returns control to the browser.
  • Threads: optional. Build with -pthread, and OpenGame serves the build isolated.
  • Memory: -sALLOW_MEMORY_GROWTH=1 lets the heap grow. If JavaScript keeps a view of the heap, create it again after growth.
  • C++ exports: put each function you mark EMSCRIPTEN_KEEPALIVE inside extern "C", so JavaScript can call it by its plain name.
The OpenGame C package, integrations/c in the repository, calls the SDK from C or C++. Copy opengame.c, opengame.h and opengame.js into the project, and link them:
main.c
og_request takes a bridge operation and its JSON arguments, and the result arrives later through the callback. Platform services lists the operations. Emscripten rewrites index.html on each build, so add the opengame-global.js script tag after the build, or pass a shell file with --shell-file that already has it. Emscripten builds covers a larger codebase, a port or a decompilation: the build flags, shorthand calls such as og_track and og_board_submit, saves that last between visits, and what the player does for fullscreen, sound and input.

Rust

Add the wasm target, then build with Trunk or with Cargo:
  • Trunk: init sets trunk build --release as the build command when the project has Trunk.toml, or an index.html that uses data-trunk. Trunk writes dist/.
  • wasm-bindgen: install the wasm-bindgen CLI at the version of the wasm-bindgen crate in Cargo.lock.
  • Threads: a build whose module uses shared memory is served isolated.
The opengame crate is integrations/rust in the repository, used as a path dependency:
Cargo.toml
The crate also has track, achievements::unlock, achievements::list, sign_in, open_link, fullscreen, player and subscribe for pause, mute and player changes. It uses wasm-bindgen by default. With default-features = false and features = ["raw-import"], it uses raw imports, and the page loads it with imports.mjs, host.mjs and lifecycle.mjs from integrations/c. To add the SDK in a Trunk project, copy both files with Trunk and load the script before Trunk’s module:
index.html

Zig

Build for wasm32-freestanding with Zig 0.13:
In build.zig, the same settings are entry = .disabled, rdynamic = true and export_memory = true. The OpenGame Zig package, integrations/zig, has a Zig module and opengame.mjs, which builds the imports the module needs:
Keep opengame.mjs and lifecycle.js beside the page. Call no export until instance is assigned, and call host.dispose() on pagehide. The Zig package expects one memory that is not shared, so use it in a single-thread build.

Go

Build with the standard Go compiler:
  • Runtime glue: copy wasm_exec.js from the Go you built with. It is in $(go env GOROOT)/lib/wasm on Go 1.24 and later, and in misc/wasm before that.
  • Page: load opengame-global.js, then lifecycle.js, then wasm_exec.js, and start the module with new Go() and go.run(instance).
  • Threads: Go’s js/wasm port runs every goroutine on the browser’s main thread.
The OpenGame Go module is integrations/go in the repository. Point your go.mod at it:
Copy integrations/go/web/lifecycle.js into the build. Drain the module’s message channel continuously, and never block the JavaScript event loop while you wait for a result.

Deploy

deploy uploads the build and prints the address of its deploy page, where Play appears once the checks pass. Export and deploy covers each step and opengame submit.

Memory and callbacks

  • A module’s declared maximum memory is a limit it reserves, not memory it uses. Measure the running game.
  • Recreate typed-array views of wasm memory after it grows.
  • The OpenGame packages hand callbacks borrowed pointers or slices. Copy what you keep before the callback returns.
  • Call the SDK from the browser’s main thread. A worker thread has no window.OpenGame.