title: Make object disappear and appear in OpenGL
body: <pre><code>#include &lt;stdio.h&gt; // this library is for standard input and output
  #include "glut.h" // this library is for glut the OpenGL Utility Toolkit
  #include &lt;math.h&gt;
  
  // left square
  void drawShape1(void) {
      glBegin(GL_POLYGON);
      glColor3f(1.0, 0.0, 0.0);
      glVertex2f(82, 250);
      glVertex2f(82, 200);
      glVertex2f(140, 200);
      glVertex2f(140, 250);
      glEnd();
  }
  
  // right square
  void drawShape2(void) {
      glBegin(GL_POLYGON);
      glColor3f(1.0, 0.0, 0.0);
      glVertex2f(232, 250);
      glVertex2f(232, 200);
      glVertex2f(290, 200);
      glVertex2f(290, 250);
      glEnd();
  }
  
  void initRendering() {
      glEnable(GL_DEPTH_TEST);
  }
  
  // called when the window is resized
  void handleResize(int w, int h) {
      glViewport(0, 0, w, h);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0.0f, (float)w, 0.0f, (float)h, -1.0f, 1.0f);
  }
  
  void display() {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      drawShape1();
      drawShape2();
      glutSwapBuffers();
      glutPostRedisplay();
  }
  
  // the timer code
  void update(int value) {
      // add code here
  
      glutPostRedisplay();
      glutTimerFunc(5, update, 0);
  }
  
  int main(int argc, char** argv) {
      glutInit(&amp;argc, argv);
      glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
      glutInitWindowSize(400, 400);
      glutCreateWindow("Squares");
      initRendering();
      glutDisplayFunc(display);
      glutReshapeFunc(handleResize);
      glutTimerFunc(5, update, 0);
      glutMainLoop();
      return(0);
  }
  </code></pre>
  
  <p>I have two squares in the middle. One square is on the left and the other square is on the right (see screenshot below). I am trying to make the left square disappear/appear every 5 seconds. I have added the timer code, but I am struggling on how to make the object disappear/appear. </p>
  
  <p><strong>Preview:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/hD6Hi.jpg" alt="Two squares"></p>