title: How can I pass the vertices position to my vertex shader. I wrote a shader that is not drawing anything to the screen
body: <p>I wrote a shader program that is not drawing anything to the screen, I think it's because I may be missed something, I don't know how to pass the vertices position to it.</p>
  
  <p>My vertex shader is:</p>
  
  <pre><code>#version 130
  
  in vec2 vertexPosition;
  
  void main()
  {
      gl_Position.xy=vertexPosition;
      gl_Position.z=-1.0;
      gl_Position.w=1.0;
  }
  </code></pre>
  
  <p>My fragment shader is:</p>
  
  <pre><code>#version 130
  
  out vec3 color;
  
  void main()
  {
      color=vec3(1.0,0.0,0.0);
  }
  </code></pre>
  
  <p>this is the code:</p>
  
  <pre><code> GLfloat triangle []
      {
          200,200,
          400,200,
          400,400
      };
      //translating the coordinates
      glViewport(0,0,640,480);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0,640,0,480,0,1);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
  
  
      GLuint triangleBufferID;//store the identifier of this buffer
      glGenBuffers(1, &amp;triangleBufferID);
      glBindBuffer(GL_ARRAY_BUFFER, triangleBufferID); 
      glBufferData(GL_ARRAY_BUFFER, sizeof(triangle), triangle, GL_STATIC_DRAW); //describe the data in the buffer
      glEnableVertexAttribArray(0); //enable the buffer
      glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); //Get the pointer for the buffer.
  
      //SECOND SHADER TYPE (READ FROM FILE):
      const GLchar* vertexshaderPath = "vertexshader.vsh";
      const GLchar* fragmentshaderPath = "fragmentshader.fsh";
      string vertexshaderSource = ""; //getting a string to store the source code of vertexshader.vsh
      string fragmentshaderSource = ""; //getting a string to store the source code of fragmentshader.fsh
      ifstream vertexfile; //getting a file pointer for vertexshader.vsh;
      ifstream fragmentfile; //getting a file pointer for fragmentshader.fsh;
      vertexfile.exceptions (ifstream::badbit); //add exceptions to the file pointer;
      fragmentfile.exceptions (ifstream::badbit); //add exceptions to the file pointer;
      try 
      {
          vertexfile.open(vertexshaderPath); //open vertexshader.vsh
          fragmentfile.open(fragmentshaderPath); //open fragmentshader.fsh
          stringstream vfstream, ffstream; //get two stringstream object;
          vfstream &lt;&lt; vertexfile.rdbuf(); //get the content of vertexshader.vsh into a stringstream;
          ffstream &lt;&lt; fragmentfile.rdbuf(); //get the content of fragmentshader.fsh into a stringstream;
          vertexfile.close(); //close the file;
          fragmentfile.close(); //close the file;
          vertexshaderSource=vfstream.str(); //copy the string from stringstream into vertexshaderSource;
          fragmentshaderSource=ffstream.str(); //copy the string from stringstream into fragmentshaderSource;
      }
      catch (ifstream::failure e) //if failure caught...
      {
          cout &lt;&lt; "Error, file is unreadable!" &lt;&lt; endl;
      }
      const GLchar* vscode = vertexshaderSource.c_str();
      //converted into c_str();
      const GLchar* fscode = fragmentshaderSource.c_str(); 
      //converted into c_str();
  
      //THIS PART FOR ALL WAYS:
      GLuint vertexshaderID=glCreateShader(GL_VERTEX_SHADER); //create a shader
      glShaderSource(vertexshaderID,1,&amp;vscode,nullptr);
      glCompileShader(vertexshaderID); //compile shader;
      GLint success;
      GLchar infolog[512];
      glGetShaderiv(vertexshaderID, GL_COMPILE_STATUS, &amp;success);
      if(!success) //check the compilation results
      {
          glGetShaderInfoLog(vertexshaderID,512,0,infolog);
          cout &lt;&lt; "Error vertex shader's compilation failed" &lt;&lt; endl;
          cout &lt;&lt; infolog &lt;&lt; endl;
      }
      GLuint fragmentshaderID=glCreateShader(GL_FRAGMENT_SHADER); //create a shader
      glShaderSource(fragmentshaderID,1,&amp;fscode, nullptr);
      glCompileShader(fragmentshaderID); //compile shader
      glGetShaderiv(fragmentshaderID,GL_COMPILE_STATUS,&amp;success);
      if(!success) //check the compilation results
      {
          glGetShaderInfoLog(fragmentshaderID,512,0,infolog);
          cout &lt;&lt; "Error fragment shader's compilation failed" &lt;&lt; endl;
          cout &lt;&lt; infolog &lt;&lt; endl;
      }
      GLuint programID = glCreateProgram(); //create a program;
      glAttachShader(programID, vertexshaderID); //attach vertexshader to the program;
      glAttachShader(programID, fragmentshaderID); //attach fragmentshader to the program;
  
      glBindAttribLocation(programID, 0, "vertexPosition");
      glUniform3f(glGetUniformLocation(programID, "color"),1.0,0.0,0.0);
  
      glLinkProgram(programID); //link the pieces of the program;
      glGetProgramiv(programID, GL_LINK_STATUS, &amp;success);
      if(!success) //check the link status;
      {
          glGetProgramInfoLog(programID,512,0,infolog);
          cout &lt;&lt; "Error linking the program" &lt;&lt; endl;
          cout &lt;&lt; infolog &lt;&lt; endl;
      }
    //  glDeleteShader(vertexshaderID);
  //    glDeleteShader(fragmentshaderID);
  
      glUseProgram(programID); //use the program;
      glDrawArrays(GL_TRIANGLES, 0, 3);
      SDL_GL_SwapWindow(window);
  </code></pre>