Original Post
for some reason my pathetic attempt at making a recursive drawing function in openGL wont work. well it does sometimes. but mostly it causes the program to hang up =/
in theory what this would do is recursively draw triangles (yeah i know i can one triangle to draw it but it looks cooler if i use the three and it makes it so i can draw from the center =P) with a new one drawn slightly further in the background at each vertex of each triangle out to where there are 256 levels of triangles from the top one. now if i comment out one or two of the recursive calls it sorta works. it doesnt do 256 layers of triangles, just two. oh, when the function is called initialy, currentdetail is set to 0. i can see why this would crash the program. but it does behave a little strangely =/
Bungo!
//Detail is a global unsigned long with a value of 256, and Pi is a global float with a value of pi =P, Point is a simple class with an X,Y, and Z float in it.
void DrawStuff(Point offset, float size, unsigned long currentdetail, Point red, Point green, Point blue)//, unsigned long colorscheme)
{
if (currentdetail<Detail)
{
Point nextoffset1;
Point nextoffset2;
Point nextoffset3;
glBegin(GL_TRIANGLES);
float degrees=2*Pi/3;
int pass=0;
for (float f=0.0f;f<2*Pi;f+=degrees)
{
float X1=sinf(f)*size;
float Y1=cosf(f)*size;
float X2=sinf(f+degrees)*size;
float Y2=cosf(f+degrees)*size;
glColor3f(red.X,green.X,blue.X);
glVertex3f(offset.X,offset.Y,offset.Z);
glColor3f(red.Y,green.Y,blue.Y);
glVertex3f(X1+offset.X,Y1+offset.Y,offset.Z);
glColor3f(red.Z,green.Z,blue.Z);
glVertex3f(X2+offset.X,Y2+offset.Y,offset.Z);
switch (pass)
{
case 0: nextoffset1.Set(X2,Y2,offset.Z-0.02f);
break;
case 1: nextoffset2.Set(X2,Y2,offset.Z-0.02f);
break;
case 2: nextoffset3.Set(X2,Y2,offset.Z-0.02f);
break;
}
pass++;
}
glEnd();
DrawStuff(nextoffset1,size-0.0005f,currentdetail+1,red,green,blue);
DrawStuff(nextoffset2,size-0.0005f,currentdetail+1,green,blue,red);
DrawStuff(nextoffset3,size-0.0005f,currentdetail+1,blue,red,green);
}
}