title: Triangles not being drawn on screen openGL even when no error is occurred
body: <p>I have written a simple openGL program to draw a triangle on the screen. I have done debugging with <strong>glGetError()</strong> and now there is no error in the code but when I try to run it only a black screen comes up.</p>
  
  <p>here is my code. I am using GLFW for window creation.</p>
  
  <pre><code>#include&lt;glew.h&gt;
  #include&lt;glfw3.h&gt;
  #include&lt;stdio.h&gt;
  
  int main(int argc, char ** argv)
  {
      glfwInit();
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
      glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  
      GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", nullptr,           nullptr);
      glfwMakeContextCurrent(window);
  
      glewExperimental = GL_TRUE;
      glewInit();
  
      float vertices[] = {
          0.0f, 0.5f,
          0.5f, -0.5f,
         -0.5f, -0.5f
      };
      GLuint vao;
      glGenVertexArrays(1, &amp;vao);
      glBindVertexArray(vao);
      GLuint vbo;
      glGenBuffers(1, &amp;vbo);
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
  
      const  GLchar * vs =
          "#version 150\n"
          "in vec2 position;\n"
          "void main() {\n"
          "vec4 gl_Position = vec4( position , 0.0 , 1.0 );\n"
          "}";
  
      const GLchar * fs =
           "#version 150\n"
           "out vec4 out_color; \n"
           "void main() { \n"
           "out_color = vec4(1.0, 1.0, 1.0, 1.0);\n"
           "}";
  
      GLuint vsh = glCreateShader(GL_VERTEX_SHADER);
      glShaderSource(vsh, 1, &amp;vs, NULL);
      glCompileShader(vsh);
      GLint status;
      glGetShaderiv(vsh, GL_COMPILE_STATUS, &amp;status);
      if (status == GL_TRUE) printf("Vertex Shader Compiled success\n");
  
      GLuint fsh = glCreateShader(GL_FRAGMENT_SHADER);
      glShaderSource(fsh, 1, &amp;fs, NULL);
      glCompileShader(fsh);
      glGetShaderiv(fsh, GL_COMPILE_STATUS, &amp;status);
      if (status == GL_TRUE) printf("Fragment Shader Compiled success\n");
  
      GLuint sp = glCreateProgram();
      glAttachShader(sp, vsh);
      glAttachShader(sp, fsh);
      glBindFragDataLocation(sp, 0, "out_color");
      glBindAttribLocation(sp,1,"position");
      glLinkProgram(sp);
      glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
      glEnableVertexAttribArray(1);
  
      glUseProgram(sp);
  
      while (!glfwWindowShouldClose(window))
      {
          glClear(GL_COLOR_BUFFER_BIT);
          glDrawArrays(GL_TRIANGLES, 0, 3);
          glfwSwapBuffers(window);
          glfwPollEvents();
      }
      glfwTerminate();
      return 0;    
  } 
  </code></pre>
  
  <p><strong>Update</strong>
  I have narrowed down the issue to just one line of code</p>
  
  <pre><code> GLint pos = glGetAttribLocation(sp, "position") //sp is shader program
  </code></pre>
  
  <p>The problem is it is returning -1. I have read in tutorials that if you don't use a variable it will be optimized out by the compiler.I have used the <strong>position</strong> in the code then why it is getting thrown away. Below is my vertex shader.</p>
  
  <pre><code>const  GLchar * vs =
          "#version 150\n"
          "in vec2 position;\n"
          "void main() {\n"
          "vec4 gl_Position = vec4( position , 0.0 , 1.0 );\n"
          "}";
  </code></pre>