How can I access the different teture unit in this shader.
addUniform(cube,“tex1”,0);
works as expected but not when I try to use texture unit 1.
I Have tried
gl_FragData[2] = texture2D(tex1, gl_TexCoord[1].st);
and
gl_TexCoord[0] = gl_MultiTexCoord0+1;
without result.
I have a multi texture shader that seems to work. Can someone please explain how to access texture unit ‘i’ in my shader for single textures.
1 #extension GL_ARB_draw_buffers : enable
2
3 varying vec3 position, normal;
4 uniform sampler2D tex1,tex2;
5
6
7 void main(void) {
8 gl_FragData[0] = vec4(position.xyz, 0.0);
9 gl_FragData[1] = vec4(normalize(normal.xyz), 0.0);
10 gl_FragData[2] = texture2D(tex1, gl_TexCoord[0].st) +
11 texture2D(tex2,gl_TexCoord[0].st);
12 }
This is code that ads the uniforms and the shader source.
56 addProgram(cube, "./shaders/single.vert", "./shaders/single.frag");
57 addUniform(cube,"tex1",1);
56 addProgram(cube, "./shaders/single.vert", "./shaders/single.frag");
57 addUniform(cube,"tex1",0);
1 #extension GL_ARB_draw_buffers : enable
2
3 varying vec3 position, normal;
4 uniform sampler2D tex1;
5
6
7 void main(void) {
8 gl_FragData[0] = vec4(position.xyz, 0.0);
9 gl_FragData[1] = vec4(normalize(normal.xyz), 0.0);
10 gl_FragData[2] = texture2D(tex1, gl_TexCoord[0].st);
11 }
~
1 varying vec3 position, normal;
2
3 void main(void) {
4 position = vec3(gl_ModelViewMatrix * gl_Vertex);
5 normal = gl_NormalMatrix * gl_Normal;
6 gl_Position = ftransform();
7 gl_TexCoord[0] = gl_MultiTexCoord0;
8 }