Hi, I am trying to capture the contents of a window and then draw them back to the same window. Later, it will not necessarily be the same frame buffer to which i write, but before I get there, I need to know why the following doesn’t work. Can anyone comment on it? Before the code executes, there is a glut window up with a pretty image on it. At the end of this snippet, the screen is black. (I put in a glClear() to see if I was redrawing correctly). Any help would be hugely appreciated. I hope this isn’t too simple a question for this forum. Sorry for so much code, but I wanted the whole picture to be give if possible. The window is indeed of type RGB.
GLint blend_enabled;
GLint depth_enabled;
GLint fog_enabled;
GLint texture2d_enabled;
GLint texture1d_enabled;
GLint saved_matrix_mode;
screenPixels = (GLubyte*)
malloc(4 * glutGet(GLUT_WINDOW_WIDTH) *
glutGet(GLUT_WINDOW_HEIGHT) *
sizeof(GLfloat));
glReadBuffer(GL_FRONT);
printf("readPixels begun
");
glReadPixels(0,0,glutGet(GLUT_WINDOW_WIDTH),
glutGet(GLUT_WINDOW_HEIGHT), GL_RGBA, GL_UNSIGNED_BYTE,
screenPixels);
printf("readPixels finished
");
/* this is to speed up a bit*/
if(blend_enabled = glIsEnabled(GL_BLEND))
glDisable(GL_BLEND);
if(depth_enabled = glIsEnabled(GL_DEPTH_TEST))
glDisable(GL_DEPTH_TEST);
if(fog_enabled = glIsEnabled(GL_FOG))
glDisable(GL_FOG);
if(texture2d_enabled = glIsEnabled(GL_TEXTURE_2D))
glDisable(GL_TEXTURE_2D);
if(texture1d_enabled = glIsEnabled(GL_TEXTURE_1D))
glDisable(GL_TEXTURE_1D);
glGetIntegerv(GL_MATRIX_MODE, &saved_matrix_mode);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0.0, (GLfloat) glutGet(GLUT_WINDOW_WIDTH),
0.0, (GLfloat) glutGet(GLUT_WINDOW_HEIGHT));
glRasterPos2i(0, 0);
glDrawBuffer(GL_FRONT);
printf("drawPixels begun
");
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(glutGet(GLUT_WINDOW_WIDTH),
glutGet(GLUT_WINDOW_HEIGHT), GL_RGBA, GL_UNSIGNED_BYTE,
screenPixels);
printf("drawPixels finished
");
free(screenPixels);
glPopMatrix();
glMatrixMode(saved_matrix_mode);
if(depth_enabled)
glEnable(GL_DEPTH_TEST);
if(fog_enabled)
glEnable(GL_FOG);
if(texture2d_enabled)
glEnable(GL_TEXTURE_2D);
if(texture1d_enabled)
glEnable(GL_TEXTURE_1D);