title: LWJGL - Attribute names and types being swapped
body: <p>I have a problem that has broken my mind.</p>
  
  <p>I'm working on a little LWJGL engine and am having an issue with shaders. Right now I'm trying to add texturing to one of my test shaders, and it appears as if OpenGL is changing the types and names of input attributes (Or I am an idiot). So far my code looks like so:</p>
  
  <p>Program.java (entrypoint)</p>
  
  <pre><code>program.introspect("vertexPosition");
  program.introspect("vertexNormal");
  program.introspect("vertexTexture");
  </code></pre>
  
  <p>program is of my ShaderProgram type, where the introspect function looks like so:</p>
  
  <pre><code>public void introspect(String name)
  {
      int location = getAttributeLocation(name);
  
      IntBuffer size = BufferUtils.createIntBuffer(1);
      IntBuffer type = BufferUtils.createIntBuffer(1);
      GL20.glGetActiveAttrib(myProgramHandle, location, size, type);
  
      Logger.log(name + " @ " + myDebugName + "." + location);
      Logger.log("\tType: " + ShaderParamType.get(type.get(0)));
      Logger.log("\tSize: " + size.get(0));
  }
  </code></pre>
  
  <p>The vertex shader looks like this (loaded from an XML file):</p>
  
  <pre><code>#version 410 core
  in vec4 vertexPosition;
  in vec3 vertexNormal;
  in vec2 vertexTexture;
  ...
  </code></pre>
  
  <p>And in my log file, I get this:</p>
  
  <pre><code>vertexPosition @ Test.0
      Type: Vector3f
      Size: 1
  vertexNormal @ Test.1
      Type: Vector4f
      Size: 1
  vertexTexture @ Test.2
      Type: Vector2f
      Size: 1
  </code></pre>
  
  <p>As you can see, the types for position and normal are swapped.</p>
  
  <p>ShaderParamType.get is just a function in an enum that uses a switch to get the enum value for the GL value:</p>
  
  <pre><code>switch(value)
  {
      case GL_FLOAT:
          return Float;
      case GL_FLOAT_VEC2:
          return Vector2f;
      case GL_FLOAT_VEC3:
          return Vector3f;
      case GL_FLOAT_VEC4:
          return Vector4f;
      ...
  </code></pre>
  
  <p>Also, even when binding the manually (the way they should show up), I get really funky results: 
  <a href="https://i.stack.imgur.com/dqufN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dqufN.png" alt="Error, vertices are not properly aligned"></a>
  Any help would be greatly appreciated!</p>
  
  <h2>Edit</h2>
  
  <p>So it looks like glGetAttribLocation does not line up to the same location as glGetActiveAttrib does. If I change the logging to log the name as fetched from glGetActiveAttrib, the type is correct but the location is not (even when lcations are declared explicitly in the shader). If I bind the attributes to match those in the logs, I only get one polygon per draw call, even with culling disabled.</p>
  
  <p>Modified introspection:</p>
  
  <pre><code>public int getAttributeLocation(String name) 
      {
          return glGetAttribLocation(myProgramHandle, name);
      }
  
      public void introspect(String name)
      {
          int location = getAttributeLocation(name);
  
          if (location != -1)
          {
              IntBuffer size = BufferUtils.createIntBuffer(2);
              IntBuffer type = BufferUtils.createIntBuffer(2);
              String attName = GL20.glGetActiveAttrib(myProgramHandle, location, size, type);
  
              Logger.log(attName + " @ " + myDebugName + "." + location);
              Logger.log("\tType: %s", ShaderParamType.get(type.get(0)));
  
              Logger.log("\tSize: " + size.get(0));
          }
      }
  </code></pre>
  
  <p>Logs:</p>
  
  <pre><code>vertexNormal @ Test.0
      Type: Vector3f
      Size: 1
  vertexPosition @ Test.1
      Type: Vector4f
      Size: 1
  vertexTexture @ Test.2
      Type: Vector2f
      Size: 1
  </code></pre>
  
  <p>New Pic:
  <a href="https://i.stack.imgur.com/zKiqb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zKiqb.png" alt="enter image description here"></a></p>