Counter problems when reading texture from FBO


  /*Read values back*/
	/*Method 1*/

    	for (i=0; i<2048*2048; i++)



	/*Method 2*/
    	glReadPixels(0, 0, 2048, 2048, GL_LUMINANCE, GL_UNSIGNED_BYTE, result);
    	printf("Data after roundtrip:
    	for (i=0; i<2048*2048; 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); 

Is it the texture fails to attach to FBO?

I check the status of FBO using the following code:

		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:


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);
		printf("FBO complete!!");

ps. 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);
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);
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?


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:

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.