Skip to content

Instantly share code, notes, and snippets.

@hikiko
Last active March 7, 2021 18:34
Show Gist options
  • Save hikiko/7ecc794fbc978e2e9ef57701f6828571 to your computer and use it in GitHub Desktop.
Save hikiko/7ecc794fbc978e2e9ef57701f6828571 to your computer and use it in GitHub Desktop.
copy paste it to dump float rgba textures (*data = the pointer I'd give in TexImage2D)
static bool
dump_float_image_rgba(const char *fname,
int w, int h,
float *data)
{
FILE *fp;
int i;
float *p;
if (!(fp = fopen(fname, "wb"))) {
fprintf(stderr, "Failed to open file: %s.\n", fname);
return false;
}
p = data;
fprintf(fp, "P6\n%d %d\n255\n", w, h);
for (i = 0; i < w * h; i++) {
fputc(p[0] * 255, fp);
fputc(p[1] * 255, fp);
fputc(p[2] * 255, fp);
p += 4;
}
fclose(fp);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment