Android shader problem


I’m new to using OpenGL ES2.0 on Android but I have a basic 2d game working with simple shaders.

I’m having a nightmare trying to modify a simple fragment shader. If I try and re-assign a variable the shader stops working or does something strange. All the example shaders I have found on the internet re-assign variables.

my fragment shader is like this:

precision mediump float;
  varying vec2 v_texCoord;
  uniform sampler2D s_texture;

  vec4 test = vec4(0.0, 0.0, 1.0, 0.5);

  vec2 test2 = vec2(0.0,0.0);    // this variable is not used but shader still works OK
 // re-assigning a variable stops the shader working, nothing is rendered
  test2 = vec2(0.0, 0.0);       // if I comment this line out the shader works OK again

  void main() {
    gl_FragColor = texture2D( s_texture, v_texCoord ) * test ;

Any ideas why the line

test2 = vec2(0.0, 0.0); 

should stop the shader working.

I have also tried

vec2 test2;
test2 = vec2(0.0, 0.0); 

but that doesn’t work either.

I can only assign a variable value when the variable is declared.

Any help or suggestions would be appreciated.

the first thing i would try is to check wheater there are any compilation / linking errors
the second thing would be to check wheater there are any other OpenGL errors

there are 2 things:
the “;” after the main function isnt necessary
the re-assigning of a variable belongs into the main function

the re-assigning of a variable belongs into the main function[/QUOTE]

That was my problem. Strange thing is the shader above worked OK on just one Android device but not any others.

Thank you for your quick reply.