PDA

View Full Version : Fail to read the frame buffer using PBO



SagoO
04-06-2011, 04:09 AM
Hi,

I try to follow the tutorial to read the frame buffer using PBO. When I want to read out the value in the frame buffer, it prints zeros only.


/*Read values back*/
/*Set the target framebuffer to read*/
glReadBuffer(GL_FRONT);
/*Read pixels from framebuffer to PBO*/
glReadPixels(0,0,size,noOfpacket,GL_RGBA,GL_UNSIGN ED_BYTE,(void*)0);
checkError("glReadPixels error!");
/*Map the PBO to process its data by CPU*/
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB,pboread);
result =
(GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
printf("Data in frame buffer:\n");
for (i=0;i<noOfpacket*size;i++)
printf("%d",result[i]);
printf("\n\n");
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB,0);


I follow exactly the same. But still cannot read the frame buffer. Is it the frame buffer really empty or cant read it? I think there should not be zeros in my frame buffer as I have output colors in my shader.

SagoO
04-06-2011, 05:47 AM
Well. I change the code like this:



/*Read values back*/
/*Set the target framebuffer to read*/
glReadBuffer(GL_FRONT);

/*Read pixels from framebuffer to PBO*/
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboread); glReadPixels(0,0,size,noOfpacket,GL_RGBA,GL_UNSIGN ED_BYTE,(void*)0);
checkError("glReadPixels error!");
/*Map the PBO to process its data by CPU*/
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboread);
result = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
printf("Data in frame buffer:\n");
checkError("Segmentation error!");
for (i=0;i<noOfpacket*size;i++)
printf("%d",result[i]);
printf("\n\n");


But segmentation fault occurs.The error is comes from this part:



printf("Data in frame buffer:\n");
for (i=0;i<noOfpacket*size;i++)
printf("%d",result[i]);
printf("\n\n");


Seems like cannot access the value of result here. But how comes like that?

V-man
04-06-2011, 06:53 AM
You need to use GL_PIXEL_PACK_BUFFER because you are transfer from the server (OpenGL) to the client (you).
You can look at the example in the spec file for GL_ARB_pixel_buffer_object.

SagoO
04-06-2011, 07:30 AM
Sry...is a mistake. Now I get the value. But all are zeros.

Why? Are the values in the frame buffer really zeros or it read from the wrong place?

V-man
04-06-2011, 02:31 PM
I wouldn't know.
Then render the scene to the backbuffer and read from the back.
glReadBuffer(GL_BACK)