title: opengl: rotating an ellipse
body: <p>I am having trouble rotating an ellipse in OpenGL. So, I have some code to draw an ellipse as follows:</p>
  
  <pre><code>glPushAttrib(GL_CURRENT_BIT);
  glColor3f(1.0f, 0.0f, 0.0f);
  glLineWidth(2.0);
  glPushMatrix();
  glTranslatef(0, 0, 0); // ellipse centre   
  glBegin(GL_LINE_LOOP);
  float inc = (float) M_PI / 500.0;
  for (GLfloat i = 0; i &lt; M_PI * 2; i+=inc)
  {
      float x = cos(i) * 0.4;
      float y = sin(i) * 0.4;
      glVertex2f(x, y);
  }
  glEnd();
  glPopMatrix();
  glPopAttrib();
  </code></pre>
  
  <p>This produces a picture as so:<img src="https://i.stack.imgur.com/IUNSy.png" alt="enter image description here"></p>
  
  <p>Now what I want to do is rotate this ellipse clockwise. So I added a glrotate in between but the result was not what I had expected.</p>
  
  <p>So, I did something like:</p>
  
  <pre><code>glPushAttrib(GL_CURRENT_BIT);
  glColor3f(1.0f, 0.0f, 0.0f);
  glLineWidth(2.0);
  glPushMatrix();
  glTranslatef(0, 0, 0);    
  glRotatef(-90, 1, 1, 0);
  glBegin(GL_LINE_LOOP);
  float inc = (float) M_PI / 500.0;
  for (GLfloat i = 0; i &lt; M_PI * 2; i+=inc)
  {
      float x = cos(i) * 0.4;
      float y = sin(i) * 0.4;
      glVertex2f(x, y);
  }
  
  glEnd();
  glPopMatrix();
  glPopAttrib();
  </code></pre>
  
  <p>This produced an image which was simply collapsed. What I wanted to do was rotate the ellipse along its center by the specified degrees. Also, I tried playing around with the various parameters of glRotatef but could not get it do as I expected. The resulting image looks like:</p>
  
  <p><img src="https://i.stack.imgur.com/j79mh.png" alt="enter image description here"></p>