//primitives // rotation of the square and filled square // introducing new versions of fundamental draw-functions // T. Kosaka CS TNCT 2001 #include #include #include #include "drawShape2D.h" void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); userdraw(); glutSwapBuffers(); } void userdraw(void) { static int tick=0; point2D_t pnt[4]; color_t color0={0,1,1}; color_t color[4]={ {1,0,1},{1,0,0},{0,1,0},{0,0,1} }; pnt[0].x=200.*cos((float)tick*.005)+320; pnt[0].y=200.*sin((float)tick*.005)+240; pnt[1].x=200.*cos((float)tick*.005+3.1415926535*.5)+320; pnt[1].y=200.*sin((float)tick*.005+3.1415926535*.5)+240; pnt[2].x=200.*cos((float)tick*.005+3.1415926535)+320; pnt[2].y=200.*sin((float)tick*.005+3.1415926535)+240; pnt[3].x=200.*cos((float)tick*.005+3.1415926535*1.5)+320; pnt[3].y=200.*sin((float)tick*.005+3.1415926535*1.5)+240; if ((tick/100)%3==0) { glutSetWindowTitle("primitives - drawPolygon"); setColor(color0); drawPolygon(pnt,4); } else if ((tick/100)%3==1) { glutSetWindowTitle("primitives - fillPolygon"); fillPolygon(pnt,4,color0); } else { glutSetWindowTitle("primitives - gradatePolygon"); gradatePolygon(pnt,color,4); } tick++; } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow ("primitives"); glClearColor(0.0, 0.0, 0.0, 0.0); gluOrtho2D(0., 640., 0., 480.0); // Define the dimensions of the Orthographic Viewing Volume glutIdleFunc(display); // idle event call back glutDisplayFunc(display); glutMainLoop(); return 0; }