Counter problems when reading texture from FBO

Hi,

  /*Read values back*/
	/*Method 1*/
	glBindTexture(GL_TEXTURE_RECTANGLE_ARB,textureID);
	  glGetTexImage(GL_TEXTURE_RECTANGLE_ARB,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,data);

	printf("Texture:
");
    	for (i=0; i<2048*2048; i++)
        	printf("%c",data[i]);

	printf("

");

	/*Method 2*/
    	glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
    	glReadPixels(0, 0, 2048, 2048, GL_LUMINANCE, GL_UNSIGNED_BYTE, result);
    	printf("Data after roundtrip:
");
    	for (i=0; i<2048*2048; i++)
        	printf("%c",result[i]);

I use 2 methods to read my texture. The first method works perfectly and it gives me the exact texture. But I not sure why method 2 give me nothing?My program just end after printing the message “Data after roundtrip”. Why?

Here is the code of FBO:


glGenFramebuffersEXT(1, &fboID); 
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fboID);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, textureID, 0);

Is it the texture fails to attach to FBO?

I check the status of FBO using the following code:


glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(GL_FRAMEBUFFER_COMPLETE_EXT)
	{
		printf("FBO complete!!");
	}

And it shows the message “FBO complete!!”. So, it means my FBO should be correct. But why I cant read it?

R u sure that the fbo is bound before the glReadBuffer call?

I check the status already and it shows FBO complete.It means no problems for the FBO right?

You still have to bind it to the context.

Do you means bind the FBO to context?Like this:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fboID);

I try ade but it still not works. It does not print out anything.

This isn’t correct, it should be something like:


GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status == GL_FRAMEBUFFER_COMPLETE_EXT)
	{
		printf("FBO complete!!");
	}

ps. http://www.songho.ca/opengl/gl_fbo.html has a nice tutorial for FBOs

I think it should be the same. But I try this code also, it shows FBO complete. What is the problem actually?

Checking “if(GL_FRAMEBUFFER_COMPLETE_EXT)” will always result in the condition being evaluated to true because what is actually being evaluated is “if (0x8CD5 != 0)”.

Okay…But I had tried to following code and it return the same output.


GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status == GL_FRAMEBUFFER_COMPLETE_EXT)
{
printf("FBO complete!!");

After I put this code, it gives me FBO complete message also.
}

If your application is terminating unexpectedly, then maybe “result” isn’t large enough to store all the data? This would mean that when OpenGL tries to write to “result”, it would end up overwriting other application data.

Have you also tried calling glGetError to see if any OpenGL errors have occurred?

Hem…The size of the result and the data that I sent into is the same. So, should be enough. But anyway, I will give this a try later.

So, my code does not have any error right? I means programming error.

So, my code does not have any error right?

The 20 or so lines you posted seem to be fine. But that doesn’t mean anything, since that’s likely less than 5% of your program.

I check my code again using glGetError().


GLenum e;
if ((e=glGetError())!= GL_NO_ERROR)
	printf("GL Error: (%s)
", gluErrorString(e));

I found this error.

GL Error: invalid operation (Readpixel)


glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glReadPixels(0, 0, size, size, GL_LUMINANCE, GL_UNSIGNED_BYTE, result);

The glReadPixels there prompt error. Invalid operation. Does glReadBuffer bind the fbo to the context? Even though it does not, i already add glBindFramebufferEXT to bind the fbo. However, still have the same problem. I not sure how to troubleshoot the problem now. What I know now is the glReadPixels generates an error.

Here are a list of causes that would lead to an invalid operation for glReadPixels.

I check already. I use the correct format. But why there are 2 different version?

glReadPixels

The above link shows that GL_LUMINANCE is the supported format. But according to the link you give me, seems like GL_LUMINANCE does not support in glReadPixels.

Are you using the core profile? If so GL_LUMINANCE is no longer supported, compare:
http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml
and
http://www.opengl.org/sdk/docs/man3/xhtml/glReadPixels.xml

Then which format should I use since I jz want to use one component only in every pixels instead of using RGB format that have 3 components. I just want every pixel store one byte of component instead of 3 bytes.

for GL 3.x core profiles try using GL_RED

Actually I not sure what is core profiles, my openGL version is just 1.4 only.

I have another question. Let’s say if i use one red component only in my texture, can I read the red component out only from the frame buffer?

Actually I not sure what is core profiles, my openGL version is just 1.4 only.

Then none of what he said matters to you. It only matters if you’re using GL 3.1 and above, and then only if you don’t want to use the compatibility profile.