title: OpenGL using glNewList and glDrawElements
body: <p>I have my code compiling and working but I am not sure if it is working just by chance. The thing is, In my <em>init</em> function I enable the vertex array, then define a glNewList and at the end I disable the vertex array.</p>
  
  <pre><code>void init(){
  
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClearDepth(1.0);
  
      glEnableClientState(GL_VERTEX_ARRAY);
      glVertexPointer(3, GL_FLOAT, 0, vertices);
  
      doubleStar = glGenLists(1);
      glNewList(doubleStar, GL_COMPILE);
          glPushAttrib(GL_CURRENT_BIT);
          glPushMatrix();
  
          glColor3f(0, 0, 0.7);
  
          // outside
          glPushMatrix();
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, indices);
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, &amp;indices[8]);
          glPopMatrix();
  
          // inside
          glPushMatrix();
              glRotatef(30, 0, 0, 1);
              glScalef(0.4, 0.4, 0.4);            
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, indices);
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, &amp;indices[8]);
          glPopMatrix();
  
          glPopMatrix();
          glPopAttrib();
      glEndList();
  
      glDisableClientState(GL_VERTEX_ARRAY);
  
      glutDisplayFunc(display);
  
  }
  </code></pre>
  
  <p>In my display function I call glCallList:</p>
  
  <pre><code>void display(){
  
      glClear(GL_COLOR_BUFFER_BIT);
      glClear(GL_DEPTH_BUFFER_BIT);
  
      glMatrixMode( GL_MODELVIEW );
      glLoadIdentity();
  
      // top left
      glPushMatrix();
          glTranslatef(-0.5, 0.5, 0);
          glRotatef(15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      // top right
      glPushMatrix();
          glTranslatef(0.5, 0.5, 0);
          glRotatef(-15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      // bot left
      glPushMatrix();
          glTranslatef(-0.5, -0.5, 0);
          glRotatef(-15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      // bot right    
      glPushMatrix();
          glTranslatef(0.5, -0.5, 0);
          glRotatef(15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      glFlush();
      glutSwapBuffers();
  
  }
  </code></pre>
  
  <p>When display is executed the array is already closed! So I am not sure if that would work in any case. On the other hand, I have read that if you call glNewList with the GL_COMPILE flag the status at compile time is saved. So, may be since at compile time the vertex array was enabled then when calling the list would be enabled.
  <br>
  So, the question is: would this work in any case? Is it a good approach?
  <br><br>
  Here the full code:
  <br></p>
  
  <pre><code>#include &lt;GL/glut.h&gt;
  #include &lt;cmath&gt;
  
  void init();
  void diplay();
  
  static const GLfloat rInt = 0.7;
  static const GLfloat rExt = 1;
  
  static const GLuint indices[] = 
  {
  
      4, 1, 3, 0, 5, 2, 4, 1,
      10, 7, 9, 6, 11, 8, 10, 7
  
  };
  
  static const GLfloat vertices[] =
  {
      0, rInt, 0,
      -cos(M_PI_2/3)*rInt, -sin(M_PI_2/3)*rInt, 0,
      cos(M_PI_2/3)*rInt, -sin(M_PI_2/3)*rInt, 0,
  
      0, rExt, 0,
      -cos(M_PI_2/3)*rExt, -sin(M_PI_2/3)*rExt, 0,
      cos(M_PI_2/3)*rExt, -sin(M_PI_2/3)*rExt, 0,
  
      // 6
  
      0, -rInt, 0,
      -cos(M_PI_2/3)*rInt, sin(M_PI_2/3)*rInt, 0,
      cos(M_PI_2/3)*rInt, sin(M_PI_2/3)*rInt, 0,
  
      0, -rExt, 0,
      -cos(M_PI_2/3)*rExt, sin(M_PI_2/3)*rExt, 0,
      cos(M_PI_2/3)*rExt, sin(M_PI_2/3)*rExt, 0
  
  };
  
  static GLuint doubleStar;
  
  int main(int argc, char** argv){
  
      glutInit(&amp;argc, argv);
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
      glutInitWindowSize(600, 600);
      glutInitWindowPosition(64, 64);
      glutCreateWindow("Mosaico estrella");
  
      init();
  
      glutMainLoop();
  
      return 0;
  
  }
  
  void display(){
  
      glClear(GL_COLOR_BUFFER_BIT);
      glClear(GL_DEPTH_BUFFER_BIT);
  
      glMatrixMode( GL_MODELVIEW );
      glLoadIdentity();
  
      // top left
      glPushMatrix();
          glTranslatef(-0.5, 0.5, 0);
          glRotatef(15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      // top right
      glPushMatrix();
          glTranslatef(0.5, 0.5, 0);
          glRotatef(-15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      // bot left
      glPushMatrix();
          glTranslatef(-0.5, -0.5, 0);
          glRotatef(-15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      // bot right    
      glPushMatrix();
          glTranslatef(0.5, -0.5, 0);
          glRotatef(15, 0, 0, 1);
          glScalef(0.5, 0.5, 0.5);
          glCallList(doubleStar);
      glPopMatrix();
  
      glFlush();
      glutSwapBuffers();
  
  }
  
  void init(){
  
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClearDepth(1.0);
  
      glEnableClientState(GL_VERTEX_ARRAY);
      glVertexPointer(3, GL_FLOAT, 0, vertices);
  
      doubleStar = glGenLists(1);
      glNewList(doubleStar, GL_COMPILE);
          glPushAttrib(GL_CURRENT_BIT);
          glPushMatrix();
  
          glColor3f(0, 0, 0.7);
  
          // outside
          glPushMatrix();
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, indices);
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, &amp;indices[8]);
          glPopMatrix();
  
          // inside
          glPushMatrix();
              glRotatef(30, 0, 0, 1);
              glScalef(0.4, 0.4, 0.4);            
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, indices);
              glDrawElements(GL_TRIANGLE_STRIP, 8, GL_UNSIGNED_INT, &amp;indices[8]);
          glPopMatrix();
  
          glPopMatrix();
          glPopAttrib();
      glEndList();
  
      glDisableClientState(GL_VERTEX_ARRAY);
  
      glutDisplayFunc(display);
  
  }
  </code></pre>