Skip to content Skip to sidebar Skip to footer

Opengl Es 2 : Use An Additional Texture Unit To Blend This Image With The Current One

I am trying to figure out a tutorial on OpenGL ES 2.0 Now the book requires as an exercise to 'Try loading in a different image, and use an additional texture unit to blend this im

Solution 1:

OpenGL ES has the ability to sample 2 or more textures to produce the final gl_FragColor. Your Java code seems to set this up OK, but your fragment shader only uses one of the textures. It should be like this to add two together:

uniform sampler2D u_TextureUnit_0;
uniform sampler2D u_TextureUnit_1;
varying vec2 v_TextureCoordinates;

voidmain()
{
    vec4vColor_0= texture2D(u_TextureUnit_0, v_TextureCoordinates);
    vec4vColor_1= texture2D(u_TextureUnit_1, v_TextureCoordinates);
    gl_FragColor = vColor_0 + vColor_1;  
}

This adds the 2 vec4 color samples together: (R0 + R1, G0 + G1, B0 + B1, A0 + A1)

Post a Comment for "Opengl Es 2 : Use An Additional Texture Unit To Blend This Image With The Current One"