I want to support etc1 in my game, but somehow it doesn't work (I'm using cocos2d-x
C++
GLProgram* glp = new GLProgram();
glp->initWithVertexShaderFilename("testv.vsh", "test.fsh");
glp->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
glp->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
glp->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORD);
glp->link();
glp->updateUniforms();
Texture2D* tex = Director::getInstance()->getTextureCache()->addImage("MenuButton_alpha.pkm");
GL::bindTexture2DN(1, tex->getName());
GLuint t1Location = glGetUniformLocation(glp->getProgram(), "tex1");
glp->setUniformLocationWith1i(t1Location, 1);
MySprite->setShaderProgram(glp);
.vsh
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
varying vec2 v_texCoord2;
uniform sampler2D tex1;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
v_texCoord2 = v_texCoord;
}
.fsh
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
varying vec2 v_texCoord2;
uniform sampler2D tex1;
void main()
{
vec3 tex = texture2D(CC_Texture0, v_texCoord).rgb;
float alpha = texture2D(CC_Texture1, v_texCoord2).a;
gl_FragColor = vec4(tex.rgb,alpha);
}
Somehow it shows my sprite in the middle but the transparent part is black. can anyone help me?