Framebuffer grab problem using glReadPixel()

  • Follow


Hi,
I wrote a simple application that loads a 3d model.
I also would grab images from framebuffer, so I add this code:

  glutPostRedisplay();
  glutSwapBuffers();
  .
  .
  glGetIntegerv(GL_VIEWPORT, geom);
  width = geom[2];
  height = geom[3];

  input = (GLubyte *) malloc(width * height * 3 * sizeof(GLubyte));
  if(!input){
	  perror("\nMalloc video buffer");
	  exit(0);
  }
  glReadBuffer(GL_BACK);
  glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, input);

Then I write input buffer in a file in ppm format.
I get good images, but if I resize manually app's window I only get
confused image files.
What is wrong in my code?


Thanks,
Alessandro Marino
0
Reply a_marino 3/1/2004 8:26:30 AM

Alex wrote:
>
>   glGetIntegerv(GL_VIEWPORT, geom);
>   width = geom[2];
>   height = geom[3];
> I get good images, but if I resize manually app's window I only get
> confused image files.
> What is wrong in my code?
>

The viewport isn't the the same as the size
of the window.


-- 
<\___/>          "To err is human, to moo bovine."
/ O O \
\_____/  FTB.    For email, remove my socks.


0
Reply fungus 3/1/2004 9:50:20 AM


Alex wrote:
> Hi,
> I wrote a simple application that loads a 3d model.
> I also would grab images from framebuffer, so I add this code:
> 
>   glutPostRedisplay();
>   glutSwapBuffers();
>   .
>   .
>   glGetIntegerv(GL_VIEWPORT, geom);
>   width = geom[2];
>   height = geom[3];
> 
>   input = (GLubyte *) malloc(width * height * 3 * sizeof(GLubyte));
>   if(!input){
> 	  perror("\nMalloc video buffer");
> 	  exit(0);
>   }
>   glReadBuffer(GL_BACK);
>   glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, input);
> 
> Then I write input buffer in a file in ppm format.
> I get good images, but if I resize manually app's window I only get
> confused image files.
> What is wrong in my code?
> 
> 
> Thanks,
> Alessandro Marino

Hi,

have you tried to set glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ) ?
The error might occur when you write your ppm from your "input"
array. The default unpack-alignment is 4 bytes, so when you resize your
window to a non-multiple of 4 you might get into trouble.

Regards,

	Toni

-- 
for mail, mirror: ed.lausivksa@elielb
0
Reply Antonio 3/1/2004 11:13:01 AM

"Alex" <a_marino@libero.it> wrote in message
news:f51b1ea6.0403010009.17465faa@posting.google.com...
> Hi,
> I wrote a simple application that loads a 3d model.
> I also would grab images from framebuffer, so I add this code:
>
>   glutPostRedisplay();
>   glutSwapBuffers();
>   .
>   .
>   glGetIntegerv(GL_VIEWPORT, geom);
>   width = geom[2];
>   height = geom[3];
>
>   input = (GLubyte *) malloc(width * height * 3 * sizeof(GLubyte));
>   if(!input){
>   perror("\nMalloc video buffer");
>   exit(0);
>   }
>   glReadBuffer(GL_BACK);
>   glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, input);
>
> Then I write input buffer in a file in ppm format.
> I get good images, but if I resize manually app's window I only get
> confused image files.
> What is wrong in my code?
>
>
> Thanks,
> Alessandro Marino

You have to handle resize event and update viewport size.
After that your code will work...

yooyo


0
Reply news 3/1/2004 11:14:48 AM

I already handle resize event with:

static void reshape ( int w, int h )
{
  glViewport ( 0, 0, w, h ) ;
}

and glutReshapeFunc( reshape );
But the application doesn't work.

Alessandro

> >   glutPostRedisplay();
> >   glutSwapBuffers();
> >   .
> >   .
> >   glGetIntegerv(GL_VIEWPORT, geom);
> >   width = geom[2];
> >   height = geom[3];
> >
> >   input = (GLubyte *) malloc(width * height * 3 * sizeof(GLubyte));
> >   if(!input){
> >   perror("\nMalloc video buffer");
> >   exit(0);
> >   }
> >   glReadBuffer(GL_BACK);
> >   glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, input);
> >
> > Then I write input buffer in a file in ppm format.
> > I get good images, but if I resize manually app's window I only get
> > confused image files.
> > What is wrong in my code?
> >
> >
> > Thanks,
> > Alessandro Marino
> 
> You have to handle resize event and update viewport size.
> After that your code will work...
> 
> yooyo
0
Reply a_marino 3/1/2004 4:44:42 PM

4 Replies
688 Views

(page loaded in 0.045 seconds)

Similiar Articles:













7/21/2012 11:25:20 PM


Reply: