Sierpinkski gasket
- start with a triangle
- compute the midpoints of the 3 sides, and create points
- connect the bisectors and remove the central triangle, making 3 trangles
- repeat recursively

- the filled area are the blue parts, it will approach 0 as we carve away more of the triangles
- the perimeter approaches infinity

- this is not an ordinary geometric object, its a fractal
→ self-similar independent of scale
→ a geometric shape that can be subdivided into parts, each of which is a reduced size copy of the whole

#define RECURSIVE_LEVELS 3

typedef GLFloat point2[2];

point2 triangle[] = {{0,0},{0.5,1},{1,0}}

void drawTriangle(point2 a, point2 b, point2 c){
    glBegin(GL_TRIANGLES);
        glVertex2fv(a);
        glVertex2fv(b);
        glVertex2fv(c);
    glEnd();
}

void divideTriangle(point2 a, point2 b, point2 c, int level){
    point2 m0,m1,m2;
    int j;
    if(level > 0){
        for( j = 0; j < 2; j++){
            m0[j] = (a[j] + b[j]) / 2
            m1[j] = //same for a and c
            m2[j] = //same for b and c
        }
        divideTriangle(a,m0,m1,level-1);
        divideTriangle(c,m1,m2,level-1);
        divideTriangle(b,m2,m0,level-1);
    } else {
        drawTriangle(a,b,c);
    }

}


in openGL, 2D is basically just a slice of 3D with the third value set to 0.
- we have to worry about the order our polygons are drawn when we think about thinks going to the back or front of our scene
- our polygons still must be simple, convex and flat
- we can use the same algorithm to subdivide a tetrahedron
- the original triangle is on the xy plane, the tetrahedron adds one more point towards the camera

typedef GLFloat point3[3]

point3 tetra[] = {{0.00.00.0},{0.5,1.0,0.0},{,,,0.0},{,,,1.0}}//final point has a z of 1


- Z-Buffer saves depth information about pixels so only things closest are rendered
- to use depth buffering:
→ call glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH)
→ enable it with glEnable(GL_DEPTH_TEST)
→ clear it in the display buffer in the display callback with glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- kinda cheating by using the | to combine the parameters with a bitwise or



Index