//open a display window //and generate a sine curve //www.timestocome.com //to compile in OSX //gcc sine.c -o sine -framework OpenGL -framework GLUT #include #include #include #include void display (void){ typedef GLfloat point2[2]; //define a point array long int k; point2 p = {0.0, 0.0}; //start somewhere glClear(GL_COLOR_BUFFER_BIT); //clear window for( k=0; k<2500; k++){ //compute point p[0] += 500.0/2500.0; p[1] = (sin(p[0])*10.0)+125; //plot point glBegin(GL_POINTS); glVertex2fv(p); glEnd(); } glFlush(); //plot quickly.. only benefit if on a network } void myinit (void){ //attributes glClearColor(1.0, 1.0, 1.0, 0.0); //backround glColor3f(1.0, 0.0, 0.0); //draw color //set up viewing glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0, 500.0, 0.0, 250.0); //2d coordinate sys lower left corner 0,0 glMatrixMode(GL_MODELVIEW); } void main(int argc, char **argv) { glutInit(&argc, argv); glutInitWindowSize(500, 250); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); (void)glutCreateWindow("2d Sine Curve"); glutDisplayFunc(display); myinit(); glutMainLoop(); }