/* * main.cpp * CompFormApp * */ #include "Shape.h" bool mouseClick = true; float mouseX = 0; float mouseY = 0; int windowW = 800; int windowH = 600; #define PI 3.14159265358979 void drawCircle(float radius, int numOfPts, Vec2d center){ Circle circ(radius, numOfPts, center); circ.draw(); } void drawOval(float vRadius, float hRadius, int numOfPts, Vec2d center){ Oval ov(vRadius, hRadius, numOfPts, center); ov.draw(); } void drawStar(float innerRadius, float outerRadius, int numOfPts, Vec2d center){ Star star(innerRadius, outerRadius, numOfPts, center); star.draw(GL_LINE_LOOP); } void drawScreen() { if (mouseClick) { int numOfStars = 100; Vec2d center(10, 400); for (int starNum = 0; starNum < numOfStars; starNum++) { glColor3f(((float)(rand() % 10)) * .1, ((float)(rand() % 10)) * .1, ((float)(rand() % 10)) * .1); int inner = rand() % 50; int outer = rand() % 50; center.x = rand() % windowW; center.y = rand() % windowW; drawStar(inner, outer, rand() % 30+ 10, center); } } } void displayFunc ( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // place your drawing code here drawScreen(); printf("displayFunc: %i\n", mouseClick); glutPostRedisplay(); glutSwapBuffers(); } void reshapeFunc ( int w, int h ) { windowW = w; windowH = h; glViewport( 0, 0, w, h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0,w,0,h ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); } void mouseDownFunc ( int button, int state, int x, int y ) { mouseClick = !mouseClick; printf("mouseClick: %i\n", mouseClick); mouseX = x; mouseY = windowH - y; } void mouseMoveFunc ( int x, int y ) { mouseX = x; mouseY = windowH - y; } void mouseDragFunc ( int x, int y ) { mouseX = x; mouseY = windowH - y; } void keyboardFunc ( unsigned char key, int x, int y ) { } void arrowKeyFunc ( int a_keys, int x, int y ) { } void init ( GLvoid ) { glShadeModel( GL_SMOOTH ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); glEnable ( GL_COLOR_MATERIAL ); glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } int main ( int argc, char** argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); glutInitWindowSize( windowW, windowH ); glutCreateWindow( "CompFormApp" ); glutDisplayFunc( displayFunc ); glutReshapeFunc( reshapeFunc ); glutMouseFunc( mouseDownFunc ); glutMotionFunc( mouseDragFunc ); glutPassiveMotionFunc( mouseMoveFunc ); glutKeyboardFunc( keyboardFunc ); glutSpecialFunc( arrowKeyFunc ); init(); glutMainLoop( ); return 0; }