Unknow type name attribute when trying the vertex shader test

Hello,
I started learning about shading in cocos2dx, so this is probably something silly.
I am using one of tests. It is the following .vsh

attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;

#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif

uniform mat4 u_MVPMatrix;

void main()
{
    gl_Position = u_MVPMatrix * a_position;
    v_fragmentColor = a_color;
    v_texCoord = a_texCoord;
}

The problem is that attribute, varying, mat4, etc… is highlighted as an unknow type error.
But if this same code is a .fsh it is fine. Any suggestions?

thx

A .vsh is Vertex Shader, .fsh is Fragment Shader, if you want to set something related to fragment then you should use .fsh, you can use varying to send variable between vsh and fsh.
Which means you should have something like

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

in the vsh accordingly.

hi there,
thanks but I don’t think you are addressing the issue I mentioned, which is why the editor complaining with :unknow type error.

I tried from the tests example_ColorBars.fsh and .vsh

This is the .fsh, no editor complains. All ok

#ifdef GL_ES
precision lowp float;
#endif

varying vec2 v_texCoord;
uniform sampler2D u_texture;

vec4 getColorByCoord(int y){
    if(y < 5){
         if(y == 0){
            return vec4(1,0,0,1);
         } else if(y == 1){
            return vec4(0,1,0,1);
         } else if(y == 2){
            return vec4(0,0,1,1);
         } else if(y == 3){
            return vec4(0,1,1,1);
         } else{
            return vec4(1,0,1,1);
         }
     } else {
         if(y == 5){
            return vec4(1,1,0,1);
         } else if(y == 6){
            return vec4(1,1,1,1);
         } else if(y == 7){
            return vec4(1,0.5,0,1);
         } else if(y == 8){
            return vec4(1,0.5,0.5,1);
         }else {
            return vec4(0.5,0.5,1,1);
         }
     }
}

void main(void) {
	// inline to prevent "float" loss and keep using lowp
    //int y = int( mod(( (gl_FragCoord.y+gl_FragCoord.x)*mod(CC_Time[0],5.0)) / 10.0, 10.0 ) );
	//int y = int( mod( CC_Time[3] + (gl_FragCoord.y + gl_FragCoord.x) / 10.0, 10.0 ) );
	int y = int( mod(gl_FragCoord.y / 10.0, 10.0 ) );
	gl_FragColor = getColorByCoord(y) * texture2D(u_texture, v_texCoord);
}

but with the following .vsh, complains about the error mentioned in the initial post

// http://www.cocos2d-iphone.org

attribute vec4 a_position;
attribute vec2 a_texCoord;

#ifdef GL_ES
varying mediump vec2 v_texCoord;
#else
varying vec2 v_texCoord;
#endif

uniform mat4 u_PMatrix;

void main()
{
    gl_Position = u_PMatrix * a_position;
	v_texCoord = a_texCoord;
}