glBlendFunc and framebuffer object

2019-08-31 08:12发布

Alpha blending is not working as expected when I draw to a framebuffer object. Specifically, calling glBlendFunc has no effect on what pixels are in the framebuffer. I check what is in the framebuffer before and after drawing using glReadPixels. The following calls to glBlendFunc* yield the same result:

glBlendFunc(GL_ONE, GL_ZERO);
glBlendFunc(GL_ZERO, GL_ONE);
glBlendFunci(myFramebuffer, GL_ONE, GL_ZERO);
glBlendFunci(myFramebuffer, GL_ZERO, GL_ONE);

Here is my draw code:

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]);

Output (for both orders of GL_ZERO, GL_ONE):

255 255 255 255
127 0 178 76

I am obviously using old GL code. Previously the context creation limited the version to 1.1. Now the version is 4.4 and I request a compatibility profile.

What is wrong here? How can I use alpha blending?

0条回答
登录 后发表回答