Where does glreadpixel go?

I’m very new to OpenGL and have been asked to include an option to output an avi file of the animation the program creates. The program is in C (Not C++) and uses GLUT for most of the calls.

In the animation loop, there is a call to

 glutPostRedisplay()

.

This call,

glutDisplayFunc(IMAGE)

, uses the IMAGE function below.

This code is in the IMAGE function:

    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glShadeModel(GL_SMOOTH);
    for (e = 1; e < nels[f]; ++e)
    {
	glPushMatrix();
	glScalef(doub1,doub1,inv10);
	glScalef(scalex, scaley, scalez);
	glTranslatef(tx,ty,tz);
	glTranslatef(inv2,inv2,inv2);
	glRotatef(anglez,0,0,1);
	glRotatef(angley,0,1,0);
	glRotatef(anglex,1,0,0);
	glTranslatef(ce3[f][e][0], ce3[f][e][1], ce3[f][e][2]);
	glRotatef(qu3[f][e][0], qu3[f][e][1], qu3[f][e][2], qu3[f][e][3]);
	glScalef(ax3[f][e][0], ax3[f][e][1], ax3[f][e][2]);
	ellmat(r,e,f);
	glPolygonMode(GL_FRONT, GL_FILL);
	glBegin(GL_QUADS);
	amb = 0.7;
	for (j = 0; j < nfaces; ++j)
	{
	    illum = doub0;
	    for (k = 0; k < 3; ++k)
	    {
		    illum += r[k][1] * norm[j][k];
	    }
	    shade = amb + (doub1 - amb)*illum;
	    glColor3f(shade * co3[f][e][0], shade * co3[f][e][1], shade * co3[f][e][2]);
	    for (k = 0; k < 4; ++k)
	    {
		    glVertex3f(sph[j][k][0], sph[j][k][1], sph[j][k][2]);
	    } /* k  vertices */
	} /* j faces */
	//
	glEnd();
	glPopMatrix();
	//
    } /* e ellipsoids */
    glutSwapBuffers();
    glFlush();

I’ve tried looking at the many examples on the web but nothing seems to click with me.

Thanks,
RON C

I don’t see what your post has to do with the title. There’s no glReadPixel. Also I wonder what nels[f] is. Can you be more precis, as what is your problem ?

nels[f] is the number of elements per frame. The parameters are precalulated.

I don’t have a glReadPixel call because I don’t know where it belongs. When is each image ready to have “glReadPixel” do it’s think. I do have the code to follow glReadPixel to use the image ouput from it to create the AVI file - frame by frame.

Thanks in advance for the help and patience.

RON C

Routine with glReadPixel (write as raw not AVI):

	//
	if(first_movie_frame == TRUE)
	{
	  /* Allocate our buffer for the image */
	  if ((movie_image = (unsigned char *)malloc(width * height * 3 * sizeof(char))) == NULL) 
	  {
			fprintf(stderr,"Failed to allocate memory for image
");
//			return(FALSE);
	  }
   }

   /* Copy the image into our buffer */
   glReadBuffer(GL_BACK_LEFT);
   glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, movie_image);

   /* Write the raw file */
   /* fprintf(fptr,"P6
%d %d
255
",width,height); for ppm */
   for (j = height - 1; j >= 0 ; j--) 
   {
	  j3width = j * 3 * width;
	  for (i = 0; i < width; i++) 
	  {
         fputc(movie_image[j3width + i * 3 + 0], movie_file);
         fputc(movie_image[j3width + i * 3 + 1], movie_file);
         fputc(movie_image[j3width + i * 3 + 2], movie_file);
      }
   }


I don’t have a glReadPixel call because I don’t know where it belongs. When is each image ready to have “glReadPixel” do it’s think.

glReadPixel will read image after all commands preceeding it have ben completed. The right place depends on what you give as parameter to the glReadBuffer funtion. If one from GL_BACK* parameters was used then the right place is after all rendering commands have ben issued and before the SwapBuffers call. If one from GL_FRONT* parameters was used then the right place is after SwapBuffers call.

You don’t need to copy the image to a specific buffer (as back left). Just call it before swapping for example, with specifying the read buffer to back.

I have it working for getting the data from the gl buffers. Now I need to code an AVI file from the data.

Thanks for the help.

RON C