Original Post
glExperts, I have a problem with glDrawPixels. It appears there's some conflicts when I use glDrawPixels and glReadPixels. I get the same image on all frames - frame n is the same as frame 0 (n=0,1,2,...); Below is my draw callback function. Any idea? pfuSaveImage basically does the following:
// Draw process callback
static void DrawChannel (pfChannel *chan, void *)
{
int g_width=500;
int g_height=500;
char *intensity_img;
static int frame_num=0;
char fname[256];
intensity_img=new char[500*500*3];
chan->clear(); //clears framebuffer
pfDraw (); //draws scene
glReadPixels( 0, 0, g_width, g_height, GL_RGB,
GL_UNSIGNED_BYTE, intensity_img);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D( 0.0, g_width, 0.0, g_height);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDrawPixels( g_width, g_height, GL_RGB,
GL_UNSIGNED_BYTE, intensity_img);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
sprintf(fname, "snap_%d.rgb", frame_num);
pfuSaveImage(fname, 0, 0, g_width, g_height, 0);
frame_num++;
if(intensity_img)
free(intensity_img);
}
int pfuSaveImage(char *name, int xorg, int yorg, int xsize, int ysize, int alpha)
{
...
open image file
...
/* read from FRONT-buffer to get channel stats info */
glReadBuffer(GL_FRONT);
/* read the display */
glReadPixels((short)xorg, (short)yorg, (short)xsize, (short)ysize,
GL_RGB, GL_UNSIGNED_BYTE, scrbuf);
/* write the data to the image file */
...
write data to file
...
...
close image file
...
}