title: OpenGL Shader error 1282
body: <p>I am trying to add lighting to my current scene of a simple cube. After setting up my uniforms I get a 1282 error from glGetError() for this piece of code</p>
  
  <pre><code>GLuint ambientHandle = glGetUniformLocation(program-&gt;getHandle(), "ambientProduct");
  glUniform4fv( ambientHandle, 1, ambientProduct );
  GLuint diffuseHandle = glGetUniformLocation(program-&gt;getHandle(), "diffuseProduct");
  glUniform4fv( diffuseHandle, 1, diffuseProduct );
  GLuint specularHandle = glGetUniformLocation(program-&gt;getHandle(), "specularProduct");
  glUniform4fv( specularHandle, 1, specularProduct );
  GLuint lightPosHandle = glGetUniformLocation(program-&gt;getHandle(), "lightPosition");
  glUniform4fv( lightPosHandle, 1, light.position );
  GLuint shinyHandle = glGetUniformLocation(program-&gt;getHandle(), "shininess");
  glUniform1f( shinyHandle, materialShininess );
  </code></pre>
  
  <p>Here are my shaders:
  vertex.glsl</p>
  
  <pre><code>#version 120
  
  attribute vec4 coord3d;
  attribute vec3 normal3d;
  
  // output values that will be interpretated per-fragment
  varying  vec3 fN;
  varying  vec3 fE;
  varying  vec3 fL;
  
  uniform vec4 lightPosition;
  uniform mat4 mTransform;
  
  void main()
  {
      fN = normal3d;
      fE = coord3d.xyz;
      fL = lightPosition.xyz;
  
      if( lightPosition.w != 0.0 ) {
      fL = lightPosition.xyz - coord3d.xyz;
      }
  
      gl_Position = mTransform*coord3d;
  }
  </code></pre>
  
  <p>fragment.glsl</p>
  
  <pre><code>// per-fragment interpolated values from the vertex shader
  varying  vec3 fN;
  varying  vec3 fL;
  varying  vec3 fE;
  
  uniform vec4 ambientProduct, diffuseProduct, specularProduct;
  uniform mat4 mTransform;
  uniform vec4 lightPosition;
  uniform float shininess;
  
  void main() 
  { 
      // Normalize the input lighting vectors
      vec3 N = normalize(fN);
      vec3 E = normalize(fE);
      vec3 L = normalize(fL);
  
      vec3 H = normalize( L + E );
  
      vec4 ambient = ambientProduct;
  
      float Kd = max(dot(L, N), 0.0);
      vec4 diffuse = Kd*diffuseProduct;
  
      float Ks = pow(max(dot(N, H), 0.0), shininess);
      vec4 specular = Ks*specularProduct;
  
      // discard the specular highlight if the light's behind the vertex
      if( dot(L, N) &lt; 0.0 ) {
      specular = vec4(0.0, 0.0, 0.0, 1.0);
      }
  
      gl_FragColor = ambient + diffuse + specular;
      gl_FragColor.a = 1.0;
  } 
  </code></pre>
  
  <p>The products and position are each a struct of three GLfloats and shininess is a float. I have checked all of the values of the handles and the values I am passing and they all seem valid. Ideas?</p>
  
  <p>--EDIT:
  I have narrowed it to the glUniform4fv calls. It happens after each one. Also I have double checked that the program->getHandle() is pointing to something that looks valid.</p>
  
  <p>I have checked program->getHandle is a valid program
  Here are the values of all handles:
  Program handle 3
  ambientHandle 0
  diffuseHandle 1
  specularHandle 5
  lightPosHandle 2
  shinyHandle 4</p>
  
  <p>So they all look good. For testing I am commenting out the lines below the ones for ambientProduct. For clarity I am explicitly using this line instead</p>
  
  <pre><code>glUniform4f( ambientHandle, ambientProd.x, ambientProd.y, ambientProd.z, ambientProd.w );
  </code></pre>
  
  <p>These are the values for ambientProd at the time that line is executed. 
  x = 0.200000003, y = 0.0, z = 0.200000003, w = 1.0</p>
  
  <p>A collaborator on this project moved the call for glUseProgram. Thanks for the help folks.</p>