diff options
author | rodri <rgl@antares-labs.eu> | 2024-01-14 22:14:04 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-01-14 22:14:04 +0000 |
commit | 88b8681339b85e27e3d1d98c867ac3aa0557f780 (patch) | |
tree | 87f320e203a9cfc0652cb611e3b8cc7df77027b7 /util.c | |
parent | 32360e2b88f88f643be632941580c90d3e466076 (diff) | |
download | tinyrend-88b8681339b85e27e3d1d98c867ac3aa0557f780.tar.gz tinyrend-88b8681339b85e27e3d1d98c867ac3aa0557f780.tar.bz2 tinyrend-88b8681339b85e27e3d1d98c867ac3aa0557f780.zip |
triangulate quads. replace matrix rotation with quaternions.
generalize texture image decoding.
change lighting.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 65 |
1 files changed, 44 insertions, 21 deletions
@@ -53,46 +53,69 @@ memsetd(double *p, double v, usize len) *dp = v; } +typedef struct Deco Deco; +struct Deco +{ + int pfd[2]; + int infd; + char *prog; +}; + static void decproc(void *arg) { - int fd, *pfd; + char buf[32]; + Deco *d; - pfd = arg; - fd = pfd[2]; + d = arg; - close(pfd[0]); - dup(fd, 0); - close(fd); - dup(pfd[1], 1); - close(pfd[1]); + close(d->pfd[0]); + dup(d->infd, 0); + close(d->infd); + dup(d->pfd[1], 1); + close(d->pfd[1]); - execl("/bin/tga", "tga", "-9t", nil); + snprint(buf, sizeof buf, "/bin/%s", d->prog); + + execl(buf, d->prog, "-9t", nil); threadexitsall("execl: %r"); } -Memimage * -readtga(char *path) +static Memimage * +genreadimage(char *prog, char *path) { Memimage *i; - int fd, pfd[3]; + Deco d; + + d.prog = prog; - if(pipe(pfd) < 0) + if(pipe(d.pfd) < 0) sysfatal("pipe: %r"); - fd = open(path, OREAD); - if(fd < 0) + d.infd = open(path, OREAD); + if(d.infd < 0) sysfatal("open: %r"); - pfd[2] = fd; - procrfork(decproc, pfd, mainstacksize, RFFDG|RFNAMEG|RFNOTEG); - close(pfd[1]); - i = readmemimage(pfd[0]); - close(pfd[0]); - close(fd); + procrfork(decproc, &d, mainstacksize, RFFDG|RFNAMEG|RFNOTEG); + close(d.pfd[1]); + i = readmemimage(d.pfd[0]); + close(d.pfd[0]); + close(d.infd); return i; } Memimage * +readtga(char *path) +{ + return genreadimage("tga", path); +} + +Memimage * +readpng(char *path) +{ + return genreadimage("png", path); +} + +Memimage * rgb(ulong c) { Memimage *i; |