This repository is a starter template for projects using MLX42.
It allows you to build and run your MLX42 project both natively and in the browser (WebAssembly/WebGL) with Emscripten.
- ✅ Preconfigured Makefile for both native and web builds
- ✅ Minimal demo project (
src/main.c) with:- Randomized pixel rendering
- Keyboard movement for an image (
↑ ↓ ← →) - ESC to close window
- ✅ Emscripten HTML template (
web/demo.html) with fullscreen canvas - ✅ Cross-platform ready:
- Native build → desktop executable
- Web build →
demo.js+demo.wasm+ HTML wrapper
.
├── src/ # Your source code (.c files)
│ └── main.c
├── include/ # Your header files (.h)
├── MLX42/ # MLX42 submodule (must be cloned)
├── web/ # Web build output
│ ├── demo.html
│ └── demo.js (generated)
├── Makefile
└── README.md
- Native build:
- GCC / Clang
- CMake
- GLFW3
- Web build:
- Emscripten (
emccin PATH)
- Emscripten (
git clone --recursive https://github.com/pulgamecanica/mlx42-web-template.git
cd mlx42-web-templateIf you forgot --recursive, fetch MLX42 later with:
git submodule update --init --recursivemake
./demomake webThis generates:
web/demo.js
web/demo.wasm
web/demo.html
Open web/demo.html in a browser (or use a local server):
python3 -m http.server -d webThen visit: http://localhost:8000/demo.html
- ESC → Exit window (native)
- ↑ / ↓ / ← / → → Move the generated image
| Target | Description |
|---|---|
make |
Build native executable (./demo) |
make web |
Build for the browser (WebAssembly) |
make clean |
Remove object files |
make fclean |
Remove binary & object files |
make re |
Rebuild everything from scratch |
-
Put your assets in an
assets/folder and preload them by uncommenting the line in the Makefile:# --preload-file assets -
mlx_loop_hooksupports multiple callbacks (as shown inmain.c). -
Native MLX42 and WebAssembly MLX42 are compiled separately.
This template was made to:
- Quickly bootstrap MLX42 graphics projects
- Provide an easy migration path from MLX (42 school) to MLX42
- Run your projects directly in the browser 🚀
Happy coding 🎉 by pulgamecanica