title: OpenGL ES triangle not showing
body: <p>First of all I'm french so sorry for my english.</p>
  
  <p>I'm new to OpenGL ES and I'm trying to draw a simple triangle with these Vertices :</p>
  
  <pre><code>typedef struct {
      float Position[3];
      float Color[4];
  } Vertex;
  
  const Vertex Vertices[] = {
      {{0.0, 1.0, -2.0}, {1, 0, 0, 1}},
      {{1.0, 0.0, -2.0}, {1, 0, 0, 1}},
      {{-1.0, 0.0, -2.0}, {1, 0, 0, 1}},
  };
  </code></pre>
  
  <p>and these indices ;</p>
  
  <pre><code>const GLubyte Indices[] = {
      0,1,2
  };
  </code></pre>
  
  <p>But the triangle is not showing up... If I change the indices to 0,2,3, It displays a triangle with vertex 0,2 and a black vertex : {{0,0,0},{0,0,0,1}} , but there is no 4th vertex... I don't understand at all could someone explain me?</p>
  
  <p>Here's my Xcode view code :</p>
  
  <pre><code>//
  //  EAGLView.m
  //  OpenGlintro
  //
  //  Created by Arnaud Miguet on 01/12/12.
  //  Copyright (c) 2012 Tap‘n'Develop. All rights reserved.
  //
  
  #import "EAGLView.h"
  
  @implementation EAGLView
  + (Class) layerClass {
      return [CAEAGLLayer class];
  }
  
  - (void)setupVBOs {
  
      GLuint vertexBuffer;
      glGenBuffers(1, &amp;vertexBuffer);
      glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
      glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
  
      GLuint indexBuffer;
      glGenBuffers(1, &amp;indexBuffer);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
  
  }
  
  - (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if (self) {
          // Initialization code
          CAEAGLLayer *EAGLLayer = (CAEAGLLayer *) super.layer;
          EAGLLayer.opaque = YES;
  
          context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
  
          if (!context || ![EAGLContext setCurrentContext:context]) {
              [self release];
              return nil;
          }
  
          GLuint framebuffer , renderbuffer;
  
          glGenBuffers(1, &amp;framebuffer);
          glGenBuffers(1, &amp;renderbuffer);
  
          glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
          glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
  
          [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:EAGLLayer];
          glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
          glViewport(10, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));
          [self compileShaders];
          [self setupVBOs];
          [self render];
      }
      return self;
  }
  
  
  - (void)render {
      glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
      glClear(GL_COLOR_BUFFER_BIT);
  
      // 1
      glViewport(0, 0, self.frame.size.width, self.frame.size.height);
  
      // 2
      glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE,
                        sizeof(Vertex), 0);
      glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE,
                        sizeof(Vertex), (GLvoid*) (sizeof(float) * 3));
  
      // 3
      glDrawElements(GL_TRIANGLES, sizeof(Indices),
                 GL_UNSIGNED_BYTE, 0);
  
      [context presentRenderbuffer:GL_RENDERBUFFER];
  }
  
  - (GLuint)compileShader:(NSString*)shaderName withType:(GLenum)shaderType {
  
      // 1
      NSString* shaderPath = [[NSBundle mainBundle] pathForResource:shaderName
                                                         ofType:@"glsl"];
      NSError* error;
      NSString* shaderString = [NSString stringWithContentsOfFile:shaderPath
                                                     encoding:NSUTF8StringEncoding error:&amp;error];
      if (!shaderString) {
          NSLog(@"Error loading shader: %@", error.localizedDescription);
          exit(1);
      }
  
      // 2
      GLuint shaderHandle = glCreateShader(shaderType);
  
      // 3
      const char * shaderStringUTF8 = [shaderString UTF8String];
      int shaderStringLength = [shaderString length];
      glShaderSource(shaderHandle, 1, &amp;shaderStringUTF8, &amp;shaderStringLength);
  
      // 4
      glCompileShader(shaderHandle);
  
      // 5
      GLint compileSuccess;
      glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &amp;compileSuccess);
      if (compileSuccess == GL_FALSE) {
          GLchar messages[256];
          glGetShaderInfoLog(shaderHandle, sizeof(messages), 0, &amp;messages[0]);
          NSString *messageString = [NSString stringWithUTF8String:messages];
          NSLog(@"%@", messageString);
          exit(1);
      }
  
      return shaderHandle;
  
  }
  
  - (void)compileShaders {
  
      // 1
      GLuint vertexShader = [self compileShader:@"SimpleVertex"
                                   withType:GL_VERTEX_SHADER];
      GLuint fragmentShader = [self compileShader:@"SimpleFragment"
                                     withType:GL_FRAGMENT_SHADER];
  
      // 2
      GLuint programHandle = glCreateProgram();
      glAttachShader(programHandle, vertexShader);
      glAttachShader(programHandle, fragmentShader);
      glLinkProgram(programHandle);
  
      // 3
      GLint linkSuccess;
      glGetProgramiv(programHandle, GL_LINK_STATUS, &amp;linkSuccess);
      if (linkSuccess == GL_FALSE) {
          GLchar messages[256];
          glGetProgramInfoLog(programHandle, sizeof(messages), 0, &amp;messages[0]);
          NSString *messageString = [NSString stringWithUTF8String:messages];
          NSLog(@"%@", messageString);
          exit(1);
      }
  
      // 4
      glUseProgram(programHandle);
  
      // 5
      _positionSlot = glGetAttribLocation(programHandle, "Position");
      _colorSlot = glGetAttribLocation(programHandle, "SourceColor");
      glEnableVertexAttribArray(_positionSlot);
      glEnableVertexAttribArray(_colorSlot);
  }
  
  typedef struct {
      float Position[3];
      float Color[4];
  } Vertex;
  
  const Vertex Vertices[] = {
      {{0.0, 1.0, -2.0}, {1, 0, 0, 1}},
      {{1.0, 0.0, -2.0}, {1, 0, 0, 1}},
      {{-1.0, 0.0, -2.0}, {1, 0, 0, 1}},
  };
  
  const GLubyte Indices[] = {
      0,2,3
  };
  
  @end
  </code></pre>