title: opengl: nonlinear additive color blending
body: <p>I'm writing an PyOpenGL-based UI for manually aligning images. I display my two images as textured quads, the moving image on top of the static reference. The moving image is shown in red with varying alpha, i.e. <code>glColor4f(1.,0.,0.,overlay_opacity)</code>, and the static image is shown in cyan with constant opacity equal to one, i.e. <code>glColor4f(0.,1.,1.,1.)</code>. The user can then vary <code>overlay_opacity</code> by mouse scrolling in order to fade between the moving and reference images.</p>
  
  <p>At the moment I am using <code>glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)</code>. Whilst this does allow me to fade smoothly between the cyan and red images, it also means that when <code>overlay_opacity</code> is equal to 0.5 I get only half the maximum intensity of the red and cyan images, so the result looks dim and muddy. If I use <code>glBlendFunc(GL_SRC_ALPHA,GL_ONE)</code> I always get the max intensity for my cyan image, so I can't fade it out. What I really want is some sort of nonlinear blending that looks like the third graph below:</p>
  
  <p><img src="https://i.stack.imgur.com/209Th.png" alt="enter image description here"></p>
  
  <p>I guess I could perhaps do this in a fragment shader, but it seems like there ought to be a much simpler way to achieve the same result using just <code>glBlendFunc()</code>. I've also tried <code>GL_SRC_ALPHA_SATURATE</code>, which doesn't seem to work in my implementation.</p>