title: Rotate Triangle In OpenGL
body: <p>I'm trying to rotate a triangle around it's center point. I'm aware that OpenGL rotates about the origin so I need to translate the middle point to the origin, then rotate, and translate back. I've commented out this last line to ensure that it at least rotates about its center  at the origin. It does not. It appears to be rotating about its old origin despite the translation... Note that ccc4 and ccp generate floats. Here's my code:</p>
  
  <pre><code>ccColor4B colors[] = {
      ccc4(255, 0, 0, 255),
      ccc4(0, 255, 0, 255),
      ccc4(0, 0, 255, 255)
  };
  
  CGPoint vertices[] = {
      ccp(0,0),
      ccp(50,100),
      ccp(100,0),
  };
  
  CGPoint middle[] = {ccp(50,50)};
  CGPoint origin[] = {ccp(0,0)};
  
  // Rotate the triangle
  glPushMatrix();
  glTranslatef(-50, -50, 0);
  glRotatef(45, 0, 0, 1.0);
  // glTranslatef(50, 50, 0);
  
  // Draw the triangle
  glLineWidth(2);
  glVertexPointer(2, GL_FLOAT, 0, vertices);
  glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
  glColor4ub(0, 0, 255, 255);
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
  
  // Revert rotation, we only want triangle to rotate 
  glPopMatrix();
  
  // Draw the points
  glDisableClientState(GL_COLOR_ARRAY);
  
  glPointSize(5);
  glColor4ub(255, 255, 255, 255);
  glVertexPointer(2, GL_FLOAT, 0, middle);
  glDrawArrays(GL_POINTS, 0, 1);
  
  glPointSize(5);
  glColor4ub(0, 255, 0, 255);
  glVertexPointer(2, GL_FLOAT, 0, origin);
  glDrawArrays(GL_POINTS, 0, 1);
  
  glEnableClientState(GL_COLOR_ARRAY);
  // End points
  </code></pre>
  
  <p>Here's the output:</p>
  
  <p><img src="https://i.stack.imgur.com/oKuss.png" alt="1">
  <img src="https://i.stack.imgur.com/WAYYr.png" alt="2"></p>