Hey guys,

I made a program in open GL which draws sierpinksy triangle recursivley. Since it's based on different levels and i'm passing "level" as param. So I tried to use a loop and increase the counter by one to see every level and paused for 1 millisecond. However, everytime it draws 0 level triangle which basically is the first one. It doesn't continue drawing until my loop condition is true. Here is the code:

Code:

void Draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
glTranslatef (0.0f, 0.0f, -4.0f); // Translate 6 Units Into The Screen
int level = 0;
Point a, b, c;
a.x = -0.5; a.y = -0.5;
b.x = 0.5; b.y = -0.5;
c.x = 0.0; c.y = 0.5;
while (level != 5) {
drawSierpinski(a, b, c, level);
level += 1;
Sleep(1);
}
glFlush (); // Flush The GL Rendering Pipeline
}
// Draws a triangle
GLint drawTri(Point a, Point b, Point c)
{
glBegin(GL_POLYGON);
glVertex2f(a.x,a.y);
glVertex2f(b.x,b.y);
glVertex2f(c.x,c.y);
glEnd();
} // end draw triangle
/*******************************************************
* Function from class to draw the Sierpinski fractal
* Recursion is FUN!
*******************************************************/
GLint drawSierpinski(Point a, Point b, Point c, GLint level)
{
Point m0, m1, m2;
Sleep(1);
if (level > 0) {
m0.x = (a.x + b.x) /2.0;
m0.y = (a.y + b.y) / 2.0;
m1.x = (a.x + c.x) / 2.0;
m1.y = (a.y + c.y) / 2.0;
m2.x = (b.x + c.x) / 2.0;
m2.y = (c.y + b.y) / 2.0;
drawSierpinski(a,m0,m1, level - 1);
drawSierpinski(b, m2, m0, level - 1);
drawSierpinski(c, m1, m2, level - 1);
}
else
drawTri(a, b, c);
} // end draw Sierpinski

Please someone help me with it or give me any idea to fix it. Don't worry about Point and void Draw(void) they have been declared in ".h" and i've inculded the headers on the top.

I did this program in Java like few months ago as my school assignment; it worked then and i've same code and everything. But now it doesn't work. I would really apperciate the help. Thank you!!