Hey I want to know how to pass another texture to GLSL?
right know i’m using the following code to use a shader on a sprite where it seems, cocos automatically passes the sprite’s texture to glsl which can be called with CC_Texture0?
But how do i pass another texture?
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();
sprite_->setShaderProgram(glp);
vertex shader:
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
void main()
{
gl_Position = CC_MVPMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}
fragment shader:
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
void main()
{
vec3 pixel = texture2D(CC_Texture0, v_texCoord).rgb;
gl_FragColor = vec4(pixel,0.1);
}
can anyone help me?
it doesn’t work.