• Advertisement
Sign in to follow this  

How do I read back texel data from texture bound to FBO

This topic is 3557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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: Render() { EnableFrameBuffers(); RenderScene(); DisableFrameBuffers(); RenderTexture1(); RenderTexture2(); RenderPlot(); } 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 = 4*m_nxPixels*m_nyPixels*sizeof(float); float* texture1Data = (float*)malloc(texture1Size); GLint texture2Size = 4*m_nxPixels*m_nyPixels*sizeof(float); float* texture2Data = (float*)malloc(texture2Size); EnableFrameBuffers(); glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); glBindTexture(texTarget, textureID); glReadPixels(0,0,m_nyPixels,m_nyPixels,texFormat,GL_FLOAT,texture1Data); glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); glBindTexture(texTarget, textureID); glReadPixels(0,0,m_nyPixels,m_nyPixels,texFormat,GL_FLOAT,texture2Data); DisableFrameBuffers(); 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. Thanks,CD

Share this post


Link to post
Share on other sites
Advertisement
You unbind the FBO, then with the bound texture object call glGetTexImage2D() and that should work... I haven't tried it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement