我关注此链接: http://sbcgamesdev.blogspot.in/2013/06/etc1-textures-loading-and-alpha.html
我有两个纹理,SpinWheel-hd.pkm(rgb)和SpinWheel1-hd.pkm(alpha)。我正在尝试使用alpha加载ETC1纹理。 结果图像变白,根据链接,它应该是我的rgb纹理与alpha。我究竟做错了什么?我正在使用cocos2dx 2.2.5
这是我的加载代码:
rgbTex = CCTextureCache::sharedTextureCache()->addETCImage("SpinWheel-hd.pkm");
MainScreen1 = CCSprite::create("SpinWheel-hd.pkm");
CCSize size1 = CCDirector::sharedDirector()->getWinSize();
MainScreen1->setPosition(ccp(size1.width/2+70, size1.height/2+70));
this->addChild(MainScreen1);
alphaTex = CCTextureCache::sharedTextureCache()->addETCImage("SpinWheel1-hd.pkm");
alphaTex->setAliasTexParameters();
CCGLProgram *shader = CCShaderCache::sharedShaderCache()->programForKey("monochromeShader");
shader->reset();
/ // Same code as before to initialize the shader
shader->initWithVertexShaderByteArray(cc_MonoChromeV, cc_MonoChrome);
MainScreen1->setShaderProgram(shader);
MainScreen1->getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
MainScreen1->getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
MainScreen1->getShaderProgram()->link();
MainScreen1->getShaderProgram()->updateUniforms();
_maskLocation = glGetUniformLocation( MainScreen1->getShaderProgram()->getProgram(),"u_colorRampTexture");
glUniform1i(_maskLocation,1);
_textureLocation = glGetUniformLocation( MainScreen1->getShaderProgram()->getProgram(),"u_texture");
glUniform1i(_textureLocation, 0);
MainScreen1->getShaderProgram()->use();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, rgbTex->getName());
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,alphaTex->getName());
glActiveTexture(GL_TEXTURE0);
这是我的片段着色器
"\n\
#ifdef GL_ES \n\
precision mediump float;\n\
#endif\n\
uniform sampler2D u_texture;\n\
uniform sampler2D u_colorRampTexture;\n\
varying mediump vec2 v_texture;\n\
void main(void)\n\
{\n\
gl_FragColor = vec4(texture2D(u_texture, v_texture).rgb, texture2D(u_colorRampTexture, v_texture).r);\n\
}\n\
";
这是我的顶点着色器:
"\n\
attribute vec4 a_position; \n\
attribute mediump vec2 a_texture;\n\
\n\
#ifdef GL_ES\n\
varying mediump vec2 v_texture;\n\
#else \n\
varying vec2 v_texture; \n\
#endif \n\
\n\
void main(void)\n\
{\n\
gl_Position = CC_MVPMatrix * a_position;\n\
v_texture = a_texture;\n\
}\n\
";
我哪里错了?我所看到的只是纯白色的图像。