It pains me to see #include at the top of the file. It makes the project feel like a toy.
Olive.c: a simple graphics library that does not have any dependencies
71–80 of 96 posts
Re: Olive.c: a simple graphics library that does not have any dependencies
#72The combination of mapping pixels to memory and rendering individually and then that appearing on webgl and looking great on a not too expensive phone, where I am pinch zooming while it flawlessly animates, sort of blows my mind in how much technology has come in 25 years. Connects the old with the new in a way I haven’t seen for a while (and yeah seen loads of C64 emulators and such)
Re: Olive.c: a simple graphics library that does not have any dependencies
#73It's cool that you can get away with software rendering these days, but it's a shame to not make use of the power of the GPU.
That's the point. Also, not all devices have dedicated graphics hardware
Re: Olive.c: a simple graphics library that does not have any dependencies
#74Re: Olive.c: a simple graphics library that does not have any dependencies
#75Nice to see tsoding on the top of HN, this guy does amazing streams and youtube video
Re: Olive.c: a simple graphics library that does not have any dependencies
#76Earlier quoted context omitted.
Sorry, why does it make the project feel like a toy? I'm not trying to argue, I just don't understand. Is it because you're including a source file instead of a header file?
single-file libraries almost always feel like toys because most serious projects i'd want them integrated into a real build system. vcpkg is a good one these days for c/cpp. nothing wrong with a toy library ofc.
Note you get some opportunities for better compiler optimizations when the entire compilation unit is the entire project. In fact, sqlite claims the code runs 5-10% faster when built as an amalgamation (https://www.sqlite.org/amalgamation.html)
Re: Olive.c: a simple graphics library that does not have any dependencies
#77Re: Olive.c: a simple graphics library that does not have any dependencies
#78Earlier 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.
Re: Olive.c: a simple graphics library that does not have any dependencies
#79Earlier quoted context omitted.
Sure, but only if the text file looks like a C string literal, i.e. starts and ends with double quotes (which would make it into a weird text file). Doing const char *s = " #inclued "test.txt" "; won't work, since the preprocessor won't interpret directives inside string literals of course. In many assemblers, there is a directive called "incbin" which pastes in unstructured binary data at the point of usage. I just…
Note that C23 will include a variant of incbin spelled #embed : Semantically, the preprocessor will insert a list of integers which you can use to initialize an array.