OpenGL ES: How to tint texture with color

前端 未结 3 1079
旧时难觅i
旧时难觅i 2021-01-19 01:46

I have texture with alpha. And I want to tint it with some color, so it will be colored depending on color alpha value, but overal opacity will be defined only by texture al

相关标签:
3条回答
  • 2021-01-19 02:14

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

    0 讨论(0)
  • 2021-01-19 02:14

    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.

    0 讨论(0)
  • 2021-01-19 02:28

    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);
    
    0 讨论(0)
提交回复
热议问题