title: Error loading vertex shader
body: <p>I'm doing my first steps in OpenGl and computer graphics.
  I found <a href="http://www.cs.unm.edu/~angel/BOOK/INTERACTIVE_COMPUTER_GRAPHICS/SIXTH_EDITION/" rel="nofollow">this book</a> and I'm trying to follow the examples and theory, but when I try to compile the project I got the following error</p>
  
  <pre><code>vertex.glsl failed to compile:
  ERROR: 0:1: '' :  version '150' is not supported
  </code></pre>
  
  <p>The vertex file has this:</p>
  
  <pre><code>#version 150
  
  varying vec4 vPosition;
  
  void main(){
      gl_Position = vPosition;
  }
  </code></pre>
  
  <p>The code I'm trying to execute is:</p>
  
  <pre><code>#include "Angel.h"
  #include &lt;iostream&gt;
  
  const int numPoints = 5000;
  typedef vec2 point2;
  
  void init(){
  
      point2 points[numPoints];
      point2 vertices[3] = {
          point2(-1.0, -1.0), point2(0.0, 1.0), point2(1.0, -1.0)
      };
  
      points[0] = point2(0.25, 0.5);
  
      for (int k = 1; k &lt; numPoints; k++) {
          int j = rand()%3;
          points[k] = (points[k-1]+vertices[j])/2.0;
      }
  
      GLuint program = InitShader("vertex.glsl", "fragment.glsl");
      glUseProgram(program);
  
      GLuint abuffer;
      glGenVertexArraysAPPLE(1, &amp;abuffer);
      glBindVertexArrayAPPLE(abuffer);
  
      GLuint buffer;
      glGenBuffers(1, &amp;buffer);
      glBindBuffer(GL_ARRAY_BUFFER, buffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
  
      GLuint location = glGetAttribLocation(program, "vPosition");
      glEnableVertexAttribArray(location);
      glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
  
      glClearColor(1.0, 1.0, 1.0, 1.0);
  
  }
  
  
  void display(){
      glClear(GL_COLOR_BUFFER_BIT);
      glDrawArrays(GL_POINTS, 0, numPoints);
      glFlush();
  }
  
  int main(int argc, char** argv){
  
      glutInit(&amp;argc, argv);
  
      glutInitDisplayMode(GLUT_RGBA);
  
      glutInitWindowSize(640, 480);
  
      glutCreateWindow("Sierpinski Gasket");
  
      init();
  
      glutDisplayFunc(display);
  
      glutMainLoop();
  
      return 0;
  }
  </code></pre>
  
  <p>I detected that the problem is in the function <code>InitShader("vertex.glsl", "fragment.glsl");</code> which is this:</p>
  
  <pre><code>#include "Angel.h"
  
  namespace Angel {
  
      // Create a NULL-terminated string by reading the provided file
      static char*
      readShaderSource(const char* shaderFile)
      {
          FILE* fp = fopen(shaderFile, "r");
  
          if ( fp == NULL ) { return NULL; }
  
          fseek(fp, 0L, SEEK_END);
          long size = ftell(fp);
  
          fseek(fp, 0L, SEEK_SET);
          char* buf = new char[size + 1];
          fread(buf, 1, size, fp);
  
          buf[size] = '\0';
          fclose(fp);
  
          return buf;
      }
  
  
      // Create a GLSL program object from vertex and fragment shader files
      GLuint
      InitShader(const char* vShaderFile, const char* fShaderFile)
      {
          struct Shader {
              const char*  filename;
              GLenum       type;
              GLchar*      source;
          }  shaders[2] = {
              { vShaderFile, GL_VERTEX_SHADER, NULL },
              { fShaderFile, GL_FRAGMENT_SHADER, NULL }
          };
  
          GLuint program = glCreateProgram();
  
          for ( int i = 0; i &lt; 2; ++i ) {
              Shader&amp; s = shaders[i];
              s.source = readShaderSource( s.filename );
              if ( shaders[i].source == NULL ) {
                  std::cerr &lt;&lt; "Failed to read " &lt;&lt; s.filename &lt;&lt; std::endl;
                  exit( EXIT_FAILURE );
              }
  
              GLuint shader = glCreateShader( s.type );
              glShaderSource( shader, 1, (const GLchar**) &amp;s.source, NULL );
              glCompileShader( shader );
  
              GLint  compiled;
              glGetShaderiv( shader, GL_COMPILE_STATUS, &amp;compiled );
              if ( !compiled ) {
                  std::cerr &lt;&lt; s.filename &lt;&lt; " failed to compile:" &lt;&lt; std::endl;
                  GLint  logSize;
                  glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &amp;logSize );
                  char* logMsg = new char[logSize];
                  glGetShaderInfoLog( shader, logSize, NULL, logMsg );
                  std::cerr &lt;&lt; logMsg &lt;&lt; std::endl;
                  delete [] logMsg;
  
                  exit( EXIT_FAILURE );
              }
  
              delete [] s.source;
  
              glAttachShader( program, shader );
          }
  
          /* link  and error check */
          glLinkProgram(program);
  
          GLint  linked;
          glGetProgramiv( program, GL_LINK_STATUS, &amp;linked );
          if ( !linked ) {
              std::cerr &lt;&lt; "Shader program failed to link" &lt;&lt; std::endl;
              GLint  logSize;
              glGetProgramiv( program, GL_INFO_LOG_LENGTH, &amp;logSize);
              char* logMsg = new char[logSize];
              glGetProgramInfoLog( program, logSize, NULL, logMsg );
              std::cerr &lt;&lt; logMsg &lt;&lt; std::endl;
              delete [] logMsg;
  
              exit( EXIT_FAILURE );
          }
  
          /* use program object */
          glUseProgram(program);
  
          return program;
      }
  
  }  // Close namespace Angel block
  </code></pre>
  
  <p>The whole source code can be found in the link of the book.
  What's this problem about? I don't know anything about shaders and I'm just trying to make this app work.
  I'm doing this on a Mac with OS X 10.8, Xcode 4.5</p>