Live data from Hacker News

Olive.c: a simple graphics library that does not have any dependencies

tsoding.org

21–30 of 96 posts

Re: Olive.c: a simple graphics library that does not have any dependencies

#22
this is very impressive, how is this done? the executable is only a few hundred KB and it runs for me, wasm is doing the magic here but I don't know too much about how the process works.

I added -I/usr/include/SDL2 to build.sh, made sure wasm-ld is in place, and it builds and runs smoothly.

Re: Olive.c: a simple graphics library that does not have any dependencies

#23

this is very impressive, how is this done? the executable is only a few hundred KB and it runs for me, wasm is doing the magic here but I don't know too much about how the process works. I added -I/usr/include/SDL2 to build.sh, made sure wasm-ld is in place, and it builds and runs smoothly.

It's a simple software rasterizer. If you're interested in writing your own, I've written a tutorial explaining the basics. https://magcius.github.io/xplain/article/rast1.html

Re: Olive.c: a simple graphics library that does not have any dependencies

#24
The TODO section at the end of olive.c shows that there's lots more to do, and decisions to make about how much to do (e.g. what about bezier curves?), but that's quibbling: it is refreshing (and educational) to see everything here done in such a perfectly self-contained way. Godspeed!

Re: Olive.c: a simple graphics library that does not have any dependencies

#27
post #9
post #7

Earlier quoted context omitted.

The function declarations and definitions are all commingled in a single file. So if you want to use this library in a project that contains multiple source files, you have to include a duplicate copy of the implementation (including e.g. the static font data) in every single compilation unit. It's possible that your linker would be smart enough to identify and remove the duplicates, but it's still inelegant, unidiom…

gcc or clang would crash on the linking step complaining about duplicate symbols. This library is only good for a project that is built in a single .c file.

There are many single-file C "libraries" that work perfectly fine as both "header" and "implementation", and that do not require unity builds (building everything as a single translation unit, e.g., a single .c file). Here is but one famous collection of them: https://github.com/nothings/stb

Re: Olive.c: a simple graphics library that does not have any dependencies

#28
post #23

this is very impressive, how is this done? the executable is only a few hundred KB and it runs for me, wasm is doing the magic here but I don't know too much about how the process works. I added -I/usr/include/SDL2 to build.sh, made sure wasm-ld is in place, and it builds and runs smoothly.

It's a simple software rasterizer. If you're interested in writing your own, I've written a tutorial explaining the basics. https://magcius.github.io/xplain/article/rast1.html

Also look at the source for original Quake (https://github.com/id-Software/Quake), one of the last pure software-rasterizing AAA 3D PC games. Michael Abrash's Graphics Programming Black Book (https://github.com/jagregory/abrash-black-book) explains many of the critical parts of the rendering pipeline.

By the way, quake.exe for DOS was 404,480 bytes.

Post reply on HN