How do I read texel data from texture bound to FBO

In my app, I render the scene to a FBO, which has two RGBA FP textures attached to it.
I use two GLSL shaders to write to the textures.
After I render to the textures, I render them on a quad to display the results.

So it goes something like this:



RenderTexture1 and RenderTexture2 use a GLSL shader to map the texture to a quad.

The ReturnPlot function is supposed to take some data from each of the aforementioned textures, do some stuff to it, and render a plot. My problem is that I can’t seem to read the data back from the texture correctly.

Here is what I am trying…

GLint texture1Size = 4m_nxPixelsm_nyPixelssizeof(float);
texture1Data = (float*)malloc(texture1Size);

GLint texture2Size = 4m_nxPixelsm_nyPixelssizeof(float);
texture2Data = (float*)malloc(texture2Size);


glBindTexture(texTarget, textureID);

glBindTexture(texTarget, textureID);


int x = 10;
int y = 10;

// get data at x,y
int index = x * m_nxPixels + y;
float red1 = texture1Data[index];
float green1 = texture1Data[index+1];
float blue1 = texture1Data[index+2];
float alpha1 = texture1Data[index+3];

float red2 = texture2Data[index];
float green2 = texture2Data[index+1];
float blue2 = texture2Data[index+2];
float alpha2 = texture2Data[index+3];

The data read back is not what I expect and not what is being rendered in the RenderTexture1 and RenderTexture2 methods. My question is, how do I read back the texel data from a texture which is currently bound to an FBO.


the texture attached to a FBO is just a standard texture
thus to see what it contains u just use the normal methods
bind the texture + draw a polygon onscreen
glGetTexImage( …, data )
save data to a file + look at it in photoshop/gimp

I rendering it, but when I try to retrieve the data in numerical format is when I have the problem… I am using the glGetTexImage call but sounds like maybe I am not getting the data in the right format… GL_FLOAT vs. GL_RGBA, or type or something… In other words, I think GL is giving me what I ask for, I am just not asking for the right thing…

Thanks for the response,

this doesnt make sense -> GL_FLOAT vs. GL_RGBA
perhaps float vs GLubyte etc, if youre saving a copy of the texture say as a *.tga texture file u most likely want to use GL_RGBA + GL_UNSIGNED_BYTE, beaware some systems have BGRA storage so u might wanna use GL_BGRA if the red + blue channels are swapped

anyways youve made an error above

int index = x * m_nxPixels + y;
float red1 = texture1Data[index];
float green1 = texture1Data[index+1];

this will only fill ~1/4 of the data
ie u need int index = (x * m_nxPixels + y) * 4;

also m_nxPixels is wrong u need m_nyPixels