title: GLSL for OpenGL ES Android
body: <p>I want to use shading on my OpenGL objects but can't seem to access GLSL functions in my opengl package. Is there a GLSL package available for OpenGL ES in Eclipse?</p>
  
  <p><strong>EDIT</strong>: As Tim pointed out. Shaders are written as text files and then loaded using glShaderSoure, I have a C++ shader file which I had written once for a ray tracing application. But, I am really confused as to how I would go about implementing in java. Suppose I have a 2D square drawn in my <code>Renderer</code> class using a gl object <code>MySquare</code> , how will I go about implementing the java equivalent of the shader file below.</p>
  
  <p><strong>Shader.vert</strong></p>
  
  <pre><code>     varying vec3 N;
       varying vec3 v;
  
  void main()
  {
  
  // Need to transform the normal into eye space.
  N = normalize(gl_NormalMatrix * gl_Normal);
  
  
  // Always have to transform vertex positions so they end
  // up in the right place on the screen.
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  }
  
    // Fragment shader for per-pixel Phong interpolation and shading.
  </code></pre>
  
  <p><strong>Shader.Frag</strong></p>
  
  <pre><code>// The "varying" keyword means that the parameter's value is interpolated
  // between the nearby vertices.
  varying vec3 N;
  varying vec3 v;
  
  //Used for Environmental mapping shader calculations
  const vec3 xUnitVec=vec3(1.0, 0.0, 0.0), yUnitVec=vec3(1.0, 1.0, 0.0);
  uniform vec3 BaseColor, MixRatio;
  uniform sampler2D EnvMap;
  
  
   void main()
  {
      // The scene's ambient light.
      vec4 ambient = gl_LightModel.ambient * gl_FrontMaterial.ambient;
  
  // The normal vectors is generally not normalized after being
  // interpolated across a triangle.  Here we normalize it.
  vec3 Normal = normalize(N);
  
  // Since the vertex is in eye space, the direction to the
  // viewer is simply the normalized vector from v to the
  // origin.
  vec3 Viewer = -normalize(v);
  
  // Get the lighting direction and normalize it.
  vec3 Light  = normalize(gl_LightSource[0].position.xyz);
  
  // Compute halfway vector
  vec3 Half = normalize(Viewer+Light);
  
  // Compute factor to prevent light leakage from below the
  // surface
  float B = 1.0;
  if(dot(Normal, Light)&lt;0.0) B = 0.0;
  
  // Compute geometric terms of diffuse and specular
  float diffuseShade = max(dot(Normal, Light), 0.0);
  float specularShade = 
    B * pow(max(dot(Half, Normal), 0.0), gl_FrontMaterial.shininess);
  
  // Compute product of geometric terms with material and
  // lighting values
  vec4 diffuse = diffuseShade * gl_FrontLightProduct[0].diffuse;
  vec4 specular = specularShade * gl_FrontLightProduct[0].specular;
  ambient += gl_FrontLightProduct[0].ambient;
  
  // Assign final color
  gl_FragColor= ambient + diffuse + specular + gl_FrontMaterial.emission;
  }
  </code></pre>