Skip to content

Instantly share code, notes, and snippets.

@hikiko
Created April 7, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hikiko/4a8566daa8f6630a6872b830503f236e to your computer and use it in GitHub Desktop.
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
{
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