Startup Program for OpenGL/GLUT
/*
Evan Golub - 2004 - egolub@acm.org
*/
#include <GL/glut.h>
#include <math.h>
#include <iostream.h>
float radius; //Global variable - Eeek!
void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex2f(-1,0); glVertex2f(1,0);
glVertex2f(0,-1); glVertex2f(0,1);
glEnd();
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(0,0);
glVertex2f(0,0.5);
glVertex2f(0.5,0.5);
glVertex2f(0.5,0);
glEnd();
glColor3f(1.0, 0.5, 0.0);
glPointSize(4);
glBegin(GL_POINTS);
glVertex2f(0,0);
glEnd();
glColor3f(1.0, 0.5, 0.75);
glBegin(GL_LINE_LOOP);
float angle;
int numberOfSegments = 100;
float PI = 3.141592;
for(int i = 0; i < numberOfSegments; i++){
angle = i*2*PI/numberOfSegments;
glVertex2f(radius*cos(angle),radius*sin(angle));
}
glEnd();
//glFlush();
glutSwapBuffers();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowSize(100,100);
glutCreateWindow("Test App");
cout << "Enter a floating point value between 0 and 1 for the radius of the circle: ";
cin >> radius;
if ((radius < 0) || (radius > 1)) radius = 0.5;
glutDisplayFunc(MyDisplay);
glutMainLoop();
}