1.15k likes | 1.17k Views
CSCE 441: Computer Graphics Scan Conversion of Polygons. Jinxiang Chai. GL_LINES. GL_POLYGON. GL_LINE_STRIP. GL_LINE_LOOP. GL_POINTS. GL_TRIANGLES. GL_QUADS. GL_TRIANGLE_FAN. GL_TRIANGLE_STRIP. GL_QUAD_STRIP. OpenGL Geometric Primitives.
E N D
CSCE 441: Computer GraphicsScan Conversion of Polygons Jinxiang Chai
GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP OpenGL Geometric Primitives • All geometric primitives are specified by vertices
GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP OpenGL Geometric Primitives • All geometric primitives are specified by vertices
GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP OpenGL Geometric Primitives • All geometric primitives are specified by vertices
Drawing General Polygons • How to draw every interior pixel? ?
Drawing General Polygons • How to draw every interior pixel?
Drawing Curved Objects • How to draw every interior pixels?
Outline • Methods for drawing polygons or curved objects - Scanline conversion of polygons - Boundary-fill - Flood-fill • Required readings: - HB 6-10 to 6-14
Drawing Rectangles Which pixels should be filled?
Drawing Rectangles Is this correct?
Drawing Rectangles What if two rectangles overlap?
Drawing Rectangles Is this correct?
Drawing Rectangles Overlap!!! Is this correct?
Drawing Rectangles Solution: Exclude pixels on top and right
Drawing Rectangles Artifacts are possible
General Polygons – Basic Idea • How to draw every interior pixel? - process the screen scan line from the bottom of the boundaries to the top - draw every interior pixel for each scan line.
General Polygons – Basic Idea • How to draw every interior pixel for a scan line?
General Polygons – Basic Idea • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges
General Polygons – Basic Idea • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges
General Polygons – Basic Idea • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges • What about this line?
General Polygons – Basic Idea • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges • Draw odd intervals only
General Polygons – Basic Idea • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges • Draw odd intervals only • Don’t fill top/right • Edges may NOT match • with line drawing algorithm
General Polygons – Basic Idea Use coherence to speed up • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges • Draw odd intervals only
General Polygons – Basic Idea Use coherence to speed up • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges • Draw odd intervals only Edges intersecting one scan line are mostly same as those intersecting previous scan line
General Polygons – Basic Idea Use coherence to speed up • Intersect scan lines with edges • Find ranges along x • Fill interior of those ranges • Draw odd intervals only The x-value of an intersection with one scan line is close to the intersection with the previous one
How to store polygon edges? Associate polygon edges with scan lines Scan Lines
How to store polygon edges? Associate polygon edges with scan lines: use the lowest end point of a edge to find the corresponding scan line Scan Lines
How to store polygon edges? Associate polygon edges with scan lines: use the lowest end point of a edge to find the corresponding scan line Scan Lines
How to store polygon edges? Associate polygon edges with scan lines: use the lowest end point of a edge to find the corresponding scan line Scan Lines
General Polygons – Data Structures • Sorted Edge Table: Store a linked-list per scan-line. Insert edges into table at scan-line associated with lowest end-point. Scan Lines Edges
General Polygons – Example C Sorted Edge Table B D G F E A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Example C Sorted Edge Table B D G F E A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Example C Sorted Edge Table B D G AB AG F E A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Example C Sorted Edge Table B D G AB AG F E Exclude horizontal edges! A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Example C Sorted Edge Table B D G FG ED AB AG F E A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Example C Sorted Edge Table B D CD G FG ED AB AG F E A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG F E A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG F E Which edges are intersecting with the current scan line? A Insert edges into table at scan-line associated with lowest end-point!
General Polygons – Data Structures • Active Edge List: List of all edges intersecting current scan-line sorted by their x-values Edges
Edge mazY currentX xIncr General Polygons – Data Structures • Edge: maxY: highest y-value currentX: x-value of end-point with lowest y-value xIncr: 1 / slope
Edge mazY currentX xIncr Scan line intersection Scan line yk+1 Scan line yk
Edge mazY currentX xIncr Scan line intersection Scan line yk+1 Scan line yk • with xk and 1/m, we can efficiently compute the next endpoint! • - increment yk by 1 • - increment xk by 1/m • with yend, we know when to end the edge.
General Polygons – Data Structures • Edge: maxY: highest y-value currentX: x-value of end-point with lowest y-value xIncr: 1 / slope Edge mazY currentX xIncr Horizontal edges will not be used!!!
General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill interior pixels on the current scan line Increment x-values on edges in Active Edge List Increment line
General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill interior pixels on the current scan line Increment x-values on edges in Active Edge List Increment line Incrementally update the coordinates of intersection points!
General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E A
General Polygons – Algorithm line = 0 While (line < height ) Add edges to Active Edge List from Sorted Edge Table starting at line Remove edges that end at line Fill pixels Increment x-values on edges in Active Edge List Increment line
General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG A maxY currentX xIncr
General Polygons – Example C Sorted Edge Table B BC D CD G FG ED AB AG Active Edge List F E AB AG A maxY currentX xIncr