Assignment 2 Help
Assignment 2 Help
2
Getting Started
• Read the project handout carefully!
http://graphics.stanford.edu/courses/cs248-05/proj2.html
3
Development
• The interface is built using a cross platform library
called GLUI.
• You won’t need to change the interface unless you add
features (extra credit). In that case, see the GLUI manual
in /usr/class/cs248/assignments/assignment2/arc.
• You can develop and test this program on Windows or
Mac, just make sure it works on the Linux machines in
Sweet Hall! NOTE: X forwarding the GUI may not
work, but you can use the command-line arguments.
4
The Interface
(The interface is described in detail in README.animgui
README.animgui))
A few key points:
• (Shift + Left click) : add vertices.
• (Left click) : completes the polygon
you’re editing, or allows you to
select and drag vertices.
• (Right click) : drag the whole
polygon
• The program we give you already
handles all the editing functionality,
you just need to work on the
rendering.
When you’re ready to see the scene, hit the “Render” button.
5
Scan Conversion (Rasterization)
The Algorithm (page 98 in Computer Graphics FvDFH second ed.)
• Create an Edge Table for the polygon being rendered, sorted on y.
• Don’t include horizontal edges, they are handled by the edges they connect to (see page 95 in text).
Note: the algorithm in the book (presented here and in course lecture notes) attempts to fix the problems
that occur when polygons share an edge, by not rasterizing the top-most row of pixels along an
edge.
7
Active Edge Table Example
Example of an AET containing edges {FA, EF, DE, CD} on scan line 8:
• 3.1: (y
(y = 8) Get edges from ET bucket y (none in this case, y = 8 has no entry)
• 3.2: Remove from the AET any entries where ymax = y (none here)
• 3.3: Draw scan line. To handle multiple edges, group in pairs: {FA,EF}, {DE,CD}
• 3.4: y = y+1 (y
(y = 8+1 = 9)
• 3.5: Update x for non-vertical edges, as in simple line drawing.
• 3.2: Remove from the AET any entries with ymax = y (remove FA, EF)
• 3.3: Draw scan line between {DE, CD}
• 3.4: y = y+1
y+1 = 10
• 3.5: Update x in {DE, CD}
• 3.1: (y
(y = 10) (Scan line 10 shown in fig 3.28 below)
• And so on…
on…
10
Antialiasing
Scan conversion with super-sampling.
How can we achieve this? Two possibilities:
13
Accumulation Buffer (cont.)
Example (with overlap):
14
Accumulation Buffer (cont.)
Question: Why should we render all polygons at once per frame
(lines 7-10), why not antialias the objects separately and then
blend their images together?
15
Rasterization Notes
Question: Which pixels do we paint in ‘edge’ cases?
• This can result in gaps, which is a form of aliasing. Don’t fix it!
• Antialiasing will fill in the gap
Slivers:
16
Floating Point Issues
Discussed in FvD 19.2.3
17
Floating Point Issues (cont.)
Helpful Hint:
18
Extra Credit
(Extra Credit is fun!!!)
1. Extend the interface to allow interactive scaling and rotations of polygons
around a chosen point. Using matrices is one way…
19
Extra Credit (cont.)
4. Extend the interface to allow the input of polygons with “curved”
boundaries. Curve is approximated by lots of closely spaced vertices that are
still linearly connected. Not too tough, add vertices along mouse path while
mouse button is down.
scissoring clipping 21
Extra Credit (cont.)
8. Implement unweighted area sampling (section 3.17.2 and earlier slide) as
a user selectable alternative to accumulation buffer antialiasing (you
must still implement accumulation buffer).
For even more fun, implement weighted area sampling (section 3.17.3).
22
Development Tips
• Your canvas has (0,0) at the top left, with (canvasWidth-1,
canvasHeight-1) at bottom right. Examples in book have (0,0) at
bottom left. Doesn’t change too much, just be aware.
• If you are comfortable using them, you might find the C++
standard templates useful (especially sorted lists) for handling
lists in your edge table.
23
Questions?
24