当我绘制到帧缓冲区对象时,Alpha 混合没有按预期工作。具体来说,调用 glBlendFunc 对帧缓冲区中的像素没有影响。我在使用glReadPixels
. 以下调用glBlendFunc*
产生相同的结果:
glBlendFunc(GL_ONE, GL_ZERO);
glBlendFunc(GL_ZERO, GL_ONE);
glBlendFunci(myFramebuffer, GL_ONE, GL_ZERO);
glBlendFunci(myFramebuffer, GL_ZERO, GL_ONE);
这是我的绘制代码:
glEnable(GL_BLEND);
glEnablei(GL_BLEND, myFramebuffer); // Obviously I don't need both
// Use this blend function ...
glBlendFunc(GL_ZERO, GL_ONE);
glBlendFunci(myFramebuffer, GL_ZERO, GL_ONE);
// ... or this:
//glBlendFunc(GL_ONE, GL_ZERO);
//glBlendFunci(myFramebuffer, GL_ONE, GL_ZERO);
glColor4f(0.7f, 0.0f, 0.5f, 0.3f);
GLubyte s[4] = {0, 0, 0, 0};
glReadPixels(x, y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, &s);
MsgUtil::TraceWin("%d %d %d %d\n", s[0], s[1], s[2], s[3]);
glBegin(GL_QUADS);
...
glEnd();
GLubyte t[4] = {0, 0, 0, 0};
glReadPixels(x, y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, &t);
MsgUtil::TraceWin("%d %d %d %d\n",t[0], t[1], t[2], t[3]);
输出(对于 GL_ZERO、GL_ONE 的两个订单):
255 255 255 255
127 0 178 76
我显然在使用旧的 GL 代码。以前,上下文创建将版本限制为 1.1。现在版本是 4.4,我请求兼容性配置文件。
这里有什么问题?如何使用 Alpha 混合?