title: Libgdx framebuffer blending not working
body: <p>I am attempting to make dynamic 2D shadows in my game.</p>
  
  <p>I'm successfully able to render the shadows to a frame buffer. (grey and white squares designate transparency)</p>
  
  <p><img src="https://i.stack.imgur.com/TtX7E.png" alt="enter image description here"></p>
  
  <p>Then for debug purposes, I render the contents of the frame buffer on top of another frame buffer which is cleared white every frame, and then render this frame on my game. This works just fine... as long as I render the shadows with 100% opaqueness: </p>
  
  <p><img src="https://i.stack.imgur.com/qeNCW.png" alt="enter image description here"></p>
  
  <p>But if I do this before drawing the shadows on the second framebuffer,</p>
  
  <pre><code>spriteBatch.setColor(0f, 0f, 0f, 0.5f);
  </code></pre>
  
  <p>The transparent shadows tear through the framebuffer and you can see the game world underneath.</p>
  
  <p><img src="https://i.stack.imgur.com/synU8.png" alt="enter image description here"></p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class Light
  {
      FrameBuffer shadowbuffer; // for rendering shadows
      FrameBuffer buffer; // for debug
      OrthographicCamera cam;
  
      public Light(Images images)
      {
          shadowbuffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
  
          buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);     
  
          cam = new OrthographicCamera(buffer.getWidth(), buffer.getHeight());
          cam.setToOrtho(true);
          cam.update();
      }
  
      public Texture render(SpriteBatch batch, GameWorld world)
      {
          batch.end();
          batch.setProjectionMatrix(cam.combined);
  
          shadowbuffer.begin();
          Gdx.gl.glClearColor(0, 0, 0, 0);
          Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);  
          batch.begin();
  
          // ... render shadows here ...
  
          batch.end();
          shadowbuffer.end();
  
          buffer.begin();
          Gdx.gl.glClearColor(0, 0, 0, 0);
          Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
  
          batch.begin();
  
          batch.setColor(0f, 0f, 0f, .5f);
          batch.draw(shadowbuffer.getColorBufferTexture(), 0, 0);
          batch.setColor(Color.WHITE);
  
          batch.end();
          buffer.end();
  
          batch.begin();
  
          return buffer.getColorBufferTexture();
      }
  }
  </code></pre>
  
  <p>I've tried all sorts of different blending settings, but none of them work..</p>
  
  <p><strong>EDIT</strong> Here are the blend settings I'm currently using:</p>
  
  <pre><code>    batch.enableBlending();
      batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
  </code></pre>