499 points · by masterofsome · 4y ago · 93 comments
And the only math from Bellard's TinyGL that I use is his clipping code, maybe 80 lines of code give or take. Not to diminish Bellard at all, if anything I'm saying any problems with PortableGL are mine not his.
It's a damn shame that he's unable to get paid from Twitch and Youtube due to the war.
https://github.com/tsoding/olive.c/blob/43a67dd76760f915516a...
From the readme.
// This idea is that you can take this code and compile it to different platforms with different rendering machanisms:
// native with SDL, WebAssembly with HTML5 canvas, etc.
The goal seems to be to maximize portability.Though most games don't bother so we don't really have actual evidence.
I'd personally be interested in a graphics API that do not try to render the whole buffer every frame, but update it given a list of changes (e.g. sprite moving/rotating). I believe that such approach could work very well for a 2D software renderer given the likeliness of spatial redundancy, and possibly for video encoding without going through a clueless encoder querying pixels (and having the ability to exploit hardware efficiency to decode/render the stream).
Both cpu renderers with texture mapping and Wavefront obj import without further dependencies.
Edit: According to the JS source file it appears to be a plain 2D canvas. Now I am even more confused, those should definitely load!
clang $COMMON_CFLAGS -Os -fno-builtin --target=wasm32 ...
I added -I/usr/include/SDL2 to build.sh, made sure wasm-ld is in place, and it builds and runs smoothly.
By the way, quake.exe for DOS was 404,480 bytes.
If OLIVE_IMPLEMENTATION is defined before including "olive.c", then the full implementation is produced. Otherwise, just declarations, so that it behaves like a header file.
It's a valid technique. If you have a library all in one source file, the requirement to have a separate .h doubles your file count.
One small reason to have a .c suffix is might be that your editor can then choose a more specific syntax scheme. A .h file could be C++. Another one is that it can be used as a source file. You can pop it into a Makefile project, and just make sure you have -DOLIVE_IMPLEMENTATION on the compiler command line for that file. Other files using it just include "olive.c" to get the declarations. Because it has a .c suffix, make will handle it via its .c.o rule.
If you have two files: .h and .c, the use scenario may be simpler. Not a lot though. And now youu have two files which have to stay together somehow, yet remain distinct. If you combine them in one body of text, you have to indicate: oh, please snip out this part as a .h file and then the rest as a .c file. In e-mail you can have it as two separate MIME attachments. You can use an archive file --- have you looked into the formats? Not so simple.
It's not hard to understand the attraction to the one file deployment, even if you don't do it yourself.
It's possible that your linker would be smart enough to identify and remove the duplicates, but it's still inelegant, unidiomatic and needlessly inefficient.
If you actually use a header-only library and it fails to link properly or be used in a project with multiple compilation units, then that would be a bug in the header-only library worth discussing and fixing. That would be a good-effort and interesting comment.
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)
const char *s =
#include "test.txt"
;
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 found a very clever C and C++ wrapper [1] for that, which gives you an INCBIN() macro. Nice!
float vertices[] = {
#include "stuff.txt"
};