Hi,
I was trying to use some code posted here to capture the screen as a TGA image (as it seemed most straighforward).
My problem is with calling the screendump() method - when called the display does not update (e.g. if I alter the rotation the update doesn’t display), and the program seems to hang indefinately. I am remotely working using ssh and xterm tp login to a linux machine (if that makes any difference). Also, please note that the program works fine until I make the glReadPixels call as far as I am aware.
Here is some of the code:
void screendump(void)
{
FILE *out = fopen("screenshot.tga","wb");
char pixel_data[3*500*500];
short TGAhead[] = {0,2,0,0,0,0,500,500,24};
glReadBuffer(GL_FRONT);
glReadPixels(0,0,w,h,GL_BGR,GL_UNSIGNED_BYTE,pixel_data);
fwrite(&TGAhead,sizeof(TGAhead),1,out);
fwrite(pixel_data,3*500*500,1,out);
fclose(out);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
// gluLookAt( 36.0, 15.0, 42.0, 0.0, 10.0, 0.0, 0.0, 1.0, 0.0 );
gluLookAt( 0, 0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
glEnable( GL_COLOR_MATERIAL );
glEnable( GL_DEPTH_TEST );
glEnable( GL_SMOOTH );
glPushMatrix();
//Rotate
glRotatef(rotX,1.0,0.0,0.0);
glRotatef(rotY,0.0,1.0,0.0);
glRotatef(rotZ,0.0,0.0,1.0);
//Translate
glTranslatef(transX,0.0,0.0);
glTranslatef(0.0,transY,0.0);
glTranslatef(0.0,0.0,transZ);
//Scale
glScalef(sc,sc,sc);
//Render the polygon!
render_poly();
//Draws the axis!
axis();
glPopMatrix();
glFlush();
glutSwapBuffers();
screendump();
glutPostRedisplay();
}