title: Getting GLSL 1.5 to work on Mac OS X
body: <p>I'm trying to create my own vertex and fragment shaders in my program (which is basically a very simple program that displays a triangle with VBO).  However, when I try run it, I always get a black screen with nothing showing up.  I've checked the compile log and it returns with no error.  I have yet to run a program with my own custom shader which makes me wonder if I'm doing anything wrong here.  I'm running my code on OpenGL 3.2 and GLSL 1.5</p>
  
  <p>The following is the code that I'm trying to run currently</p>
  
  <pre><code>
  GLuint vbo;
  
  GLfloat data[] = {0.0, 0.0, -5.0,
                    1.0, 0.0, -5.0,
                    1.0, 1.0, -5.0
  };
  
  const char *vertexShader = "\n\
  #version 150\n\
  \n\
  layout (location=0) in vec4 position;\n\
  void main()\n\
  {\n\
  gl_Position = position;\n\
  }\n\
  ";
  
  const char *fragmentShader = "\n\
  #version 150\n\
  \n\
  out vec4 outColor;\n\
  \n\
  void main()\n\
  {\n\
      outColor = vec4(1.0, 0.0, 0.0, 1.0);\n\
  }";
  
  
  - (void)drawRect:(NSRect)dirtyRect
  {
      glClear(GL_COLOR_BUFFER_BIT);
  
      glMatrixMode(GL_MODELVIEW);
  
      glLoadIdentity();
  
      glUseProgram(programId);
  
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      glEnableVertexAttribArray(0);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
  
      glEnableClientState(GL_VERTEX_ARRAY);
  
      glVertexPointer(3, GL_FLOAT, 0, 0);
  
      glDrawArrays(GL_TRIANGLES, 0, sizeof(data));
  
      glFlush();
  
  
      glDisableClientState(GL_VERTEX_ARRAY);
  
  }
  
  -(void)reshape
  {
      glViewport(0, 0, w, h);
      gluPerspective(45.0,                  //The camera angle
                     (double)w / (double)h, //The width-to-height ratio
                     1.0,                   //The near z clipping coordinate
                     200.0); 
  }
  
  -(void)prepareOpenGL
  {
      glEnable(GL_DEPTH_TEST);  
  
      glGenBuffersARB(1, &vbo);
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
      glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW);
  
      glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, 0);
  
  
      vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
      glShaderSource(vertexShaderId, 1, &vertexShader, NULL);
  
      glCompileShader(vertexShaderId);
  
      GLint completed;
      glGetShaderiv(vertexShaderId, GL_COMPILE_STATUS, &completed);
  
      if (!completed)
      {
          GLint length;
          GLchar *log;
          glGetShaderiv(vertexShaderId, GL_INFO_LOG_LENGTH, &length);
  
          log = (GLchar *)malloc(length);
          glGetShaderInfoLog(vertexShaderId, length, &length, log);
          fprintf(stderr, "Vertex compile log = '%s'\n", log);
      }
  
  
  
      fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
      glShaderSource(fragmentShaderId, 1, &fragmentShader, NULL);
      glCompileShader(fragmentShaderId);
  
      GLint complete;
  
      glGetShaderiv(fragmentShaderId, GL_COMPILE_STATUS, &complete);
  
      if (!complete)
      {
          GLint length;
          GLchar *log;
          glGetShaderiv(fragmentShaderId, GL_INFO_LOG_LENGTH, &length);
  
          log = (GLchar *)malloc(length);
          glGetShaderInfoLog(fragmentShaderId, length, &length, log);
          fprintf(stderr, "fragment compile log = '%s'\n", log);
      }
  
      programId = glCreateProgram();
  
      glAttachShader(programId, vertexShaderId);
      glAttachShader(programId, fragmentShaderId);
  
      glLinkProgram(programId);
  
      glUseProgram(programId);
  }
  </code></pre>