CS-460/560, Assignment # 4
Due Date : 3-15-2010

The only difference in the assignment for CS-460 and CS-560 students is in 
Part A. Here CS-460 students will be working with convex polygons, whereas 
CS-560 students will be working with arbitrary (convex or concave) 

Part A of this assignment is to be an OpenGL program using Microsoft Visual 
C++ (either MFC using wgl or Win32 API using GLUT). Parts B should be an
MFC application that uses the Windows GDI (not OpenGL).

Part A.

In this part of the assignment, using OpenGL in an MFC (wgl approach) or 
Win32 API (GLUT approach) application, you are to implement the scanline 
polygon fill algorithm discussed in class to fill a polygon with a 
two-color pattern defined by the user. For CS-460 students the polygon 
always will always be be convex, but for CS-560 students the program 
should be able to handle both convex and concave polygons. You are to 
implement the algorithm as a Visual C++ function that takes the following 
parameters: the number of vertices in the polygon, the floating point RGB 
values of the two colors to be displayed in the pattern [values between 0 
and 1, to be used in calls to glColor3f()], a 16-element array of 16-bit 
integers (unsigned) that represents the fill pattern to be used, and an
array of x,y coordinates of successive connected vertices of the polygon 
to be filled. To test your fill routine write a short main function that 
defines the following sample polygon:

 int vertices[]=(-190,-190,-20,10,70,-170,100,100,130,-110,220,10,320,-80,
// CS-560

int vertices[]={-100,50,50,150,130,20,130,-100,60,-190,-50,-190,-150,-100};
// CS-460

and the following fill pattern:

 unsigned pat[]={0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,

Here each bit of each element of the pat[] array determines whether the
corresponding pixel inside a 16 X 16 area of the screen is set to the
first RGB value (bit=0) or to that of the second RGB value (bit=1). In other
words, each element defines a row in the pattern matrix, and the value of
each bit in a given element determines which of the two colors the
corresponding pixel in that row will have. If, for example, the two RGB 
values corresponded to red (bit=0 ==> R=1.0, G=0.0, B=0.0) and blue 
(bit=1 ==> R=0.0, G=0.0, B=1.0), in the pattern given above, then the first 
row would have its pixels set as rrrrrrrrbbbbbbbb (r means red, b means 
blue). Thus, when tiled over a polygon, the pattern given above will form 
a checkerboard in which each square is 8 pixels wide and 8 pixels high.

The program should call your fill function to perform the patterned area
fill. For example, if we wanted the polygon defined above to be filled
with a red/blue checkerboard pattern (i.e., using the pattern defined
above), the code might be something like the following:

   fill(13, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, pat, vertices); // CS-560
   // 13 vertices, Red (1.0,0.0,0.0), Blue (0.0,0.0,1.0)

   fill(6, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, pat, vertices); // CS-560
   // 6 vertices, Red (1.0,0.0,0.0), Blue (0.0,0.0,1.0)

Your program should define at least one other different polygon and fill
pattern and call the fill function to fill that polygon with the new

You are to set up your pattern fill in such a way that the pattern
is not "anchored" to a fixed point (e.g., 0,0) on the screen), but
instead to one of the polygon's vertices. Demonstrate that this works by
redrawing and refilling the same polygon translated by some distance that
is not an integral multiple of 16. You should observe that the pattern
"moves with" the polygon.

Part B.

You are to implement a scanline ellipse fill algorithm that will fill
an arbitrary ellipse (oriented along the screen axes) with a pattern
defined by the user. The technique to be used will be a modification of
the scanline polygon fill algorithm discussed in class. The main
difference will be that in moving from one scanline to the next, the
intersection points with the scanline must lie on the arc of the
ellipse. These points can be determined incrementally as in the
midpoint ellipse algorithm discussed in class and that you implemented 
in your last programming assignment.

The same pattern-definition scheme is to be used here as in Part A.

Your implementation should be a function that takes the following parameters: 
the x,y coordinates of the center of the ellipse, the semimajor and semiminor 
axes (xr, yr), the colors to be used in the pattern, and the fill pattern 

   COLORREF r,b;
   r=RGB(255,0,0); g=RGB(0,0,255);
   fillellipse (xcenter, ycenter, xr, yr, r, b, pat);

You should include several other calls to fillellipse() using other ellipses 
and at least one other fill pattern.