Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a simple shader to test multitextureing the problem is both samplers are using same image as their reference.

the shader code is basically just this :

vec4 mid = texture2D(u_texture,v_texCoord);
float g = texture2D(u_guide,v_guideCoord);
gl_FragColor = vec4(g , mid.g,0,1);

and this is how I'm calling draw function :

int last_State;
glGetIntegerv(GL_ACTIVE_TEXTURE, &last_State);
glBindTexture(GL_TEXTURE_2D, getTexture()->getName());
glBindTexture(GL_TEXTURE_2D, mGuideTexture->getName());

ccGLEnableVertexAttribs( kCCVertexAttribFlag_TexCoords |kCCVertexAttribFlag_Position);

glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, texCoord);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);


I've already check mGuideTexture->getName() and getTexture()->getName() are returning correct textures. but looking at the result I can tell, both samplers are reading from getTexture()->getName().

here are some screen shots showing what is happening :

  1. The image rendered Using above codes The image rendered Using above codes
  2. The image rendered when I change textures passed to samples The image rendered when I change textures passed to samples

I'm expecting to see green objects from the first picture with red objects hanging from the top.

after testing lots of things I've figured out glUniform1i is not working as expected, Though I'm not sure what is wrong with it. Here is the code:

glUniform1i(textureLocation, GL_TEXTURE0); 
glUniform1i(guideLocation, GL_TEXTURE1); 
share|improve this question
up vote 3 down vote accepted

This is what you're doing wrong:

glUniform1i(textureLocation, GL_TEXTURE0); 
glUniform1i(guideLocation, GL_TEXTURE1); 

Instead of GL_TEXTURE0 and GL_TEXTURE1 you need to give them 0 and 1, like so:

glUniform1i(textureLocation, 0); 
glUniform1i(guideLocation, 1); 

Also, when using shaders you don't need glEnable (GL_TEXTURE_2D), or the corresponding glDisable (GL_TEXTURE_2D) - unrelated to your problem but let's get that right too.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.