OpenGL ES: How to tint texture with color

前端 未结 3 1075
旧时难觅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: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);
    

提交回复
热议问题