Can't get masking to work correctly with OpenGL

南楼画角 提交于 2019-12-05 14:39:51

Well for starters, I don't think this will do what you expect:

glBlendFunc(GL_ONE, GL_ZERO);
draw_img(mask);

This is blending the mask with the background, but you're saying "Take 100% of the mask always, and 0% of the destination always". After this step there will be no more red pixels in the framebuffer, because you've replaced all the channels of the framebuffer with the mask texture.

I guess you were probably intending to replace only the alpha channel, and leave the colors untouched? You can do this if you mask the color channels before drawing the mask, with glColorMask(GL_FALSE,GL_FALSE,GL_FALSE, GL_TRUE);

I think if you do that it might work.

I think this kind of effect might typically be done with a multitexturing operation with glTexEnv, but if you don't want to use multitexturing this should work.

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