I originally wrote a shader program cannot run then I don't see texture and copy online examples of some bosses over still can't see the texture in the heart is very confused to consult:
The following are examples of bosses and no error is texture shows don't come out
Create elven:
Auto Sprite=Sprite: : create (" HelloWorld. PNG ");
If (Sprite==nullptr)
{
ProblemLoading (" 'the HelloWorld. PNG ");
}
The else
{
Sprite - & gt; SetPosition (Vec2 (visibleSize. Width/2 + origin. X, visibleSize. Height/2 + origin. Y));
This - & gt; AddChild (Sprite);
ShaderNode (Sprite);
}
This method is
Void the HelloWorld: : shaderNode (Node * Node)
{
GLProgram * program=GLProgramCache: : getInstance () - & gt; TestShader getGLProgram (" ");
If (the program==nullptr)
{
Program=GLProgram: : createWithFilenames (" test. The vert ", "test. Frag");
GLProgramCache: : getInstance () - & gt; TestShader addGLProgram (program, "");
}
GLProgramState * programState=GLProgramState: : getOrCreateWithGLProgram (program);
ProgramState - & gt; SetUniformVec4 (" u_grayParam Vec4 (0.2 f, f 0.3, 0.5 f, 1.0 f));
Node - & gt; SetGLProgramState (programState);
}
Vertex shader
The attribute vec4 a_position;
The attribute vec2 a_texCoord;
Varying vec2 v_texCoord;
Void main ()
{
Gl_Position=CC_PMatrix * a_position;
V_texCoord=a_texCoord;
}
A fragment shader
Varying vec2 v_texCoord;
Uniform vec4 u_grayParam;
Void main ()
{
Vec4 texColor=texture2D (CC_Texture0 v_texCoord);
TexColor. RGB=texColor. R * u_grayParam. R + texColor. G * u_grayParam in g + texColor. B * u_grayParam. B;
Gl_FragColor=texColor;
}


CodePudding user response:


CodePudding user response:
