GLchar* pszFragSource =
“#ifdef GL_ES \n
precision mediump float; \n
#endif \n
uniform sampler2D u_texture; \n
varying vec2 v_texCoord; \n
varying vec4 v_fragmentColor; \n
void main(void) \n
{ \n
// Convert to greyscale using NTSC weightings \n
vec4 col = texture2D(u_texture, v_texCoord); \n
float grey = dot(col.rgb, vec3(0.299, 0.587, 0.114)); \n
gl_FragColor = vec4(grey, grey, grey, col.a); \n
}”;
/CCGLProgram pProgram = new CCGLProgram();
pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_noMVP_vert, pszFragSource);*/
CCGLProgram* pProgram = CCGLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, pszFragSource);
pProgram->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
pProgram->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
pProgram->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
iconImg->getVirtualRenderer()->setShaderProgram(pProgram);
pProgram = iconImg->getVirtualRenderer()->getShaderProgram();
CHECK_GL_ERROR_DEBUG();
pProgram->link();
pProgram->updateUniforms();
CHECK_GL_ERROR_DEBUG();
疑问:
为什么这样写显示不出来图,
把蓝色部分注释掉,用红色部分shader就正常?