From 88b8681339b85e27e3d1d98c867ac3aa0557f780 Mon Sep 17 00:00:00 2001 From: rodri Date: Sun, 14 Jan 2024 22:14:04 +0000 Subject: triangulate quads. replace matrix rotation with quaternions. generalize texture image decoding. change lighting. --- util.c | 65 ++++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index b523cf8..98f6db6 100644 --- a/util.c +++ b/util.c @@ -53,45 +53,68 @@ 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) { -- cgit v1.2.3