PDA

View Full Version : OpenGL screen capture -> then write out as bitmap..



cutting_crew
07-22-2004, 08:44 AM
i have an openGL and i want to be able to press a certain key and the image is stored into a buffer then written out in a folder as a .bmp file. so far this is what i have..to an extent..
after the glReadPixels i dont know where to go from there. i have my buffer stored of the current screen. as you can see i am using GLUT, not something propietary like windows, so this would need to work on windows and linux at the least, preferable OS X and SGI systems.. thanks all for your help in advance!

void saveScreen()
{
int nWidth = glutGet( GLUT_WINDOW_WIDTH );
int nHeight = glutGet( GLUT_WINDOW_HEIGHT );
//my buffer
unsigned char* pcBuffer =
new unsigned char[nWidth * nHeight * 3];

glReadBuffer( GL_BACK );

glReadPixels( 0, 0,
nWidth, nHeight,
GL_RGB,
GL_UNSIGNED_BYTE,
(GLvoid*)pcBuffer);

............
............
?????

}

//this is in glut keyboard function
if(capture button is pressed, whatever that is)
saveScreen();

SeskaPeel
07-22-2004, 09:29 AM
You did all the OpenGL part, so you've started an offtopic thread.

Get a documentation on bmp format (wotsite.org ?), write the correct header, and then write the data contained in your buffer using this format (your buffer contains RGBRGBRGBRGB... data, each R, G or B component being a char, starting from bottom left IIRC, and jumping back to the left pixel of the line one row up whan at end of line).
To open and write in a file, use your os specific file format, or use fopen and fwrite, or whatever.

SeskaPeel.