- Very basic 2D computer graphics library in C. A lightweight version of orhanemree/aldrin.
- Just copy and paste
lib/aldrin-light.cfile to your project.
#include "lib/aldrin-light.c" // that's it!// hello-world.c
#include "lib/aldrin-light.c"
#define WIDTH 160
#define HEIGHT 90
static uint32_t pixels[WIDTH*HEIGHT];
int main() {
Aldrin_Canvas ac = { pixels, WIDTH, HEIGHT };
aldrin_fill(ac, 0xff00ff); // paint the whole canvas pink!
aldrin_save_ppm(ac, "out/hello_world.ppm");
return 0;
}Output (after .ppm converted to .jpg):
- In order to use the library on platform
wasm, you first need to build a blankAldrin_Canvas. So in JS, you can manipulate pixels in the memory.
// wasm.c
#include "lib/aldrin-light.c"
#define WIDTH 200 // pre-set width and height!
#define HEIGHT 200
static uint32_t pixels[WIDTH*HEIGHT];
Aldrin_Canvas ac = { pixels, WIDTH, HEIGHT };- Build file using
clangandwasm-ld, withPLATFORM_WASMdefined.
$ clang -DPLATFORM_WASM --target=wasm32 -c -o aldrin-light.o wasm.c
$ wasm-ld --no-entry --allow-undefined --export-all -o aldrin-light.wasm aldrin-light.o- You will see
aldrin-light.wasmfile.
- You can have more than one canvas in a project.
// multiple.c
#include "lib/aldrin-light.c"
#define WIDTH 200
#define HEIGHT 200
static uint32_t pixels0[WIDTH*HEIGHT];
Aldrin_Canvas ac0 = { pixels0, WIDTH, HEIGHT };
static uint32_t pixels1[WIDTH*HEIGHT];
Aldrin_Canvas ac1 = { pixels1, WIDTH, HEIGHT };- MIT
