Presentation is loading. Please wait.

Presentation is loading. Please wait.

Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();

Similar presentations


Presentation on theme: "Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();"— Presentation transcript:

1 Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity(); gluOrtho2D(-1,1,-1,1); glBegin(GL_QUADS); glColor3f(1,1,0); glVertex2i(-0.5,-0.5); glVertex2i(+0.5,0); glVertex2i(+0.5,+0.5); glVertex2i(-0.5,+0.5); glEnd(); }

2 2D Graphics Pipeline Object Local Coordinates Object World Coordinates Modeling transformation (next page) Graphics processing consists of many stages:

3 2D Graphics Pipeline (2) Object World Coordinates Object subset window to viewport mapping Object Screen coordinates RasterizationDisplay Applying world window Clipping Simple 2D Drawing Pipeline

4 Clipping and Rasterization OpenGL does these for you – no explicit OpenGL functions needed for doing clipping and rasterization Clipping – Remove objects that are outside the world window Rasterization (scan conversion) – Convert high level object descriptions to pixel colors in the frame buffer

5 2D Point Clipping Determine whether a point (x,y) is inside or outside of the world window? (xmin, ymin) (xmax, ymax) If (xmin <= x <= xmax) and (ymin <= y <= ymax) then the point (x,y) is inside else the point is outside

6 2D Line Clipping Determine whether a line is inside, outside, or partially inside If a line is partially inside, we need to display the inside segment (xmin, ymin) (xmax, ymax)

7 Trivial Accept Case Lines that are clearly inside the world window - what are they? (Xmin, Ymin) (Xmax, Ymax) p1 p2 Xmin <= P1.x, P2.x <=xmax Ymin <= P1.y, P2.y <= Ymax

8 Trivial Reject Case Lines that are clearly outside the world window – what are they? p1 p2  p1.x, p2.x <= Xmin OR  p1.x, p2.x >= Xmax OR  p1.y, p2.y <= ymin OR  p1.y, p2.y >= ymax

9 Non-Trivial Cases Lines that cannot be trivially rejected or accepted One point inside, one point outside Both points are outside, but not “trivially” outside Need to find the line segments that are inside p1 p2

10 Rasterization (Scan Conversion) Convert high-level geometry description to pixel colors in the frame buffer Viewport Transformation Rasterization

11 Rasterization Algorithms A fundamental computer graphics function Determine the pixels’ colors, illuminations, textures, etc. Implemented by graphics hardware Rasterization algorithms Lines Circles Triangles Polygons

12 Rasterize Lines Why learn this? Understand the discrete nature of computer graphics Write pure device independent graphics programs (Palm graphics) Become a graphics system developer

13 Line Drawing Algorithm (1) 0 1 2 3 4 5 6 7 8 9 10 11 12 8765432187654321 Line: (3,2) -> (9,6) ?

14 Line Drawing Algorithm (2) Slope-intercept line equation Y = mx + b Given two end points (x0,y0), (x1, y1), how to compute m and b? m = (y1-y0) / (x1 – x0) = dy / dx (x0,y0) (x1,y1) dx dy b = y1 – m * x1

15 Line Drawing Algorithm (3) (x0,y0) (x1,y1) dx dy Given the line equation y = mx + b, and end points (x0,y0) (x1, y1) Walk through the line: starting at (x0,y0) If we choose the next point in the line as X = x0 +  x Y = ? Y = y0 +  x * m = y0 +  x * (dy/dx)

16 Line Drawing Algorithm (4) (x0, y0) X = x0 + 1 Y = y0 + 1 * m Illuminate pixel (x, int(Y)) X = X + 1 Y = Y + 1 * m Illuminate pixel (x, int(Y)) … Until X == x1 (x1,y1) X = x0 Y = y0 Illuminate pixel (x, int(Y))

17 Line Drawing Algorithm (5) How about a line like this? Can we still increment X by 1 at each Step? The answer is No. Why? How to fix it ? Increment Y We don’t get enough samples

18 Line Drawing Algorihtm (6) Y = y0 + 1 X = x0 + 1 * 1/m Illuminate pixel (x, int(Y)) Y = Y + 1 X = X + 1 /m Illuminate pixel (x, int(Y)) … Until Y == y1 X = x0 Y = y0 Illuminate pixel (x, int(Y)) (x1,y1) (x0,y0)

19 Line Drawing Algorithm (7) The above is the simplest line drawing algorithm Not very efficient Optimized algorithms such integer DDA and Bresenhan algorithm are typically used Not the focus of this course

20 Triangle Rasterization Issues Sliver

21 Triangle Rasterization Issues Moving Slivers

22 Triangle Rasterization Issues Shared Edge Ordering

23 Edge Equations An edge equation is simply the equation of the line defining that edge Q: What is the implicit equation of a line? A: Ax + By + C = 0 Q: Given a point ( x,y ), what does plugging x & y into this equation tell us? A: Whether the point is: On the line: Ax + By + C = 0 “Above” the line: Ax + By + C > 0 “Below” the line: Ax + By + C < 0

24 Edge Equations Edge equations thus define two half- spaces:

25 Edge Equations And a triangle can be defined as the intersection of three positive half- spaces: A 1 x + B 1 y + C 1 < 0 A 2 x + B 2 y + C 2 < 0 A 3 x + B 3 y + C 3 < 0 A 1 x + B 1 y + C 1 > 0 A 3 x + B 3 y + C 3 > 0 A 2 x + B 2 y + C 2 > 0

26 Edge Equations So…simply turn on those pixels for which all edge equations evaluate to > 0:


Download ppt "Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();"

Similar presentations


Ads by Google