CSCE 441: Computer Graphics

Spring 2014


Assignment 2: Polygon Scan Conversion and Clipping [150 points]

Due 2/14/14

Purpose:
This assignment is designed to help you become familiar with polygon scan conversion and clipping algorithms. The scan conversion section of this assignment will later be used in Assignment 4 as well.

Description:
In this assignment you will write a program that allows the user to input a set of polygons, scan converts those polygons onto the screen, allows the user to specify a clipping rectangle and displays the clipped polygons. You will NOT be using OpenGL's polygon or clipping commands. Instead, you will use the skeleton code provided. This code provides a 2D array for you to set color values and displays that 2D array. However, you may use OpenGL to draw anything else (lines, points, etc...) as part of the user interface for the assignment.

You should write a program that:
  • allows the user to specify the polygons using the mouse. The user will press the left mouse button to specify a vertex. Each button press will be the next vertex (in order) for the polygon. The final point of the polygon will be specified by pressing the right mouse button. So the user can specify a triangle with two left clicks and one right click. The user may define up to 10 polygons, each with at most 10 vertices (before clipping).
  • scan converts those polygons. Each polygon should be drawn using a different color. You should use an active edge table for this portion of the project.
  • lets the user enter clipping mode by pressing 'C'. Once this key has been pressed, no more polygons can be entered.
  • allows the user to specify the clipping rectangle by clicking and dragging the mouse. The point the user clicks with the left mouse button will be one corner of the rectangle and the point the mouse is released will be the other. The clipping region should be highlighted as the user drags the mouse (draw the four edges of the rectangle) with the polygons the user entered still being shown.
  • allows the user to change the clip region as many times as desired. In each case, the original polygons should be used for clipping and not the already clipped polygons. You may use a polygon clipping algorithm that leaves extraneous edges for concave polygons being clipped.
Do not be surprised if your program runs somewhat slowly.

Grading:
[15] Capturing user polygon input correctly
[55] Scan converting input polygons
[5] Different color for each scanned polygon
[5] Mode transition to clipping mode
[15] Capturing clip rectangle correctly and drawing of clip rectangle
[55] Clipping of polygons and scan conversion of clipped polygons


FAQ

The assignment says that we should use an active edge table to scan convert the polygons. Does that mean we cannot use glBegin(GL_POLYGON)?

As stated in the assignment page, “You will NOT be using OpenGL's polygon or clipping commands.” The entire point of this assignment is to test your knowledge of the polygon drawing and clipping algorithms… not to see if they’re implemented correctly in OpenGL.

What about drawing the edges of the window for the clipping region? Can we use glBegin(GL_LINES)?

Yes. This assignment is not about line drawing. If you would like to use OpenGL to draw horizontal and vertical lines, you may.

When the user drags the mouse during clipping, we need to draw the four edges of the clipping rectangle. Do we also need to change the background color inside the clipping rectangle to highlight it?

You do not need to change the background color inside the clipped rectangle. You should only draw the outline of the rectangle.

Should the polygons the users originally inputs always remain displayed in the screen?

When the user is in clipping mode, only the portions of the polygons inside the clip rectangle should be visible. When the user is not in clipping mode, all of the polygons should be visible.

Each time the user drags and lets go of the mouse, a clipping region is highlighted so nothing outside the clipping rectangle is displayed?

Yes. While the user is dragging the clipping rectangle, you can show all of the polygons until they let go of the mouse button. Then you should clip the polygons and only draw what is inside the clipping rectangle. Alternatively, if your polygon drawing and clipping is fast enough, you can do it in real-time as the user drags the window.