cocos2d/OpenGL multitexturing problem

Posted by Gajoo on Game Development See other posts from Game Development or by Gajoo
Published on 2012-10-18T00:25:06Z Indexed on 2012/10/18 5:24 UTC
Read the original article Hit count: 257

Filed under:
|
|

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);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, getTexture()->getName());
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
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);

glDisable(GL_TEXTURE_2D);

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.

© Game Development or respective owner

Related posts about opengl-es

Related posts about cocos2d