Hi I am trying to pass 2 textures to a shader and I am a little confused about the working here
This is the opengl code
Code :GLuint textures; GLuint textures1; glGenTextures(1,&textures); glGenTextures(1,&textures1); glBindTexture(GL_TEXTURE_2D,textures); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,texImg); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glBindTexture(GL_TEXTURE_2D,textures1); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,texImg1); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glBindTexture(GL_TEXTURE_2D,textures1); GLuint location1=glGetUniformLocationARB(programObjectFloor,"Tex1"); GLuint location2=glGetUniformLocationARB(programObjectFloor,"Tex2"); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,textures); glUniform1i(location1, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,textures1); glUniform1i(location2, 1);
the vertex shader is
Code :attribute vec4 position; attribute vec4 texture; uniform mat4 MVP; varying vec4 ptexture; void main() { ptexture = texture; gl_Position = MVP * position; }
the fragment shader is
Code :varying vec4 ptexture; uniform sampler2D Tex1; uniform sampler2D Tex2; uniform bool swit; void main() { gl_FragColor = texture2D(Tex1,ptexture.st); }
In my fragment shader, when I change my code to the below, still only the first texture is displayed.
Code :varying vec4 ptexture; uniform sampler2D Tex1; uniform sampler2D Tex2; uniform bool swit; void main() { gl_FragColor = texture2D(Tex2,ptexture.st); }
But when I comment out the opengl code as shown below, the second texture is shown
Code :glGenTextures(1,&textures); glGenTextures(1,&textures1); glBindTexture(GL_TEXTURE_2D,textures); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,texImg); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glBindTexture(GL_TEXTURE_2D,textures1); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,texImg1); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glBindTexture(GL_TEXTURE_2D,textures1); GLuint location1=glGetUniformLocationARB(programObjectFloor,"Tex1"); GLuint location2=glGetUniformLocationARB(programObjectFloor,"Tex2"); // glActiveTexture(GL_TEXTURE0); // glBindTexture(GL_TEXTURE_2D,textures); // glUniform1i(location1, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,textures1); glUniform1i(location2, 1);
this line below in the fragment shader does not affect the rendering in anyway
i can mention Tex1 or Tex2 and it still displays some texture, I am totally confused, it would be great if someone could explain what is happening.Code :gl_FragColor = texture2D(Tex2,ptexture.st);
Thanks!!



its fixed now, Changed it to, but there is no change in the output of the program.
