X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Ftungen.c;h=4148b2641d6e0d32ff631f7432c3b42666b73861;hb=bbe2ec049a812155c75da5ecc303bf3793c9cca8;hp=8122c9508ad47b00fea5e5d5d616d55528087dc2;hpb=f6d4c2f2ee940cadff5c5792c789ba86b9df7d4d;p=gbajam21 diff --git a/tools/tungen.c b/tools/tungen.c index 8122c95..4148b26 100644 --- a/tools/tungen.c +++ b/tools/tungen.c @@ -3,11 +3,16 @@ #include #include +struct vec2 { + float x, y; +}; + int main(int argc, char **argv) { - int i, j, xsz = 240, ysz = 160, texsz = 128; + int i, j, imgrad, xsz = 240, ysz = 160, texsz = 128; struct vec2 *tunbuf, *tun; - float aspect; + float aspect, prev_r; + struct vec2 *buf, *ptr; for(i=1; i= 0 && x < xsz && y >= 0 && y < ysz) { + ptr = buf + y * xsz + x; + ptr->x = u; + ptr->y = v * 8; + } + } + prev_r = r; + } + FILE *fp = fopen("tun_preview.ppm", "wb"); if(fp) { fprintf(fp, "P6\n%d %d\n255\n", xsz, ysz); @@ -43,32 +81,24 @@ invalopt: fprintf(stderr, "invalid argument: %s\n", argv[i]); aspect = (float)xsz / (float)ysz; - tun = tunbuf; + ptr = buf; for(i=0; ix; + float v = ptr->y; + int r = (int)(u * 8.0 * 255.0f) & 0xff; + int b = (int)(v * 8.0 * 255.0f) & 0xff; - float u = 0.5f * theta / M_PI + 0.5f; - float v = 0.8f / r; + ptr++; - /* - uint32_t out = ((uint32_t)(u * 65535.0f) & 0xffff) | - (((uint32_t)(v * 65535.0f) & 0xffff) << 16); - */ uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) | (((uint16_t)(v * 255.0f) & 0xff) << 8); fwrite(&out, sizeof out, 1, stdout); if(fp) { - int cr = (int)(u * 2048.0f) & 0xff; - int cb = (int)(r * 2048.0f) & 0xff; - fputc(cr, fp); + fputc(r, fp); fputc(0, fp); - fputc(cb, fp); + fputc(b, fp); } } }