title: OpenGL Vertices not drawn
body: <p>I'm trying the whole day to get OpenGL to work in Java (with LWJGL 3/GLFW). The problem is that besides the clear color, I don't see anything drawn.</p>
  
  <p><strong>Question:</strong> </p>
  
  <ol>
  <li>Is the order of my OpenGL Function calls ok? </li>
  <li>Are there any mistakes
  that prevents the vertices from being drawn?</li>
  </ol>
  
  <p>This is the order of OpenGL calls, besides the initialization. The complete program can be found here <a href="http://pastebin.com/JWJ7pqBs" rel="nofollow">http://pastebin.com/JWJ7pqBs</a> and is derived from the LWJGL 3 "Getting Started"-Example to skip the initialization part.</p>
  
  <p><strong>EDIT:</strong> Corrected some mistakes as stated by <code>derhass</code>. But still no visible output. <a href="http://pastebin.com/FbkuusM3" rel="nofollow">http://pastebin.com/FbkuusM3</a></p>
  
  <p><strong>EDIT2:</strong> Tried with fixed color in fragment-shader, but no vertices drawn.</p>
  
  <p>Variables:</p>
  
  <pre><code>int shader;
  int vao;
  int vbo;
  </code></pre>
  
  <p>Create Shader (once):</p>
  
  <pre><code>    String dummyVertexShaderSrc =
                  "#version 330 core"
                  + "\n" + "layout(location = 0) in vec3 vs_position;"
                  + "\n" + "layout(location = 1) in vec4 vs_color;"
                  + "\n" + ""
                  + "\n" + "out vec4 fs_color;"
                  + "\n" + ""
                  + "\n" + "void main() {"
                  + "\n" + "    gl_Position = vec4(vs_position, 1.0);"
                  + "\n" + "    fs_color = vs_color;"
                  + "\n" + "}"
                  ;
  
          String dummyFragmentShaderSrc = "#version 330 core"
                  + "\n" + "in vec4 fs_color;"
                  + "\n" + "void main() {"
                  + "\n" + "    gl_FragColor = fs_color;"
                  + "\n" + "}";
  
          System.out.println("Vertex-Shader: \n" + dummyVertexShaderSrc + "\n");
          System.out.println("Fragment-Shader: \n" + dummyFragmentShaderSrc + "\n");
  
          // 1# Read/Compile VertexShader
          int idVertexShader = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
          GL20.glShaderSource(idVertexShader, dummyVertexShaderSrc);
          GL20.glCompileShader(idVertexShader);
  
          if (GL20.glGetShaderi(idVertexShader, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
              System.err.println("Could not compile vertex shader: " + GL20.glGetShaderInfoLog(idVertexShader));
              System.exit(-1);
          }
  
          // 2# Read/Compile FragmentShader
          int idFragmentShader = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);
          GL20.glShaderSource(idFragmentShader, dummyFragmentShaderSrc);
          GL20.glCompileShader(idFragmentShader);
  
          if (GL20.glGetShaderi(idFragmentShader, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
              System.err.println("Could not compile fragment shader: " + GL20.glGetShaderInfoLog(idFragmentShader));
              System.exit(-1);
          }
  
          // 3# Create Shader-Program
          shader = GL20.glCreateProgram();
          GL20.glAttachShader(shader, idVertexShader);
          GL20.glAttachShader(shader, idFragmentShader);
  
          GL20.glBindAttribLocation(shader, 0, "vs_position");
          GL20.glBindAttribLocation(shader, 1, "vs_color");
  
          GL20.glLinkProgram(shader);
          if (GL20.glGetProgrami(shader, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
              System.out.println("Shader linking failed: " + GL20.glGetProgramInfoLog(shader));
              System.exit(-1);
          }
  
          GL20.glValidateProgram(shader);
          GL20.glDeleteShader(idVertexShader);
          GL20.glDeleteShader(idFragmentShader);
  </code></pre>
  
  <p>Create VAO/VBO (once):</p>
  
  <pre><code>        vao = GL30.glGenVertexArrays();
          GL30.glBindVertexArray(vao);
  
              vbo = GL15.glGenBuffers();
              GL15.glBindBuffer( GL15.GL_ARRAY_BUFFER, vbo);
              GL15.glBufferData( GL15.GL_ARRAY_BUFFER, 1024 * Vertex.ByteSize, null, GL15.GL_STREAM_DRAW );
  
              GL20.glEnableVertexAttribArray(0);
              GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
  
              GL20.glEnableVertexAttribArray(1);
              GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, 0, 3);
  
              GL20.glDisableVertexAttribArray(0);
              GL20.glDisableVertexAttribArray(1);
  
              GL15.glBindBuffer( GL15.GL_ARRAY_BUFFER, 0);
  
          GL30.glBindVertexArray(0);  
  </code></pre>
  
  <p>Fill the VAO/VBO with data (once):</p>
  
  <pre><code>    Vertex[] vertices = new Vertex[] {
                  new Vertex(new Vector3f(-1.0f, -1.0f, 0.0f), new Color4f(0.5f, 0.5f, 0.5f, 0.5f), Vector2f.Zero),
                  new Vertex(new Vector3f( 1.0f, -1.0f, 0.0f), new Color4f(0.5f, 0.5f, 0.5f, 0.5f), Vector2f.Zero),
                  new Vertex(new Vector3f( 0.0f,  1.0f, 0.0f), new Color4f(0.5f, 0.5f, 0.5f, 0.5f), Vector2f.Zero),
          };
  
          // 1# Create buffer
          FloatBuffer buffer = ByteBuffer.allocateDirect(3 * 7 * Float.BYTES).asFloatBuffer();
          buffer.position(0);
          for(Vertex vertex : vertices) {
              buffer.put(vertex.position.x);
              buffer.put(vertex.position.y);
              buffer.put(vertex.position.z);
              buffer.put(vertex.color.r);
              buffer.put(vertex.color.g);
              buffer.put(vertex.color.b);
              buffer.put(vertex.color.a);
          }
  
          // 2# Write data
          GL30.glBindVertexArray(vao);
  
              GL15.glBindBuffer( GL15.GL_ARRAY_BUFFER, vbo);
              GL15.glBufferSubData( GL15.GL_ARRAY_BUFFER, 3 * 7, buffer);
              GL15.glBindBuffer( GL15.GL_ARRAY_BUFFER, 0);
  
          GL30.glBindVertexArray(0);
  </code></pre>
  
  <p>And finally in the main loop draw the vertices (multiple times):</p>
  
  <pre><code>        GL20.glUseProgram(shader);
          GL30.glBindVertexArray( vao );
          GL20.glEnableVertexAttribArray(0);
          GL20.glEnableVertexAttribArray(1);
  
          GL11.glDrawArrays( GL11.GL_TRIANGLES, 0, 3 );
  
          GL20.glDisableVertexAttribArray(1);
          GL20.glDisableVertexAttribArray(0);
          GL30.glBindVertexArray( 0 );
          GL20.glUseProgram(0);
  </code></pre>