Simple 2D Computer Graphics Library in C.
It stores some color codes of pixels in memory (called canvas here) and you are free to use this pixels wherever you want. You can write the pixels to .ppm file or build .c code to .wasm and display the pixels on JavaScript Canvas. Keep reading to see examples on both platforms.
Visit orhanemree/aldrin.js to WebAssembly version.
Visit orhanemree/aldrin.py to Python wrapper.
Visit Playground to try online.
Visit Editor to try online editor project made with Aldrin.
- Just copy and paste
/src/aldrin.cfile to your project.
#include "aldrin.c" // that's it!#include <stdint.h>
#include "src/aldrin.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);
aldrin_save_ppm(ac, "img/hello_world.ppm");
return 0;
}Output should look something like this:
Note that: aldrin_save_ppm() function generates .ppm output (see /img/hello_world.ppm). The output converted to .png format to be displayed here.
- Build to normal
Cprogram.
$ clang -DPLATFORM_C -o <filename> <filename>.c
# or
$ gcc <filename>.c -o <filename> -DPLATFORM_C- Build to
.wasmplatform.
$ clang -DPLATFORM_WASM --target=wasm32 -o <filename>.o -c <filename>.c
$ wasm-ld --no-entry --allow-undefined --export-all -o <filename>.wasm <filename>.o- Note: Make sure you have
clangandwasm-ldinstalled.
- See
/examples.
- You need Python to run tests.
$ cd test
$ python main.py- Get more info:
$ python main.py help- See
docs/DOCUMENTATION.mdto read from file. - See
websiteto read from web and run examples live.
- Gabriel Gambetta / Computer Graphics from Scratch
- Tsoding / Graphics Library in C [Video]
- ChatGPT of course :D
- Licensed under the MIT License.

