OpenGL: How to do RGBA->RGBA blitting without changing destination alpha

ぃ、小莉子 提交于 2019-12-03 21:01:48

You can set the blend-modes for RGB and alpha to different equations:

void glBlendFuncSeparate(
    GLenum srcRGB, 
    GLenum dstRGB, 
    GLenum srcAlpha, 
    GLenum dstAlpha);

In your case you want to use the following enums:

  glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);

Note that you may have to import the glBlendFuncSeparate function as an extension. It's safe to do so though. The function is around for a very long time. It's part of OpenGL 1.4

Another way to do the same is to disable writing to the alpha-channel using glColorMask:

void glColorMask( GLboolean red,
                  GLboolean green,
                  GLboolean blue,
                  GLboolean alpha )

It could be a lot slower than glBlendFuncSeparate because OpenGL-drivers optimize the most commonly used functions and glColorMask is one of the rarely used OpenGL-functions.

If you're unlucky you may even end up with software-rendering emulation by calling oddball functions :-)

Maybe you could use glColorMask()? It let's you enable/disable writing to each of the four color components.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!