title: OpenGL - Uniform not being passed properly?
body: <p>I've got an extremely simple fragment shader:</p>
  
  <pre><code>#version 330 core
  
  // Interpolated values from the vertex shaders
  in vec3 positionW;
  
  // Output data
  out vec3 frag_color;
  
  uniform vec3 alsoLightW;
  
  void main(void) {
      vec3 temp = normalize(alsoLightW);
      frag_color = vec3((temp.x + 1.0) / 2, (temp.y + 1.0) / 2, (temp.z + 1.0) / 2);
  }
  </code></pre>
  
  <p>All it does is normalize a uniform vec3 I've passed to it, and then set my fragment color to it (between 0 and 1 - so a 0 vector would have a color of 0.5, 0.5, 0.5). I print this vector out in my c++ code, and verify that it is passed in properly with renderdoc, however the actual colors that it spits out are consistently wrong - they don't seem to have anything to do with my uniform, but it's always giving me the same color, regardless. For instance, my vec3 is supposed to have a y-coordinate of 0 so I expect a Green value of 0.5, but according to renderdoc, I'm instead getting something around .2</p>
  
  <p>What could be the reason for this? It's been driving me crazy, and is making my much more complicated shader not work at all.</p>
  
  <p>Edit: passing uniform to OpenGL:</p>
  
  <pre><code>ctx.shader-&gt;Enable();
  
  ...
  
  glm::vec3 oppOffset = *Object::globalOffset;
  oppOffset *= -1;
  
  glUniform3fv(lightLocation, 1, glm::value_ptr(oppOffset));
  
  glm::vec3 norm = glm::normalize(oppOffset);
  //Prints the correct information
  std::cout &lt;&lt; (norm.x + 1) / 2 &lt;&lt; "," &lt;&lt; (norm.y + 1) / 2 &lt;&lt; "," &lt;&lt; (norm.z + 1) / 2 &lt;&lt; std::endl;
  </code></pre>
  
  <p>Edit2: I tried passing them as individual floats, and I'm getting the same exact weird numbers as before. <a href="https://i.imgur.com/ThIeGVV.png" rel="nofollow noreferrer">I've uploaded an image of what I mean</a> - the bottom left numbers are the ones I'm getting from cout, and the top right are the ones that RenderDoc are giving me</p>
  
  <p>This is what my uniform passing looks like now:</p>
  
  <pre><code>glm::vec3 norm = glm::normalize(oppOffset);
  norm = (norm + glm::vec3(1.0, 1.0, 1.0)) * glm::vec3(0.5, 0.5, 0.5);
  float x, y, z;
  x = norm.x;
  y = norm.y;
  z = norm.z;
  ctx.shader-&gt;uniform1fv("lightx", 1, &amp;x);
  ctx.shader-&gt;uniform1fv("lighty", 1, &amp;y);
  ctx.shader-&gt;uniform1fv("lightz", 1, &amp;z);
  std::cout &lt;&lt; x &lt;&lt; "," &lt;&lt; y &lt;&lt; "," &lt;&lt; z &lt;&lt; std::endl;
  </code></pre>
  
  <p>And my shader:</p>
  
  <pre><code>#version 330 core
  
  // Interpolated values from the vertex shaders
  in vec3 positionW;
  
  // Output data
  out vec3 frag_color;
  
  uniform float lightx;
  uniform float lighty;
  uniform float lightz;
  
  void main(void) {
      //vec3 temp = normalize(alsoLightW);
      frag_color = vec3(lightx, lighty, lightz);
  }
  </code></pre>
  
  <p>Something very weird is happening...</p>