Jump to content

  • Log In with Google      Sign In   
  • Create Account


Fail to read the offscreen buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 SagoO   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 April 2011 - 08:27 AM

HI,

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

static const char *fragment_source = {

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


Then, I create a offscreen rendering FBO:

/*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);

Then, I read the buffer:

/*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);

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.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS