Sierpinski pyramid - problem with clearing screen

I need to do Sierpinski pyramid in openGL, and I actually did, but I have problem with clearing screen correctly. Code is in file. I write in DevC++. Just run it and you will understand what I mean.

(press + or - to change depth of recursion)

Hi,
It’s not a matter of clearing screen. It is more a code organization issue. Another thing is that you should render all of the triangles as a single batch rather than three different batches. So here is the final version of the rysuj_r function.


static void rysuj_r (float v1[], float v2[], float v3[], float v4[], int d)
{
   //root case: just render the primitives
   if(d==0) {
       glBegin(GL_TRIANGLES);
       glColor3f(1.0f,0.0f,0.0f);
       glVertex3fv(v1);
       glColor3f(0.0f,1.0f,0.0f);
       glVertex3fv(v2);
       glColor3f(0.0f,0.0f,1.0f);
       glVertex3fv(v3);
       
       glColor3f(1.0f,0.0f,0.0f);
       glVertex3fv(v1);
       glColor3f(0.0f,0.0f,1.0f);
       glVertex3fv(v3);
       glColor3f(0.0f,1.0f,0.0f);
       glVertex3fv(v4);
        

       
       glColor3f(1.0f,0.0f,0.0f);
       glVertex3fv(v1);
       glColor3f(0.0f,1.0f,0.0f);
       glVertex3fv(v4);
       glColor3f(0.0f,0.0f,1.0f);
       glVertex3fv(v2);
 

     
       glColor3f(1.0f,0.0f,0.0f);
       glVertex3fv(v3);
       glColor3f(0.0f,0.0f,1.0f);
       glVertex3fv(v2);
       glColor3f(0.0f,1.0f,0.0f);
       glVertex3fv(v4);
       glEnd();
   } else { 
   //otherwise find the new points and recurse
      float w1[3],w2[3],w3[3],w4[3],w5[3],w6[3];	
      for (int a=0; a<3; a++)
      {
         w1[a]=(v1[a]+v2[a])/2.0;
	 w2[a]=(v1[a]+v3[a])/2.0;
	 w3[a]=(v1[a]+v4[a])/2.0;
	 w4[a]=(v2[a]+v4[a])/2.0;
	 w5[a]=(v2[a]+v3[a])/2.0;
	 w6[a]=(v3[a]+v4[a])/2.0;
      }       
      rysuj_r (w1,v2,w5,w4,d-1);
      rysuj_r (w2,w5,v3,w6,d-1);
      rysuj_r (w3,w4,w6,v4,d-1);
      rysuj_r (v1,w1,w2,w3,d-1);
   }
}

Ahh, thank you man!!