Accumulating Alpha in FBO -> Texture loop

I’m trying to accumulate alpha values from progressive calls of the same shader / fbo. I am using the rgb channels to store movement data, so I’m left with only the alpha as a usable extra. I dont’ actually care about doing proper transparency blending or anything like that, I just want to move the numbers from output by the shader back into the shader. Here’s what my code looks like.

ofFbo fbo;
ofShader shader;
ofTexture feedback;
ofPixels pixels;

fbo.allocate(w, h, GL_RGBA);
texture.allocate(w, h, GL_RGBA);
pixels.allocate(w, h, OF_PIXELS_RGBA);

fbo.begin();
ofClear(0,0,0,0);
  shader.begin();
    shader.setUniformTexture('tex0', feedback, 0);
    feedback.draw(0,0);
  shader.end();
fbo.end();

fbo.readToPixels(pixels);
feedback.loadData(pixels);

And then in my shader

uniform sampler2DRect tex0;
varying uv
void main(){
 float alpha = texture2DRect(tex0, uv).a;
 alpha += 0.1;
  gl_FragColor = vec4(1.0,0.0,0.0,alpha);
}

I thought that the output of the framebuffer would keep whatever alpha values are written to it when I transfer it to the feedbackTexture, but it seems like nothing is happening. What I really want is for no changes to be made to whatever is output from the shader/fbo, so it can just be recycled back in.

I usually just get a bunch of gunk from whatever was leftover in gpu memory. I was under the impression that my alpha would slowly increase the longer the program was run but this is clearly not the case. I also thought that my ofClear call would empty out the fbo, so that it could draw on a clean slate.

Can someone explain what’s going on here and how I might accomplish this? FWIW I have been messing around with quite a few glBlendFunc but I just can’t seem to find the right combo.

Also I feel like this should work since if I make my shader look like below I get the behavior I want.

 uniform sampler2DRect tex0;
    varying uv
    void main(){
     float val = texture2DRect(tex0, uv).b;
     val += 0.1;
      gl_FragColor = vec4(1.0,0.0,val,1.0);
    }

Thanks!

It looks like you would like to implement an alpha accumulation with no blending, correct?
To disable OpenGL alpha blending, you can call ofEnableBlendMode( OF_BLENDMODE_DISABLED ) right before you draw into you FBO.

Hope that helps!