FBO to store / accumulate pixels in fragment shader? OpenGL


Trying to follow this tutorial: http://in2gpu.com/2014/09/24/render-to-texture-in-opengl/

Here’s my code so far:

on init:

pixelaccum_buffer = vector<GLfloat>(width*height, 0);

glTexImage2D(GL_TEXTURE_2D, 0, 0x822E/*GL_R32F*/, width, height, 0, GL_RED, GL_FLOAT, pixelaccum_buffer.data());

render loop:

glGenTextures(1, &pixelaccum_texture_id); // get texture id
glBindTexture(GL_TEXTURE_2D, pixelaccum_texture_id);
e.glUniform1i(e.glGetUniformLocation(shader->getProgramID(), "pixelaccum_texture"), 0);

/* FBO */
e.glGenFramebuffers(1, &FBO_id);
//e.glBindFramebuffer(GL_FRAMEBUFFER, FBO_id);
//e.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, pixelaccum_texture_id, 0);

if I uncomment e.glBindFramebuffer(GL_FRAMEBUFFER, FBO_id); I get an openGL error.

Am I on the right track or is there a better way? I just want the frament shader to write brightness values of GLfloat from 0.0f to 1.0f. Everytime the fragment shaders writes a brightness value, it needs to accumulate it. So it needs to add to the pixel values already there. Then I need to subtract each pixel value by some fixed amount, say -0.05f. This is pixel decay. Finally, I want to render a black and white image essentially.