Web
Download the SDK bundle for web, install the
Emscripten SDK,
and put main.c beside the folders the bundle unzipped:
my_game/
├── include/
│ └── natiny.h
├── lib/
│ └── libnatiny_webassembly.a
└── main.c
#include "natiny.h"
#include <stddef.h>
static NatinyWindow window;
static void frame(float dt, void* userdata)
{
(void)dt;
(void)userdata;
natiny_window_bind(window);
natiny_render_clear(0.07f, 0.09f, 0.13f, 1.0f);
natiny_render_set_color(0.66f, 0.76f, 0.22f, 1.0f);
natiny_render_rectangle(360.0f, 260.0f, 80.0f, 80.0f);
natiny_window_unbind();
}
int main(void)
{
if (!natiny_backend_init(NATINY_BACKEND_AUTO)) {
return 1;
}
window = natiny_window_create("Hello, Natiny", 800, 600);
if (!window) {
natiny_backend_shutdown();
return 1;
}
natiny_backend_loop(frame, NULL);
natiny_backend_shutdown();
return 0;
}
Compile and link:
emcc -O2 -Iinclude -c main.c -o main.o
em++ -O2 main.o lib/libnatiny_webassembly.a \
--use-port=emdawnwebgpu \
-sASYNCIFY -sALLOW_MEMORY_GROWTH=1 -sWASM_BIGINT \
-o app.html
That writes app.html, app.js and app.wasm. Serve them over HTTP and open
app.html:
python -m http.server 8000
A dark canvas with a green square.
Compile with emcc, link with em++. Natiny is C, but Emscripten's
emdawnwebgpu port is C++ and turns the plain C driver down. emcc
-sDEFAULT_TO_CXX is the same thing spelled as a flag.
--use-port=emdawnwebgpu is what provides WebGPU, the only backend here.
-sASYNCIFY is what lets natiny_backend_loop block the way it does
everywhere else while the browser still gets its frames back.
Dawn's code is linked into your program rather than into the archive, so its notice comes from your Emscripten install and ships with what you publish. BSD 3-clause, asking the same thing MIT does: keep the notice.
A page cannot read its own files from file://, so http.server above is not
a suggestion - opening the .html directly will fail to load the .wasm.