Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Fail to read the offscreen buffer

4: Adsense

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   

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.




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.