title: Drawing a tetrahedron with 4 triangles with OpenGL
body: <p>I decided to make a tetrahedron manually(4 triangles) and rotate it. It kinda work, the only problem is that one of the triangles is never drawn. In my example code the front triangle(red) is drawn first, but when I render it, it never appears. Instead half of the left triangle(white) and right triangle(blue) appear. However when I change the code and put the three vertices of the front triangle after the the vertices of the other triangles, I do get the front triangle. Nevertheless one of the other two triangles disappear. What am I doing wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;GLUT/glut.h&gt;
  #include &lt;OpenGL/glu.h&gt;
  #include &lt;OpenGL/gl.h&gt;
  
  float posx = 0;
  float posy = 0;
  
  void drawLines(void)
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      //THIS ROTATES THE WHOLE SCENCE
      /*glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      glRotatef(posx, 0.0f, 1.0f, 0.0f);*/
  
      //THIS ROTATES ONLY THE OBJECTS INSIDE THE GLPUSHMATRIX AND GLPOPMATRIX FUNCTIONS
      glPushMatrix();
      glRotatef(posx, 0.0f, 1.0f, 0.0f);
  
      //TETAEDRON BY HAND
      glBegin(GL_TRIANGLES);
  
      //front triangle
      glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
      glVertex3f(0.0f, 5.0f, 0.0f);
      glVertex3f( -5.0f, -5.0f, 0.0f);
      glVertex3f( 5.0f,  -5.0f, 0.0f);
  
      //right side triangle
      glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
      glVertex3f( 5.0f,  -5.0f, 0.0f);
      glVertex3f(0.0f, 5.0f, 0.0f);
      glVertex3f( 0.0f,  -5.0f, -5.0f);
  
      //left side triangle
      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
      glVertex3f( -5.0f, -5.0f, 0.0f);
      glVertex3f(0.0f, 5.0f, 0.0f);
      glVertex3f( 0.0f,  -5.0f, -5.0f);
  
      //bottom triangle
      glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
      glVertex3f( -5.0f, -5.0f, 0.0f);
      glVertex3f( 5.0f,  -5.0f, 0.0f);
      glVertex3f( 0.0f,  -5.0f, -5.0f);
  
      glEnd();
  
      //glutSolidTeapot(5.0);
      glPopMatrix();
      glutWireTeapot(5.0);
      glFlush();
  }
  
  void init()
  {
      /*glClearDepth(1.0f);
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);*/
      glClearColor(0, 0, 0, 0);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, -10.0f, 10.0f);//range of x,y,z axis
      //gluOrtho2D(0.0f, 500.0f, 500.0f, 0.0f);//setup the camera in 2d mode
  
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
  }
  
  void keyboard(unsigned char key, int x, int y)
  {
      switch (key)
      {
          case 'd':posx+=10;
              printf("derecha %f\n",posx);
              break;
          case 'a':posx-=10;
              printf("izquierda\n");
              break;
          case 'w':posy-=10;
              printf("arriba\n");
              break;
          case 's':posy+=10;
              printf("abajo\n");
              break;
       }
  
   //glMatrixMode(GL_MODELVIEW);
   //glLoadIdentity();
   //glViewport(100.0f, 100.0f, 500.0f, 500.0f);
   //glTranslatef(posx, posy, 0.0);
   if(posx&gt;=360)
       posx = 0;
   //glRotatef(posx, 0.0f, 1.0f, 0.0f);
  }
  
  int main(int argc, const char * argv[])
  {
  
      // insert code here...
  
      glutInit(&amp;argc, argv);
      glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
      glutInitWindowPosition(400, 200);
      glutInitWindowSize(500, 500);
      glutCreateWindow("OpenGLTest");
  
      init();
  
      glutDisplayFunc(drawLines);
      glutIdleFunc(drawLines);
      glutKeyboardFunc(keyboard);
      glutMainLoop();
      return 1;
  }
  </code></pre>