OpenGL ES: How to tint texture with color

自古美人都是妖i 提交于 2019-12-01 18:07:56

Have you tried the above code with glEnable(GL_BLEND)?

You might want to read the OpenGL documentation on transparency, 15.020: "How can I achieve a transparent effect?"

Make sure you are rendering the scene in the right order (your answer does not show any rendering).

Make sure you are using the desired blend function.

Another suggestion I could make is to start using shaders. I always feel a bit more in control when I use them.

I get the same results (running on Android Samsung Galaxy S, for what it's worth). I don't understand why it doesn't work. The docs seem reasonably clear.

For me it works if I use GL_MODULATE for the RGB. It fails again if I use GL_ADD or GL_ADD_SIGNED. Even using GL_MODULATE on the alpha gives the same erroneous behaviour when using those modes on the RGB. You might be stuck with modulating your colours instead of interpolating them.

In summary, this works for me:

glActiveTexture (GL_TEXTURE0); // do we need stage #1?
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, (GLfloat*) &tintColor_);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

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