Fail to read the frame buffer using PBO

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_UNSIGNED_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:
");
for (i=0;i<noOfpacket*size;i++)
        printf("%d",result[i]);
printf("

");
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.

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_UNSIGNED_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:
");
checkError("Segmentation error!");
for (i=0;i<noOfpacket*size;i++)
        printf("%d",result[i]);
printf("

");

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


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

");	

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

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.

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?

I wouldn’t know.
Then render the scene to the backbuffer and read from the back.
glReadBuffer(GL_BACK)