我解释我的问题:
我有三个 png 图像,第一个有通道 alpha,另外两个是 RGB:
frame mask background
我必须把它混合起来才能得到这个结果
现在我知道我必须以这种方式掩盖第三个纹理:
if mask_pixel=white:
blend_pixel=pixel with alpha 0
else if mask_pixel=black:
blend_pixel=backgroud_pixel
从现在开始我写了这个:
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, background);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mask);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, frame);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable (GL_BLEND);
glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0, 0.0, 0.0);
glMultiTexCoord2f(GL_TEXTURE1, 0.0, 0.0);
glMultiTexCoord2f(GL_TEXTURE2, 0.0, 0.0);
glVertex3f(-0.7, 0.0, 0.0);
glMultiTexCoord2f(GL_TEXTURE0, 1.0, 0.0);
glMultiTexCoord2f(GL_TEXTURE1, 1.0, 0.0);
glMultiTexCoord2f(GL_TEXTURE2, 1.0, 0.0);
glVertex3f(0.7, 0.0, 0.0);
glMultiTexCoord2f(GL_TEXTURE0, 1.0, 1.0);
glMultiTexCoord2f(GL_TEXTURE1, 1.0, 1.0);
glMultiTexCoord2f(GL_TEXTURE2, 1.0, 1.0);
glVertex3f(0.7, 2.6, 0.0);
glMultiTexCoord2f(GL_TEXTURE0, 0.0, 1.0);
glMultiTexCoord2f(GL_TEXTURE1, 0.0, 1.0);
glMultiTexCoord2f(GL_TEXTURE2, 0.0, 1.0);
glVertex3f(-0.7, 2.6, 0.0);
glEnd();
glDisable(GL_BLEND);
glActiveTexture (GL_TEXTURE2);
glDisable (GL_TEXTURE_2D);
glActiveTexture (GL_TEXTURE1);
glDisable (GL_TEXTURE_2D);
glActiveTexture (GL_TEXTURE0);
glDisable (GL_TEXTURE_2D);
但我不确定如何使用 glTexEnvi 来获得所需的效果,有什么建议吗?