Rookie
Rookie

Reputation: 3793

How to blend texture colors with simple multiplication to the colors under it?

So i want my texture colors to multiply with the colors under it, how this can be done with glBlendFunc() ?

For example: if i have a texture color (0.31, 0.51, 0.124) and there is a color (0.83, 0.64, 0.12) under it, the resulting color would be 0.31*0.83, 0.51*0.64, 0.124*0.12. How to do this?

Upvotes: 2

Views: 1527

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473212

So i want my texture colors to multiply with the colors under it, how this can be done with glBlendFunc() ?

By "texture colors", I'm going to assume that you mean "the color output by the glTexEnv process". Or, using more rigorous OpenGL spec language, the fragment color.

In any case, this is a simple matter of blending. If you're using OpenGL 2.1 or above:

glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); //No, that's not a typo. Read the wiki article.
glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);

This causes the destination color (what's in the framebuffer) to be multiplied with the source color (what comes out of glTexEnv), and added to zero (technically, zero times the destination color).

Upvotes: 4

Related Questions