1.23k likes | 1.25k Views
CSCE 441 Lecture 2: Scan Conversion of Lines. Jinxiang Chai. 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.
E N D
CSCE 441 Lecture 2:Scan Conversion of Lines Jinxiang Chai
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 2/110
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 3/110
Displays – Smart Phone 8/110
Displays – Oculus 9/110
Image Representation An image is a 2D rectilinear array of Pixels - A width*height array where each entry of the array stores a single pixel - Each pixel stores color information (255,255,255)
Displays – Pixels • Pixel: the smallest element of picture - Integer position (i,j) - Color information (r,g,b) y x (0,0)
Image Representation A pixel stores color information Luminance pixels - gray-scale images (intensity images) - 0-1.0 or 0-255 - 8 bits per pixel Red, green, blue pixels (RGB) - Color images - Each channel: 0-1.0 or 0-255 - 24 bits per pixel
Digital Scan Conversion • Convert graphics output primitives into a set of pixel values for storage in the frame buffer
Outline • How to draw a line? - Digital Differential Analyzer (DDA) - Midpoint algorithm • Required readings - HB 6.1 to 6.8
Problem • Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line
Problem • Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line
Problem • Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line
Special Lines - Horizontal Increment x by 1, keep y constant
Special Lines - Vertical Keep x constant, increment y by 1
Special Lines - Diagonal Increment x by 1, increment y by 1
How about Arbitrary Lines? • How to draw an arbitrary line?
Arbitrary Lines Slope-intercept equation for a line: m: slope b: y-intercept
Arbitrary Lines Slope-intercept equation for a line: How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept
Arbitrary Lines Slope-intercept equation for a line: How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept
Arbitrary Lines • Assume
Arbitrary Lines Assume Other lines by swapping x, y or negating - e.g., reverse the role of x and y if m>1 30/110
Arbitrary Lines Assume Other lines by swapping x, y or negating - e.g., reverse the role of x and y if m>1 - e.g., negate y if 31/110
Arbitrary Lines Assume Other lines by swapping x, y or negating A simple idea: Take steps in x and determine where to fill y 32/110
Digital Differential Analyzer • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi+1 + b
Digital Differential Analyzer Simple algorithm: - sample unit intervals in one coordinate - find the nearest pixel for each sampled point.
Digital Differential Analyzer (DDA) • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) //sample unit intervals in x coordinate DrawPixel ( xi, Round ( yi) ) //find the nearest pixel for each sampled point. xi+1 = xi+ 1 yi+1 = m ( xi + 1 ) + b
DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi + m + b
DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi + b + m
DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi + b + m
DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = yi + m