Created
April 7, 2020 13:22
-
-
Save hikiko/4a8566daa8f6630a6872b830503f236e to your computer and use it in GitHub Desktop.
the code I use to dump ppm because I always forget those P6, P3 etc :p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
unsigned char pix[160 * 160 * 4]; | |
FILE *fp; | |
int i; | |
glBindTexture(GL_TEXTURE_2D, gl_tex); | |
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix); | |
if ((fp = fopen("/tmp/foo.ppm", "wb"))) { | |
//fprintf(fp, "P6\n160 160\n255\n"); | |
fprintf(fp, "P3\n160 160\n255\n"); | |
for (i = 0; i < 160 * 160; i++) { | |
#if 0 | |
fputc(pix[i * 4], fp); | |
fputc(pix[i * 4 + 1], fp); | |
fputc(pix[i * 4 + 2], fp); | |
#endif | |
fprintf(fp, "%d %d %d\n", (int)pix[i * 4], (int)pix[i * 4 + 1], (int)pix[i * 4 + 2]); | |
} | |
fclose(fp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment