title: Menger Sponge algorithm in c++
body: <p>I'm trying to create a Menger Sponge for an assignment,</p>
  
  <p><a href="http://upload.wikimedia.org/wikipedia/commons/d/de/Menger_sponge_%28Level_0-3%29.jpg" rel="nofollow">Meger sponge image from Wikipedia</a></p>
  
  <p>and at this point I have a 3*3*3 cube of cubes. I'm now trying to remove the correct blocks, to form the first iteration of the fractal. Each of the 27 blocks I have given an index, starting at 0 (blockNumber in my code). The block I have to remove are contained in my skipHere[] array. 4 is the first one removed, because it is the middle block of the first row.</p>
  
  <p>This code however is still printing out the full 3*3*3 structure, not skipping any block i'm trying to skip. So I think I'm looping over the skipHere[] array incorrectly, but I'm having trouble finding my logic error.</p>
  
  <pre><code>void display()
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glEnable(GL_DEPTH_TEST);
  
      UpdateTransform(0,0,0);
  
      int skipHere[7] = {4, 10, 12, 13, 14, 16, 22};
      int blockNumber = 0;
      bool skip = false;
      int x = 0;
      int y = 0;
      int z = 0;
      float Xres = 0;
      float Yres = 0;
      float Zres = 0;
      for(x = 0;x &lt; 3; ++x)
      {
  
        for(y = 0; y &lt; 3; ++y)
        {
  
        for(z = 0; z &lt; 3; ++z)
        {
          for(int i = 0; i &lt; 7; i++)
          {
  
            if(blockNumber == skipHere[i])
            {
              skip = true;
            }
  
            if(skip == false)
            {
              glPushMatrix();
              UpdateTransform(Xres,Yres,Zres);
              drawOneCube();
              glPopMatrix();
  
            }
            skip = false;
  
  
        }
  
        Zres -= 1.1;
  
        blockNumber += 1;
      }   
  
      Yres += 1.1;
      Zres = 0;
  
        }
  
        Xres += 1.1;
        Yres = 0;
  
  
      }
  
  
      glutSwapBuffers();
  
  }
  </code></pre>