// Peter Bui // CSE 40166 Computer Graphics (Fall 2010) // Program 1: display initials in different colors #include #include #include void init(); void display(); int main(int argc, char *argv[]) { glutInit(&argc, argv); glutCreateWindow("initials"); glutDisplayFunc(display); init(); // Setup some non-default parameters glutMainLoop(); return (EXIT_SUCCESS); } void init() { // Choose a black background/clearing color glClearColor(0.0, 0.0, 0.0, 1.0); // Setup a non-perspective camera (more in later lectures/examples) glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0); } void draw_circle(GLfloat ox, GLfloat oy, GLfloat radius, int triangles) { int i; GLfloat angle; glBegin(GL_TRIANGLE_FAN); { glVertex2f(ox, oy); for (i = 0; i <= triangles; i++) { angle = i * 2.0 * M_PI / triangles; glVertex2f(ox + radius * cos(angle), oy + radius * sin(angle)); } } glEnd(); } void draw_semicircle(GLfloat ox, GLfloat oy, GLfloat radius, int triangles, int direction) { int i; GLfloat angle; glBegin(GL_TRIANGLE_FAN); { glVertex2f(ox, oy); for (i = 0; i <= triangles; i++) { angle = i * M_PI * direction / triangles; glVertex2f(ox + radius * cos(angle), oy + radius * sin(angle)); } } glEnd(); } void display() { glClear(GL_COLOR_BUFFER_BIT); // p glColor3f(1.0, 0.0, 0.0); glRectf(-6.0, 5.0, -5.0, -4.5); draw_circle(-3.5, 2.5, 2.5, 36); glColor3f(0.0, 0.0, 0.0); draw_circle(-3.5, 2.5, 1.5, 36); // j glColor3f(0.0, 1.0, 0.0); glRectf(-0.5, 5.0, 0.5, -2.5); draw_circle(0.0, 6.0, 0.5, 36); draw_semicircle(-2.0, -2.0, 2.5, 36, -1); glColor3f(0.0, 0.0, 0.0); draw_semicircle(-2.0, -2.0, 1.5, 36, -1); // b glColor3f(0.0, 0.0, 1.0); glRectf( 1.0, 9.5, 2.0, 0.0); draw_circle( 3.5, 2.5, 2.5, 36); glColor3f(0.0, 0.0, 0.0); draw_circle( 3.5, 2.5, 1.5, 36); glFlush(); }