title: Want to draw square on one face of a rectangular prism opengl es ios
body: <p>I have rendered a rectangular prism using opengl es for ios in Xcode. I want to draw a square on one of the faces of the rectangular prism (front face). I cant use a different data structure to hold the vertices, color co-ordinates and texture because the rectangular prism rotates with touch, and if I use a separate datastructure then the square wont rotate with the rectangular prism. So in the same datastructure I want to make a square. When I add the co-ordinates to the data structure and specify the points of the triangles it does not render the new square. Here is the code...</p>
  
  <pre><code>typedef struct {
    float Position[3];
    float Color[4];
    float TexCoord[2];
  } Vertex;
  
  
  
  const Vertex Vertices[] = {
     // Front
     {{1, -2, 0.10}, {1, 1, 1, 1}, {1, 0}},
     {{1, 2, 0.10}, {1, 1, 1, 1}, {1, 1}},
     {{-1, 2, 0.10}, {1, 1, 1, 1}, {0, 1}},
     {{-1, -2, 0.10}, {1, 1, 1, 1}, {0, 0}},
     // Back
     {{1, 2, -0.10}, {1, 1, 1, 1}, {0, 1}},
     {{-1, -2, -0.10}, {1, 1, 1, 1}, {1, 0}},
     {{1, -2, -0.10}, {1, 1, 1, 1}, {0, 0}},
     {{-1, 2, -0.10}, {1, 1, 1, 1}, {1, 1}},
     // Left
     {{-1, -2, 0.10}, {1, 1, 1, 1}, {1, 0}},
     {{-1, 2, 0.10}, {1, 1, 1, 1}, {1, 1}},
     {{-1, 2, -0.10}, {1, 1, 1, 1}, {0, 1}},
     {{-1, -2, -0.10}, {1, 1, 1, 1}, {0, 0}},
     // Rightself
     {{1, -2, -0.10}, {1, 1, 1, 1}, {1, 0}},
     {{1, 2, -0.10}, {1, 1, 1, 1}, {1, 1}},
     {{1, 2, 0.10}, {1, 1, 1, 1}, {0, 1}},
     {{1, -2, 0.10}, {1, 1, 1, 1}, {0, 0}},
     // Top
     {{1, 2, 0.10}, {1, 1, 1, 1}, {1, 0}},
     {{1, 2, -0.10}, {1, 1, 1, 1}, {1, 1}},
     {{-1, 2, -0.10}, {1, 1, 1, 1}, {0, 1}},
     {{-1, 2, 0.10}, {1, 1, 1, 1}, {0, 0}},
     // Bottom
     {{1, -2, -0.10}, {1, 1, 1, 1}, {1, 0}},
     {{1, -2, 0.10}, {1, 1, 1, 1}, {1, 1}},
     {{-1, -2, 0.10}, {1, 1, 1, 1}, {0, 1}},
     {{-1, -2, -0.10}, {1, 1, 1, 1}, {0, 0}},
  
    //new square
    {{1, -2, -0.1}, {1, 1, 1, 1}, {1, 0}},
    {{1, -2, 0.1}, {1, 1, 1, 1}, {1, 1}},
    {{-1, -2, 0.1}, {1, 1, 1, 1}, {0, 1}},
    {{-1, -2, -0.1}, {1, 1, 1, 1}, {0, 0}},
  };
  
  
  
  
   const GLubyte Indices[] = {
     // Front
     0, 1, 2,
     2, 3, 0,
  
     // Back
     4, 6, 5,
     4, 5, 7,
     // Left
     8, 9, 10,
     10, 11, 8,
  
     // Right
     12, 13, 14,
     14, 15, 12,
     // Top
     16, 17, 18,
     18, 19, 16,
     // Bottom
     20, 21, 22,
     22, 23, 20,
     //new square
     24, 25, 26,
     26, 27, 24,
  };
  </code></pre>
  
  <p>Is the square not rendering because I messed up with my co-ordinates, or is there another method that I need to check and specify I am adding new co-ordinates. Also I am using GLKBaseEffect, so no vertex and fragment shaders. </p>
  
  <pre><code>- (void)setupGL {
  
  [EAGLContext setCurrentContext:self.context];
  glEnable(GL_CULL_FACE);
  
  self.effect = [[GLKBaseEffect alloc] init];
  
  NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithBool:YES],
                            GLKTextureLoaderOriginBottomLeft, 
                            nil];
  
  NSError * error;    
  NSString *path = [[NSBundle mainBundle] pathForResource:@""ofType:@"png"];
  GLKTextureInfo * info = [GLKTextureLoader textureWithContentsOfFile:path options:options error:&amp;error];
  if (info == nil) {
      NSLog(@"Error loading file: %@", [error localizedDescription]);
  }
  self.effect.texture2d0.name = info.name;
  self.effect.texture2d0.enabled = true;
  
  // New lines
  glGenVertexArraysOES(1, &amp;_vertexArray);
  glBindVertexArrayOES(_vertexArray);
  
  // Old stuff
  glGenBuffers(1, &amp;_vertexBuffer);
  glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
  glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
  //glBufferData(GL_ARRAY_BUFFER, sizeof(VerticesTwo), VerticesTwo, GL_STATIC_DRAW);
  
  glGenBuffers(1, &amp;_indexBuffer);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices), Indices, GL_STATIC_DRAW);
  //glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(IndicesTwo), IndicesTwo, GL_STATIC_DRAW);
  
  
  // New lines (were previously in draw)
  glEnableVertexAttribArray(GLKVertexAttribPosition);        
  glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));
  glEnableVertexAttribArray(GLKVertexAttribColor);
  glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color));
  glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
  glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, TexCoord));
  
  glEnableVertexAttribArray(GLKVertexAttribPosition);
  //glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VertexTwo), (const GLvoid *) offsetof(Vertex, Position));
  glEnableVertexAttribArray(GLKVertexAttribColor);
  //glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(VertexTwo), (const GLvoid *) offsetof(VertexTwo, Color));
  glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
  //glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(VertexTwo), (const GLvoid *) offsetof(Vertex, TexCoord));
  
  // New line
  glBindVertexArrayOES(0);
  
  _rotMatrix = GLKMatrix4Identity;
  _quat = GLKQuaternionMake(0, 0, 0, 1);
  _quatStart = GLKQuaternionMake(0, 0, 0, 1);
  
  UITapGestureRecognizer * dtRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
  dtRec.numberOfTapsRequired = 2;
  [self.view addGestureRecognizer:dtRec];
  //[self addGestureRecognizer:dtRec];
  //[self.view bringSubviewToFront: self.view];
  
  
  }
  </code></pre>