CS-460, Assignment # 4
Due Date: 3-15-02
Part A of this assignment is to be implemented in an openGL program using
Microsoft Visual C++ (MFC). Part B should be a second MFC program that uses
the Windows GDI (not openGL).
Part A.
In this part of the assignment, using OpenGL in an MFC application, you
are to implement the scanline polygon fill algorithm discussed in class
to fill a convex polygon with a two-color pattern defined by the user. You
are to write the routine 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 use the following sample polygon:
int vertices[]=(200,-190,350,-100,380,-60,380,200,0,200,-100,-30,0,-190);
and the following fill pattern:
unsigned pat[]={0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,0x00ff,
0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00,0xff00};
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
color that corresponds to the first RGB values (bit=0) or to that of the
second RGB values (bit=1). In other words, each element of the pat[] array
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.
The program should call your fill function to perform the pattern 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 call to the fill function might be something like the
following:
fill(13, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, pat, vertices);
// 13 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
pattern. The details of how the displays are initiated (e.g., with menu
items, keyboard presses, etc.) are up to you.
Part B.
In this part of the assignment you are to implement the "scanline
boundary fill" algorithm (Dino's Demo) discussed briefly in class. The
Windows GDI (not openGL) should be used in this part of the assignment.
You may assume that the boundary to be filled is convex -- that is,
there will never be a situation where there is more than one pixel
above and one pixel below the current line that needs to be pushed
onto the stack. You may also take the fill color and the boundary color
to be the same. Your implementation is to be a function that takes a
seed point (xseed,yseed) and the boundary/fill color (bf_Color):
slb_fill (int xseed, int yseed, COLORREF bf_Color);
Test your routine on several circles that have been drawn in a given
color. For example:
...
COLORREF m_color = RGB(0,255,0); // green boundary-fill color
pDC = GetDC();
CPen pen(PS_SOLID, 1, m_color);
CPen *pPenOld = pDC->SelectObject(&Pen);
pDC->Ellipse(hDC,100,100,400,400);
slb_fill(250,200,m_color); // this is the call to your function
...
// Do more circles as above