Jump to content
  • Advertisement
Sign in to follow this  
sinanmut

Reading a texture from FBO

This topic is 2867 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

Hi,

I want to use FBO for GPGPU application. But when I read the result from color buffer(GL_COLOR_ATTACHMENT0_EXT) I only see "0.0" values. I changed the fragmant shader to "gl_FragColor = vec4(1.0, 1.0, 0.33, 1.0)" for the purpose of debugging, but it is still giving 0.0 values. What I am doing is:

1- creating the FBO,
2- assigning GL_COLOR_ATTACHMENT0_EXT as a render target, and assigning a texture for this buffer.

glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, channels, text_size, text_size, 0, type, GL_FLOAT, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, GL_TEXTURE_2D, textureID, 0);

then I am trying to render the result in to the color buffer by

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_uiFBO);
glPushAttrib(GL_VIEWPORT_BIT );
glViewport(0, 0, text_size, text_size);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

glBindTexture(GL_TEXTURE_2D, frame_buffer_object->getTextureID(0));
glsl_program->use(); //enables the glsl program

glBegin(GL_QUADS);
{
glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f);
glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f);
glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f);
}
glEnd();

glReadPixels(0, 0, 1024, 1024, GL_RGBA, GL_FLOAT, result_texture);

result_texture returns (0.0, 0.0, 0.0, 0.0) values for each pixel which should be another value because all the fragmants are set by the shader to (1.0, 1.0, 0.33, 1.0).

Is there any idea how can I render the result of a shader to a FBO, and read the related buffer to a texture?

Share this post


Link to post
Share on other sites
Advertisement
The fragment shader only deals with pixels actually drawn on screen. If nothing arrives and passes all of the tests (depth, stencil, alpha, ownership, clip) then nothing will show up on screen and all color values will equal the clear color set. Try this:



glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_uiFBO);
glPushAttrib(GL_VIEWPORT_BIT );
glViewport(0, 0, text_size, text_size);

// HERE
glClearColor(0.7, 0.3, 0.1, 0.85);
// HERE

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glEnd();




and see if you get something other than 0.0.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!