case(l): /* store second vertex */ count++; xp[l] = x; yp[l] = y; break; case(2): /* third vertex: draw triangle */ if (fill) glBegin(GL_POLYGON); else glBegin(GL_LINE_LOOP); glVertex2i(xp[0], wh-yp[0]); glVertex2i(xp[1], wh-yp[1]); glVertex2i(x, wh-y); glEnd( ); draw_mode = 0; /* reset mode */ couht = 0; } Note that the first mouse click selects triangle mode; subsequent clicks count and store vertices. However, if the mouse is clicked on another button before the third vertex is selected, a new object is selected and drawn. key function renders characters entered from the keyboard to characters on the display. void key(unsigned char k, int xx, int yy) { If (draw_mode != TEXT) return; /* draw characters until mode changes */ glRasterPos2i(rx, ry); glCallList(k); /* Display list for character k */ rx += glutBitmapWidth(GLUT_BITMAP_9_BY_15, k); } A typical display from the middle of a drawing is below: Although paint program is simple and is limited in the facilities that it provides the user, more functionality can be added to it easily say adding the ability to switch from raster to stroke text,
case(l): /* store second vertex */ count++; xp[l] = x; yp[l] = y; break; case(2): /* third vertex: draw triangle */ if (fill) glBegin(GL_POLYGON); else glBegin(GL_LINE_LOOP); glVertex2i(xp[0], wh-yp[0]); glVertex2i(xp[1], wh-yp[1]); glVertex2i(x, wh-y); glEnd( ); draw_mode = 0; /* reset mode */ couht = 0; } Note that the first mouse click selects triangle mode; subsequent clicks count and store vertices. However, if the mouse is clicked on another button before the third vertex is selected, a new object is selected and drawn. key function renders characters entered from the keyboard to characters on the display. void key(unsigned char k, int xx, int yy) { If (draw_mode != TEXT) return; /* draw characters until mode changes */ glRasterPos2i(rx, ry); glCallList(k); /* Display list for character k */ rx += glutBitmapWidth(GLUT_BITMAP_9_BY_15, k); } A typical display from the middle of a drawing is below: Although paint program is simple and is limited in the facilities that it provides the user, more functionality can be added to it easily say adding the ability to switch from raster to stroke text,
CGV-Unit-3-by-Chandrashekar-MA-Input-and-Interaction.docx