title: OpenGL ES 2 - Drawing GL_POINTS directly vs indirectly
body: <p>I am creating an iOS app for drawing / sketching and right now encountering a problem when I draw GL_POINTS <strong>indirectly</strong> to an FBO that then this FBO is stamped onto a final FBO. </p>
  
  <p>Here is the result when I draw the GL_POINTS <strong>DIRECTLY</strong> to an FBO</p>
  
  <p><img src="https://i.stack.imgur.com/tLN4l.png" alt="Direct Drawing"></p>
  
  <p>And here is the result when I draw the points <strong>INDIRECTLY</strong> by drawing to an FBO and then draw this FBO onto another FBO</p>
  
  <p><img src="https://i.stack.imgur.com/ocVMo.png" alt="Drawing Indirectly"></p>
  
  <p>As you can see, the indirect method didn't blend quite right. I don't know if the problem is because of my blend mode is wrong or because there's a loss precision when drawing indirectly.</p>
  
  <p>Here is my algorithm :</p>
  
  <p>I. Drawing the points to an offscreen FBO named drawingFramebuffer:</p>
  
  <pre><code>// pre-multiplied alpha
  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  glBindFramebuffer(GL_FRAMEBUFFER, drawingFramebuffer);
  // clear drawing FBO
  glClearColor(0, 0, 0, 0);
  glClear(GL_COLOR_BUFFER_BIT);
  ... 
  // draw the points
  glDrawArrays(GL_POINTS, 0, totalPoints);
  </code></pre>
  
  <p>in the fragment shader</p>
  
  <pre><code>uniform sampler2D brushTexture;
  uniform highp vec4 brushColor;
  void main()
  {
      highp vec4 textureAlpha = texture2D(brushTexture, gl_PointCoord.xy);
      gl_FragColor = vec4(brushColor.rgb * textureAlpha.a, textureAlpha.a);      
  }
  </code></pre>
  
  <p>II. And then, stamping the drawingFramebuffer onto final Framebuffer by using a quad </p>
  
  <pre><code>// draw the texture using pre-multiplied alpha
  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  glBindFramebuffer(GL_FRAMEBUFFER, finalFramebuffer);
  ... 
  // draw the quad vertices using triangle strip
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  </code></pre>
  
  <p>in the fragment shader</p>
  
  <pre><code>uniform sampler2D texture;
  varying highp vec2 textureCoord;
  void main()
  {
      highp vec4 textureColor = texture2D(texture, textureCoord);
      gl_FragColor = textureColor;      
  }
  </code></pre>
  
  <p>I'm utterly confused, how can drawing directly and indirectly yields different results when the blend modes are the same. </p>
  
  <p>Thanks guys/girls for any help!</p>
  
  <p>--- Edited to Add ---</p>
  
  <p>After some calculations with excel, I found out that my blending is already correct, so I suspect the problem is the loss of precision that's happening when reading the drawing FBO</p>