#include <iostream>
#include <stdlib.h>
#include "Angel.h"
typedef vec2 point2;
const int numPoints = 5000;
void init(void) {
//Initialize random number generator
std::srand((uint)std::time(0));
point2 points[numPoints];
//The vertices of a triangle in a plane
point2 vertices[3] ={point2(-1.0,-1.0),
point2(0.0,1.0),
point2(1.0, -1.0)};
//An arbitrary point inside the triangle
points[0] = point2(0.25, 0.25);
for(int k = 1; k < numPoints; ++k) {
//Picks a random vertex
int j = rand()%3;
//Computes the point halfway between the
//selected vertex and the previous point
points[k] = (points[k-1]+vertices[j])/2.0;
}
// Load shaders and use the resulting shader program
GLuint program = InitShader( "vshader.glsl", "fshader.glsl" );
glUseProgram( program );
// Create a vertex array object
GLuint vao;
glGenVertexArraysAPPLE( 1, &vao );
glBindVertexArrayAPPLE( vao );
// Create and initialize a buffer object
GLuint buffer;
glGenBuffers( 1, &buffer );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );
// Initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
//----------------------------------------------------------------------
void display( void ) {
glClear( GL_COLOR_BUFFER_BIT ); // clear the window
glDrawArrays( GL_POINTS, 0, numPoints ); // draw the points
glFlush();
}
//----------------------------------------------------------------------
int main( int argc, char **argv ) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_3_2_CORE_PROFILE);
glutInitWindowSize( 512, 512 );
// If you are using freeglut, the next two lines will check if
// the code is truly 3.2. Otherwise, comment them out
glutCreateWindow( "Sierpinski Gasket" );
init();
glutDisplayFunc( display );
glutMainLoop();
return 0; }