• Advertisement
Sign in to follow this  

Fail to read the offscreen buffer

This topic is 2480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI,

I have create a offscreen rendering buffer. I have a fragment program jz simple as this:

[code]
static const char *fragment_source = {

"void main(void)"
"{"
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);"
"}"

[/code]

Then, I create a offscreen rendering FBO:

[code]
/*Create a fbo to perform offscreen rendering*/
glGenFramebuffersEXT(1,&fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo);

/*Create render object*/
glGenRenderbuffersEXT(1,&renderbuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,renderbuffer);

glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_RGBA,noOfpacket,size);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_RENDERBUFFER_EXT,renderbuffer);

status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

switch(status)
{
case GL_FRAMEBUFFER_COMPLETE_EXT:
printf("***FBO complete***\n\n");
break;
default:
fprintf(stderr, "Error: %s\n", gluErrorString(status));
break;
}

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo);
[/code]

Then, I read the buffer:

[code]
/*Read values back*/
/*Set the target framebuffer to read*/
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);

/*Read pixels from framebuffer to CPU buffer*/
glReadPixels(0,0,size,noOfpacket,GL_RGBA,GL_UNSIGNED_BYTE,result);
checkError("glReadPixels error!");
printf("Data in frame buffer:\n");
for (i=0;i<noOfpacket*size;i++)
printf("%d",result[i]);
printf("\n\n");

glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
[/code]

Well. I got all zeros all the time in the frame buffer. That is impossible since my fragment should output something. I never unbound my FBO. So, the shader should render to the offscreen FBO. Any one face this problem before?

Help please.... Thank for your reply.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement