]> Pileus Git - grits/commit
Use glBlendFuncSeparate for alpha masking in tex.c
authorAndy Spencer <andy753421@gmail.com>
Mon, 30 Jan 2012 06:39:15 +0000 (06:39 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 30 Jan 2012 08:16:09 +0000 (08:16 +0000)
commit474d8fa06cb68a91acdf81c89d3bfe6dd2d7ba68
tree1ff3d0d120f805a04a85a801f08979d17b49ac5e
parentfb5bebeaac12935e2202f34b4719fcfcef84a4c6
Use glBlendFuncSeparate for alpha masking in tex.c

The draw happens in two steps:

1. Copy the alpha mask to the framebuffer without changing the color
   channels: glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO)

   This uses GL_LINEAR filtering and GL_CLAMP_TO_BORDER to create a
   alpha mask with hard edges as opposed to blurred edges.

2. Copy the texture color to the framebuffer using the alpha mask
   stored in the frame buffer as the mask:
   glBlendFuncSeparate(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ZERO, GL_ZERO);

   We can turn on GL_LINEAR filtering and GL_CLAMP here because the
   alpha mask is taken from the framebuffer instead of the filtered
   alpha component of the texture.

This creates a nice looking image without having to do any fancy setup.
The previous version also has issues if the texture is not split in the
middle of the polygon.

Unfortunately glBlendFuncSeparate depends on OpenGL 2.0 and requires
twice as many draws.
examples/tex/tex.c