|
This opengl code snippet writes the current color buffer to a raw grayscale image. Photoshop recognizes this format as Photoshop Raw.
int screenshot(char *filename) {
FILE* imgfile;
unsigned char* pixels;
unsigned char* flipped;
int viewport[4];
int width, height, i;
glGetIntegerv(GL_VIEWPORT, viewport);
width = viewport[2];
height = viewport[3];
pixels = malloc(width*height);
glReadPixels(0, 0, width, height,
GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels);
flipped = malloc(width*height);
for (i=0; i < height; i++)
memcpy(flipped + width*i,
pixels + width*(height-i-1), width);
free(pixels);
imgfile = fopen(filename, "wb");
fwrite(flipped, width*height, 1, imgfile);
free(flipped);
fclose(imgfile);
return 1;
}
back to → isomotion
Show pagesource
Old revisions
Backlinks
Index
Recent changes
Login
opengl-raw-image.txt · Last modified: July 19, 2007 (external edit) |