Graphics Output Primitives Hearn & Baker Chapter 3. Some slides are taken from Robert Thomsons notes.

Size: px
Start display at page:

Download "Graphics Output Primitives Hearn & Baker Chapter 3. Some slides are taken from Robert Thomsons notes."

Transcription

1 Graphics Output Primitives Hearn & Baker Chapter 3 Some slides are taken from Robert Thomsons notes.

2 OVERVIEW Coordinate reference frames OpenGL Point & Line functions Line drawing algorithms Curve drawing algorithms Fill-area primitives Pixel-array primitives Character primitives Picture Partitioning

3 Basic Elements Three basic elements Scalars Vectors Points Develop mathematical operations among them Define basic primitives: Points Line segments

4 Basic Elements Points are associated with locations in space Vectors have magnitude and direction represent displacements between points, or directions Points, vectors, and operators that combine them are the common tools for solving many geometric problems that arise in Geometric Modeling, Computer Graphics, Animation, Visualization, and Computational Geometry.

5 3.1 COORDINATE REFERENCE FRAMES To describe a picture, we first decide upon A convenient Cartesian coordinate system, called the world-coordinate reference frame, which could be either 2D or 3D. We then describe the objects in our picture by giving their geometric specifications in terms of positions in world coordinates. e.g., we define a straight-line segment with two endpoint positions, and a polygon is specified with a set of positions for its vertices. These coordinate positions are stored in the scene description along with other info about the objects, such as their color and their coordinate extents coordinate extents are the minimum and maximum x, y, and z values for each object. A set of coordinate extents is also described as a bounding box for an object. For a 2D figure, the coordinate extents are sometimes called its bounding rectangle.

6 3.1 COORDINATE REFERENCE FRAMES Objects are then displayed by passing the scene description to the viewing routines which identify visible surfaces and map the objects to the frame buffer positions and then on the video monitor. The scan-conversion algorithm stores info about the scene, such as color values, at the appropriate locations in the frame buffer, and then the scene is displayed on the output device. locations on a video monitor are referenced in integer screen coordinates, which correspond to the integer pixel positions in the frame buffer.

7 3.1 COORDINATE REFERENCE FRAMES Scan-line algorithms for the graphics primitives use the coordinate descriptions to determine the locations of pixels E.g., given the endpoint coordinates for a line segment, a display algorithm must calculate the positions for those pixels that lie along the line path between the endpoints. Since a pixel position occupies a finite area of the screen the finite size of a pixel must be taken into account by the implementation algorithms. for the present, we assume that each integer screen position references the centre of a pixel area.

8 3.1 COORDINATE REFERENCE FRAMES Once pixel positions have been identified the color values must be stored in the frame buffer Assume we have available a low-level procedure of the form setpixel (x, y); stores the current color setting into the frame buffer at integer position (x, y), relative to the position of the screen-coordinate origin getpixel (x, y, color); retrieves the current frame-buffer setting for a pixel location; parameter color receives an integer value corresponding to the combined RGB bit codes stored for the specified pixel at position (x,y). additional screen-coordinate information is needed for 3D scenes. For a two-dimensional scene, all depth values are 0.

9 3.1 Absolute and Relative Coordinate Specifications So far, the coordinate references discussed are given as absolute coordinate values values are actual positions wrt origin of current coordinate system some graphics packages also allow positions to be specified using relative coordinates as an offset from the last position that was referenced (called the current position)

10 Specifying A 2D World-coordinate Reference Frame in OpenGL World-coordinate limits for a display window, as specified in the glortho2d function. gluortho2d function specifies an orthogonal projection, we need also to be sure that the coordinate values are placed in the OpenGL projection matrix. In addition, we could assign the identity matrix as the projection matrix before defining the world-coordinate range. This would ensure that the coordinate values were not accumulated with any values we may have previously set for the projection matrix. glmatrixmode (GL_PROJECTION); glloadidentity ( ); glu0rtho2d (xmin, xmax, ymin, ymax); The display window will then be referenced by coordinates (xmin, ymin) at the lower-left corner and by coordinates (xmax, ymax) at the upper-right corner, as shown in Fig. 3-2.

11

12 3-3 OpenGL POINT FUNCTIONS To specify the geometry of a point, we simply give a coordinate position in the world reference frame. Then along with other geometric descriptions this data is passed to the viewing routines. Unless we specify other attribute values, OpenGL primitives are displayed with a default size and color. The default color for primitives is white and the default point size is equal to the size of one screen pixel.

13 3-3 OpenGL POINT FUNCTIONS A glvertex function must be placed between a glbegin function and a glend function. The argument of the glbegin function is used to identify the kind of output primitive that is to be displayed For point plotting, the argument of the glbegin function is the symbolic constant GL_POINTS. and glend takes no arguments. glbegin (GL_POINTS); glvertex* ( ); glend ( ) ;

14 3-3 OpenGL POINT FUNCTIONS glvertex* ( ); state the coordinate values for a single position where the asterisk (*) indicates that suffix codes are required for this function. These suffix codes are used to identify the spatial dimension, 2, 3, or 4 (indicates a scaling factor for the Cartesian-coordinate values.) the numerical data type i (integer), s (short), f (float), and d (double) and a possible vector form for the coordinate specification append a third suffix code: v (for "vector"). the glvertex function is used in OpenGL to specify coordinates for any point position. In this way, a single function is used for point, line, and polygon specifications

15 3-3 OpenGL POINT FUNCTIONS. glbegin (GL_POINTS); glvertex2i (50, 100); glvertex2i (75, 150); glvertex2i (100, 200); g1end ( ) ; Alternatively, we could specify the coordinate values for the preceding points in arrays such as int point1 [ ] = {50, 100}; int point2 [ ] = {75, 150}; int point3 [ ] = {100, 200}; and call the OpenGL functions for plotting the three points as glbegin (GL_POINTS); glvertex2iv (pointl); glvertex2iv (point2); glvertex2iv (point3); glend ( ) ;

16 3-3 OpenGL POINT FUNCTIONS. class wcpt2d { public: GLfloat x, y; }; Using this class definition, we could specify a 2D, worldcoordinate point position with the statements wcpt2d pointpos; pointpos.x = ; pointpos.y = 45.30; glbegin (GL_POINTS); glvertex2f (pointpos.x, pointpos.y); glend ( )

17 3-4 OpenGL LINE FUNCTIONS now we use a symbolic constant as the argument for the glbegin function that interprets a list of positions as the endpoint coordinates for line segments. A set of straight-line segments between each successive pair of endpoints in a list is generated using the primitive line constant GL_LINES glbegin (GL_LINES): glvertex2iv(pl); glvertex2iv(p2); glvertex2iv(p3); glvertex2iv(p4); glvertex2iv(p5); glend ( ); Nothing is displayed if we do not list at least two coordinate positions p2 p3 p4 pl

18 3-4 OpenGL LINE FUNCTIONS. glbegin (GL_LINE_STRIP); glvertex2iv (pl); glvertex2iv (p2); glvertex2iv (p3); glvertex2iv (p4); p3 glvertex2iv (p5); p5 pl glend ( ) The first line segment in the polyline is displayed between the first endpoint and the second endpoint; the second line segment is between the second and third endpoints; and so forth, up to the last line endpoint. p2 p4

19 3-4 OpenGL LINE FUNCTIONS gibegin (GL_LINE_LOOP); glvertex2iv (pl); glvertex2iv (p2); glvertex2iv (p3); glvertex2iv (p4); glvertex2iv (p5); glend ( ) ; produces a closed polyline. the last coordinate endpoint in the sequence is connected to the first coordinate endpoint of the polyline. p5 p2 p3 p4 pl

20 3-5 LINE-DRAWING ALGORITHMS A straight-line segment in a scene is defined by the coordinate positions for the endpoints of the segment. 1. To display the line on a raster monitor, the graphics system must first project the endpoints to integer screen coordinates and determine the nearest pixel positions along the line path between the two endpoints. 2. Then the line color is loaded into the frame buffer at the corresponding pixel coordinates. 3. Reading from the frame buffer, the video controller plots the screen pixels. This process digitizes the line into a set of discrete integer positions that, in general, only approximates the actual line path.

21 3-5 LINE-DRAWING ALGORITHMS On raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical directions are constrained by pixel separations. That is, we must "sample" a line at discrete positions and determine the nearest pixel to the line at sampled position. Sampling is measuring the values of the function at equal intervals Idea: A line is sampled at unit intervals in one coordinate and the corresponding integer values nearest the line path are determined for the other coordinate.

22 Towards the Ideal Line We can only do a discrete approximation Illuminate pixels as close to the true path as possible, consider bi-level display only Pixels are either lit or not lit In the raster line alg., we sample at unit intervals and determine the closest pixel position to the specified line path at each step

23 What is an ideal line Must appear straight and continuous Only possible with axis-aligned and 45 o lines Must interpolate both defining end points Must have uniform density and intensity Consistent within a line and over all lines What about anti-aliasing? Aliasing is the jagged edges on curves and diagonal lines in a bitmap image. Anti-aliasing is the process of smoothing out those jaggies. Graphics software programs have options for anti-aliasing text and graphics. Enlarging a bitmap image accentuates the effect of aliasing. Must be efficient, drawn quickly Lots of them are required

24 Simple Line The Cartesian slope-intercept equation for a straight line is : y = mx + b with m as the slope of the line and b as the y intercept. Simple approach: increment x, solve for y

25 Line-Drawing Algorithms: DDA Bresenham s Midpoint Algorithm

26 Algorithms for displaying lines are based on the Cartesian slope-intercept equation y = m.x + b where m and b can be calculated from the line endpoints: m = (y1-y0) / (x1-x0) b = y0 - m. x0 For any x interval x along a line the corresponding y = m.x y interval y 1 y 0 x 0 x 1

27 Simple Line Based on slope-intercept algorithm from algebra: y = mx + b Simple approach: increment x, solve for y Floating point arithmetic required

28 Does it Work? It works for lines with a slope of 1 or less, but doesn t work well for lines with slope greater than 1 lines become more discontinuous in appearance and we must add more than 1 pixel per column to make it work. Solution? - use symmetry.

29 Modify algorithm per octant OR, increment along x-axis if dy<dx else increment along y-axis

30 DDA Algorithm The digital differential analyser (DDA) is a scan-conversion line algorithm based on using x or y. A line is sampled at unit intervals in one coordinate and the corresponding integer values nearest the line path are determined for the other coordinate.

31 Line with positive slope If m<=1, Sample at unit x intervals (dx=1) Compute successive y values as y k+1 =y k +m 0<=k<=x end -x 0 Increment k by 1 for each step Round y to nearest integer value. If m>1, Sample at unit y intervals (dy=1) Compute successive x values as x k+1 =x k +1/m 0<=k<=y end -y 0 Increment k by 1 for each step Round x to nearest integer value.

32 inline int round (const float a) { return int (a + 0.5); } void linedda (int x0, int y0, int xend, int yend) { int dx = xend - x0, dy = yend - y0, steps, k; float xincrement, yincrement, x = x0, y = y0; if (fabs (dx) > fabs (dy)) steps = fabs (dx); else steps = fabs (dy); xincrement = float (dx) / float (steps); yincrement = float (dy) / float (steps); } setpixel (round (x), round (y)); for (k = 0; k < steps; k++) { x += xincrement; y += yincrement; setpixel (round (x), round (y)); }

33 DDA algorithm Need a lot of floating point arithmetic. 2 round s and 2 adds per pixel. Is there a simpler way? Can we use only integer arithmetic? Easier to implement in hardware.

34 Bresenham's line algorithm Accurate and efficient Uses only incremental integer calculations The method is described for a line segment with a positive slope less than one The method generalizes to line segments of other slopes by considering the symmetry between the various octants and quadrants of the xy plane

35 Bresenham's line algorithm Specified line path Decide what is the next pixel position (11,11) or (11,12)

36 Illustrating Bresenham s Approach y k+3 y k+2 y=mx+b For the pixel position x k+1 =x k +1, which one we should choose: (x k+1,y k ) or (x k+1, y k+1 ) y k+1 y k x k x k+1 x k+2 x k+3

37 Bresenham s Approach y k+1 y y k d upper d lower y=m(x k + 1)+b d lower =y-y k =m(x k + 1)+b-y k x k+1 d lower - d upper = 2m(x k + 1)-2y k +2b-1 d upper =(y k +1)-y = y k +1 -m(x k + 1)-b Rearrange it to have integer calculations: m=δy/δx Decision parameter: p k = Δx(d lower - d upper )=2Δy.x k - 2Δx. y k + c

38 The Decision Parameter Decision parameter: p k = Δx(d lower - d upper )=2Δy.x k - 2Δx. y k + c p k has the same sign with d lower - d upper since Δx>0. c is constant and has the value c= 2Δy + Δx(2b-1) c is independent of the pixel positions and is eliminated from decision parameter p k. If d lower < d upper then p k is negative. Plot the lower pixel (East) Otherwise Plot the upper pixel (North East)

39 At step k+1 Succesive decision parameter p k+1 = 2Δy.x k+1-2δx. y k+1 + c Subtracting two subsequent decision parameters yields: p k+1 -p k = 2Δy.(x k+1 -x k ) - 2Δx. (y k+1 -y k ) x k+1 =x k +1 so p k+1 = p k + 2Δy - 2Δx. (y k+1 -y k ) y k+1 -y k is either 0 or 1 depending on the sign of p k First parameter p 0 p 0 =2 Δy - Δx

40 Bresenham's Line-Drawing Algorithm for I m I < 1 1. Input the twoline endpoints and store the left endpoint in (x 0,y 0 ). 2. Load (x 0,y 0 ) into the frame buffer; that is, plot the first point. 3. Calculate constants Δx, Δy, 2Δy, and 2Δy - 2Δx, and obtain the starting value for the decision parameter as p 0 =2 Δy - Δx 4. At each x k along the line, starting at k = 0, perform the following test: If p k < 0, the next point to plot is (x k+1, y k ) and p k+1 =p k + 2Δy Otherwise, the next point to plot is (x k+1, y k+1 ) and p k+1 =p k + 2Δy - 2Δx 5. Repeat step 4 Δx -1 times.

41 Trivial Situations: Do not need Bresenham m 0 horizontalline m 1 line y x m vertical line

42 Example Draw the line with endpoints (20,10) and (30, 18). Δx=30-20=10, Δy=18-10=8, p 0 = 2Δy Δx=16-10=6 2Δy=16, and 2Δy - 2Δx=-4 Plot the initial position at (20,10), then

43

44 Example Line end points: Deltas: dx 4; dy ( x y ) (5,8); x, y ), 0 0 ( (9,11) initially p(5, 8) 2( dy) -( dx) p 2 NE

45 Graph

46 Continue the process

47 Graph

48 Graph

49 Graph

50 /* Bresenham line-drawing procedure for m < 1.0. */ void linebres (int x0, int y0, int xend, int yend) { int dx = fabs (xend - x0), dy = fabs(yend - y0); int x, y, p = 2 * dy - dx; int twody = 2 * dy, twodyminusdx = 2 * (dy - dx); } /* Determine which endpoint to use as start position. */ if (x0 > xend) { x = xend; y = yend; xend = x0; } else { x = x0; y = y0; } setpixel (x, y); while (x < xend) { x++; if (p < 0) p += twody; else { y++; p += twodyminusdx; } setpixel (x, y); }

51 Line-drawing algorithm should work in every octant, and special cases m<-1 m>1 0>m>-1 0<m<1 0<m<1 0>m>-1 m>1 m<-1

52 Simulating the Bresenham algorithm in drawing 8 radii on a circle of radius 20 Horizontal, vertical and 45 radii handled as special cases

53 Circle / Curve Drawing in OpenGL Routines for drawing circles or ellipses are not included in the OpenGL core library. Does include functions for displaying Bezier splines GLU (OpenGL Utility) library has some routines for drawing spheres, cylinders, B-splines. Rational B-splines can be used to display circles and ellipses. GLUT (OpenGL Utility Toolkit) has some routines to display 3D shapes such as cones, spheres All these discussed later

54 Another method: Approximate it using a polyline.

55 Scan Converting Circles ( x x c ) 2 ( y y c ) 2 R 2 y y c R 2 ( x x c ) 2 Explicit: y = f(x) y R x 2 2 We could draw a quarter circle by incrementing x from 0 to R in unit steps and solving for +y for each step. Method needs lots of computation, and gives non-uniform pixel spacing

56 Parametric: x y Scan Converting Circles Rcos Rsin Draw quarter circle by stepping through the angle from 0 to 90 -avoids large gaps but still unsatisfactory -How to set angular increment Computationally expensive trigonometric calculations

57 Scan Converting Circles Implicit: f(x,y) = x 2 +y 2 -R 2 If f(x,y) = 0 then it is on the circle. f(x,y) > 0 then it is outside the circle. f(x,y) < 0 then it is inside the circle. Try to adapt the Bresenham midpoint approach Again, exploit symmetries

58

59 Generalising the Bresenham midpoint approach Set up decision parameters for finding the closest pixel to the cırcumference at each sampling step Avoid square root calculations by considering the squares of the pixel separation distances Use direct comparison without squaring. Adapt the midpoint test idea: test the halfway position between pixels to determine if this midpoint is inside or outside the curve This gives the midpoint algorithm for circles Can be adapted to other curves: conic sections

60 Eight-way Symmetry - only one octant s calculation needed

61 The 2 nd Octant is a good arc to draw It is a well-defined function in this domain single-valued no vertical tangents: slope 1 Lends itself to the midpoint approach only need consider E or SE Implicit formulation F(x,y) = For (x,y) on the circle, F(x,y) = 0 x 2 + y 2 r 2 F(x,y) > 0 (x,y) Outside F(x,y) < 0 (x,y) Inside

62 Choose E or SE Decision variable d is x 2 + y 2 r 2 Then d = F(M) 0 SE Or d = F(M) < 0 E

63 F (M) 0 SE current pixel ideal curve E M SE

64 F (M) < 0 E E ideal curve M SE

65 Decision Variable p As in the Bresenham line algorithm we use a decision variable to direct the selection of pixels. Use the implicit form of the circle equation p = F (M ) = x 2 + y 2 r 2

66 1 2 Midpoint coordinates are ( x k 1, yk )

67 Assuming we have just plotted point at (xk,yk) we determine whether move E or SE by evaluating the circle function at the midpoint between the two candidate pixel positions p k F ( x circ k ( x k 1) 2 1, y ( y k k 1 ) 2 1 ) 2 2 r 2 pk is the decision variable if pk <0 the midpoint is inside the circle Thus the pixel above the midpoint is closer to the ideal circle, and we select pixel on scan line yk. i.e. Go E

68 If pk >0 the midpoint is outside the circle. Thus the pixel below the midpoint is closer to the ideal circle, and we select pixel on scan line yk-1. i.e. Go SE Calculate successive decision parameter values p by incremental calculations. p k1 F [( x circ k ( x k1 1) 1] 1, 2 y k 1 ( y k1 1 ) 2 1 ) 2 2 r 2

69 recursive definition for successive decision parameter values p 1 ) ( ) ( 1) 2( ) 2 1 ( 1] 1) [( ) 2 1 1, ( k k k k k k k k k k k circ k y y y y x p p r y x y x F p Where yk+1 = yk if p<0 (move E) yk+1 = yk-1 if p>0 (move SE) yk+1 and xk+1 can also be defined recursively

70 Initialisation x 0 = 0, y 0 = r Initial decision variable found by evaluating circle function at first midpoint test position p F (1, r 1 0 circ 1 ( r 5 4 r 1 ) 2 ) 2 For integer radius r p 0 can be rounded to p 0 =1-r since all increments are integer. 2 r 2

71

72 Midpoint Circle Algorithm (cont.)

73 r=10 Example

74 Conic Sections A conic section, or conic, is any figure that can be formed by slicing a double cone with a plane Parabola Circle Ellipse Hyperbola

75 General equation of a Conic Section Ax 2 By 2 Cxy Dx Ey F 0 Parabola: A = 0 OR B = 0 Circle: Ellipse: Hyperbola: A = B AB, but both have the same sign A and B have different signs

76 Ellipses F1 d1 F2 d2 P = (x,y) Ellipse generated about foci F1 and F2 d1 + d2 = constant

77 Scan Converting Ellipses F x y b x a y a b (, ) 0 b a a is the length of the semi-major axis along the x axis. b is the length of the semi-minor axis along the y axis. The midpoint algorithm can also be applied to ellipses. For simplicity, we draw only the arc of the ellipse that lies in the first quadrant, the other three quadrants can be drawn by symmetry

78 Regions

79 Region 1

80 Region 2

81 Fill area : an area that is filled with solid colour or pattern

82

83 Identifying a concave polygon has at least one interior angle >180 degrees extensions of some edges will intersect other edges One test: Express each polygon edge as a vector, with a consistent orientation. Can then calculate cross-products of adjacent edges

84 Identifying a concave polygon When polygon edges are oriented with an anticlockwise sense z coordinate of the cross product at convex vertex has positive sign concave vertex gives negative sign

85 Normals Every plane has a vector n normal (perpendicular, orthogonal) to it n = u x v (vector cross product) u v P x y y x z x x z y z z y v u v u v u v u v u v u v u

86 Vector method for splitting concave polygons E 5 E 6 E 1 E 2 E E 4 E 1 =(1,0,0) E 2 =(1,1,0) E 3 =(1,-1,0) E 4 =(0,2,0) E 5 =(-3,0,0) E 6 =(0,-2,0) All z components have 0 value. Cross product of two vectors E j xe k is perpendicular to them with z component E jx E ky -E kx E jy

87 Example continued E 6 E 5 E 4 E 1 xe 2 = (0,0,1) E 2 xe 3 = (0,0,-2) E 3 xe 4 = (0,0,2) E 4 xe 5 = (0,0,6) E 5 xe 6 = (0,0,6) E 6 xe 1 = (0,0,2) E 2 E 3 E Since E 2 xe 3 has negative sign, split the polygonalong the line of vector E 2

88 Rotational method Rotate the polygon so that each vertex in turn is at coordinate origin. If following vertex is below the x axis, polygon is concave. Split the polygon by x axis.

89 E 5 E 6 E 4 E 2 E 3 E 1

90

91

92 Inside-Outside? nonzero winding-number rule A winding number is an attribute of a point with respect to a polygon that tells us how many times the polygon encloses (or wraps around) the point. It is an integer, greater than or equal to 0. Regions of winding number 0 (unenclosed) are obviously outside the polygon, and regions of winding number 1 (simply enclosed) are obviously inside the polygon. Initially 0 +1: edge crossing the line from right to left -1: left to right

93 Winding Number Count clockwise encirclements of point winding number = 1 winding number = 2 Alternate definition of inside: inside if winding number 0

94 Polygon tables store descriptions of polygon geometry and topology, and surface parameters: colour, transparency, light-reflection organise in 2 groups geometric data attribute data

95 Polygon Tables: Geometric data Data can be used for consistency checking Additional geometric data stored: slopes, bounding boxes

96 Shared Edges Vertex lists will draw filled polygons correctly but if we draw the polygon by its edges, shared edges are drawn twice Can store mesh by edge list

97

98 Inward and Outward Facing Polygons The order {v 1, v 6, v 7 } and {v 6, v 7, v 1 } are equivalent in that the same polygon will be rendered by OpenGL but the order {v 1, v 7, v 6 } is different The first two describe outwardly facing polygons Use the right-hand rule = counter-clockwise encirclement of outward-pointing normal OpenGL can treat inward and outward facing polygons differently

99 OpenGL Primitives GL_POLYGON GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUADSTRIP

100

101

102

103

104

105

106 Modelling a Cube 3.17 : OpenGL vertex arrays Model a color cube for rotating cube program Define global arrays for vertices and colors GLfloat vertices[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};

107 Drawing a polygon from a list of indices Draw a quadrilateral from a list of indices into the array vertices and use color corresponding to first index void polygon(int a, int b, int c, int d) { glbegin(gl_polygon); glcolor3fv(colors[a]); glvertex3fv(vertices[a]); glvertex3fv(vertices[b]); glvertex3fv(vertices[c]); glvertex3fv(vertices[d]); glend(); }

108 Draw cube from faces void colorcube( ) { polygon(0,3,2,1); polygon(2,3,7,6); polygon(0,4,7,3); polygon(1,2,6,5); polygon(4,5,6,7); polygon(0,1,5,4); } Note that vertices are ordered so that we obtain correct outward facing normals 0 3

109 Efficiency The weakness of our approach is that we are building the model in the application and must do many function calls to draw the cube Drawing a cube by its faces in the most straight forward way requires 6 glbegin, 6 glend 6 glcolor 24 glvertex More if we use texture and lighting

110 Vertex Arrays OpenGL provides a facility called vertex arrays that allows us to store array data in the implementation Six types of arrays supported Vertices Colors Color indices Normals Texture coordinates Edge flags We will need only colors and vertices

111 Initialization Using the same color and vertex data, first we enable glenableclientstate(gl_color_array); glenableclientstate(gl_vertex_array); Identify location of arrays glvertexpointer(3, GL_FLOAT, 0, vertices); 3d arrays stored as floats data array data contiguous (offset) glcolorpointer(3, GL_FLOAT, 0, colors);

112 Mapping indices to faces Form an array of face indices GLubyte cubeindices[24] = {0,3,2,1,2,3,7,6 0,4,7,3,1,2,6,5,4,5,6,7,0,1,5,4}; Each successive four indices describe a face of the cube Draw through gldrawelements which replaces all glvertex and glcolor calls in the display callback

113 Drawing the cube Method 1: what to draw number of indices for(i=0; i<6; i++) gldrawelements(gl_polygon, 4, GL_UNSIGNED_BYTE, &cubeindices[4*i]); format of index data Method 2: start of index data gldrawelements(gl_quads, 24, GL_UNSIGNED_BYTE, cubeindices); Draws cube with 1 function call!!

114 OpenGL Character Functions Characters are defined as bitmap functions. Some predefined character sets are available in GLUT. Display a bitmap GLUT character with glutbitmapcharacter (font, character) Use either the ASCII code (i.e. 65) or the specific character (i.e. A ) Can select a fixed-width fonts GLUT_BITMAP_8_BY_13 or GLUT_BITMAP_9_BY_15 GLUT_BITMAP_TIMES_ROMAN_10

115 OpenGL Character Functions Define the lower left corner of the bitmap as current raster position. glrasterposition2i (x, y) for (k=0; k<36;k++) glutbitmapcharacter (GLUT_BITMAP_9_BY_15,text [k]); Characters in text array is displayed starting from position (x,y) with current color.

116 OpenGL Display Lists Structures for storing object descriptions Must define (name, create) Add contents Close Reference the list, with different display options In client-server environment, display list is placed on server Can be redisplayed without sending primitives over network each time

117 Display List Functions Creating a display list GLuint listid; void init() { } //generates a unique identifier glnewlist( listid, GL_COMPILE ); listid = glgenlists( 1 ); /* other OpenGL routines */ glendlist(); Call a created list void display() { } glcalllist( listid ); //executes the display list

118 Display Lists and State Most OpenGL functions can be put in display lists Can put one list in another State changes made inside a display list persist after the display list is executed

119 Hierarchy and Display Lists Consider model of a car - Create display list for chassis - Create display list for wheel glnewlist( CAR, GL_COMPILE ); glcalllist( CHASSIS ); gltranslatef( ); glcalllist( WHEEL ); gltranslatef( ); glcalllist( WHEEL ); glendlist();

120 Handling Input in OpenGL Input devices contain a trigger which can be used to send a signal to the operating system Button on mouse Pressing or releasing a key When triggered, input devices return information (their measure) to the system Mouse returns position information Keyboard returns ASCII code

121 Request Mode Input provided to program only when user triggers the device Typical of keyboard input Can erase (backspace), edit, correct until the enter (return) key (the trigger) is depressed

122 Event Mode Most systems have more than one input device, each of which can be triggered at an arbitrary time by a user Each trigger generates an event whose measure is put in an event queue which can be examined by the user program

123 GLUT Event Loop Recall that the last line in main.c for a program using GLUT must be glutmainloop(); which puts the program in an infinite event loop In each pass through the event loop, GLUT looks at the events in the queue for each event in the queue, GLUT executes the appropriate callback function if one is defined if no callback is defined for the event, the event is ignored

124 Event Types Window: resize, expose Mouse: click one or more buttons Motion: move mouse Keyboard: press or release a key Idle: nonevent Define what should be done if no other event is in queue

125 Callbacks Programming interface for event-driven input Define a callback function for each type of event the graphics system recognizes This user-supplied function is executed when the event occurs GLUT example: glutmousefunc(mymouse) mouse callback function

126 Interaction in OpenGL : callbacks Handling Input Events You can use these routines to register callback commands that are invoked when specified events occur. glutkeyboardfunc(void (*func)(unsigned char key, int x, int y)) and glutmousefunc(void (*func)(int button, int state, int x, int y)) allow you to link a keyboard key or a mouse button with a routine that's invoked when the key or mouse button is pressed or released. glutmotionfunc(void (*func)(int x, int y)) registers a routine to call back when the mouse is moved while a mouse button is also pressed. glutreshapefunc(void (*func)(int w, int h)) indicates what action should be taken when the window is resized.

127 The display callback The display callback is executed whenever GLUT determines that the window should be refreshed, for example When the window is first opened When the window is reshaped When the user program decides it wants to change the display In main.c glutdisplayfunc(mydisplay) identifies the function to be executed Every GLUT program must have a display callback

128 Display function After the window is created, but before you enter the main loop, you should register callback functions using the following routines. void glutdisplayfunc(void (*func)(void)); Specifies the function that's called whenever the contents of the window need to be redrawn. The contents of the window may need to be redrawn when the window is initially opened, when the window is popped and window damage is exposed, and when glutpostredisplay() is explicitly called.

129 Post redisplay void glutpostredisplay(void); Marks the current window as needing to be redrawn. At the next opportunity, the callback function registered by glutdisplayfunc() will be called. Many events may invoke the display callback function Can lead to multiple executions of the display callback on a single pass through the event loop We can avoid this problem by instead using glutpostredisplay(); which sets a flag. GLUT checks to see if the flag is set at the end of the event loop If set then the display callback function is executed

130 Keyboard function glutkeyboardfunc(void (*func)(unsigned char key, int x, int y)) Specifies the function, func, that's called when a key that generates an ASCII character is pressed. The key callback parameter is the generated ASCII value. The x and y callback parameters indicate the location of the mouse (in window-relative coordinates) when the key was pressed.

131 Mouse function void glutmousefunc(void (*func)(int button, int state, int x, int y)); Specifies the function, func, that's called when a mouse button is pressed or released. The button callback parameter is one of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON. The state callback parameter is either GLUT_UP or GLUT_DOWN,depending upon whether the mouse has been released or pressed. The x and y callback parameters indicate the location (in window-relative coordinates) of the mouse when the event occurred.

132 Motion function void glutmotionfunc(void (*func)(int x, int y)); Specifies the function, func, that's called when the mouse pointer moves within the window while one or more mouse buttons is pressed. The x and y callback parameters indicate the location (in window-relative coordinates) of the mouse when the event occurred.

133 Reshape function void glutreshapefunc(void (*func)(int width, int height)); Specifies the function that's called whenever the window is resized or moved. The argument func is a pointer to a function that expects two arguments, the new width and height of the window. Typically, func calls glviewport(), so that the display is clipped to the new size, and it redefines the projection matrix so that the aspect ratio of the projected image matches the viewport, avoiding aspect ratio distortion. If glutreshapefunc() isn't called or is deregistered by passing NULL, a default reshape function is called, which calls glviewport(0, 0, width, height). Viewports are discussed in H&B Ch.6

134 Example: handling a mouse button press void mykeyboardfunc (unsigned char key, int x, int y) { switch (key) { case 'f': removefirstpoint(); glutpostredisplay(); break; } case 27: } exit(0); break; // Escape key

135 Example: handling a mouse button press // use left button presses place a control point. void mymousefunc( int button, int state, int x, int y ) { if ( button==glut_left_button && state==glut_down ) { float xpos = ((float)x)/((float)(windowwidth-1)); float ypos = ((float)y)/((float)(windowheight-1)); ypos = 1.0f-yPos; // Flip value since y position is from top row. } } addnewpoint( xpos, ypos ); glutpostredisplay();

136 Positioning The position in the screen window is usually measured in pixels with the origin at the top-left corner Consequence of refresh done from top to bottom OpenGL uses a world coordinate system with origin at the bottom left Must invert y coordinate returned by callback by height of window y = h y; (0,0) h w

137 Obtaining the window size To invert the y position we need the window height Height can change during program execution Track with a global variable New height returned to reshape callback

138 Terminating a program In our original programs, there was no way to terminate them through OpenGL We can use the simple mouse callback void mouse(int btn, int state, int x, int y) { if(btn==glut_right_button && state==glut_down) exit(0); }

139 Using the mouse position In the next example, we draw a small square at the location of the mouse each time the left mouse button is clicked This example does not use the display callback but one is required by GLUT; We can use the empty display callback function mydisplay(){}

140 Drawing squares at cursor location void mymouse(int btn, int state, int x, int y) { if(btn==glut_right_button && state==glut_down) exit(0); if(btn==glut_left_button && state==glut_down) drawsquare(x, y); } void drawsquare(int x, int y) { y=w-y; /* invert y position */ glcolor3ub( (char) rand()%256, (char) rand )%256, (char) rand()%256); /* a random color */ glbegin(gl_polygon); glvertex2f(x+size, y+size); glvertex2f(x-size, y+size); glvertex2f(x-size, y-size); glvertex2f(x+size, y-size); glend(); }

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server Display Lists Conceptually similar to a graphics file Must define (name, create) Add contents Close In client-server environment, display list is placed on server Can be redisplayed without sending primitives

More information

Building Models. Objectives. Introduce simple data structures for building polygonal models. OpenGL vertex arrays. Vertex lists Edge lists

Building Models. Objectives. Introduce simple data structures for building polygonal models. OpenGL vertex arrays. Vertex lists Edge lists Building Models Objectives Introduce simple data structures for building polygonal models Vertex lists Edge lists OpenGL vertex arrays 2 Representing a Mesh Consider a mesh v 5 v e e e 3 v 9 8 8 v e 4

More information

Building Models. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Building Models. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Building Models Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Introduce simple data structures for building polygonal

More information

CSCI 4620/8626. Coordinate Reference Frames

CSCI 4620/8626. Coordinate Reference Frames CSCI 4620/8626 Computer Graphics Graphics Output Primitives Last update: 2014-02-03 Coordinate Reference Frames To describe a picture, the world-coordinate reference frame (2D or 3D) must be selected.

More information

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives. D Graphics Primitives Eye sees Displays - CRT/LCD Frame buffer - Addressable pixel array (D) Graphics processor s main function is to map application model (D) by projection on to D primitives: points,

More information

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics: Project Sketchpad Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics: User sees an object on the display User points to (picks) the object

More information

Lecture 4. Interaction / Graphical Devices. CS 354 Computer Graphics Sunday, January 20, 13

Lecture 4. Interaction / Graphical Devices. CS 354 Computer Graphics  Sunday, January 20, 13 Lecture 4 Interaction / Graphical Devices Graphical Input Devices can be described either by - Physical properties Mouse Keyboard Trackball - Logical Properties What is returned to program via API A position

More information

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms Chater : Grahics Outut Primitives Primitives: functions in grahics acage that we use to describe icture element Points and straight lines are the simlest rimitives Some acages include circles, conic sections,

More information

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers 1. How long would it take to load an 800 by 600 frame buffer with 16 bits per pixel

More information

Graphics (Output) Primitives. Chapters 3 & 4

Graphics (Output) Primitives. Chapters 3 & 4 Graphics (Output) Primitives Chapters 3 & 4 Graphic Output and Input Pipeline Scan conversion converts primitives such as lines, circles, etc. into pixel values geometric description a finite scene area

More information

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE DRAWING PRIMITIVES: LEGACY VS. NEW Legacy: specify primitive in glbegin() glbegin(gl_points); glvertex3f(1,5,0);

More information

Lecture 3 Advanced Computer Graphics (CS & SE )

Lecture 3 Advanced Computer Graphics (CS & SE ) Lecture 3 Advanced Computer Graphics (CS & SE 233.420) Programming with OpenGL Program Structure Primitives Attributes and States Programming in three dimensions Inputs and Interaction Working with Callbacks

More information

Working with Callbacks

Working with Callbacks Working with Callbacks 1 Objectives Learn to build interactive programs using GLUT callbacks Mouse Keyboard Reshape Introduce menus in GLUT 2 The mouse callback glutmousefunc(mymouse) void mymouse(glint

More information

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization. Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática Chap. 2 Rasterization Rasterization Outline : Raster display technology. Basic concepts: pixel, resolution,

More information

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007 Filled Area Primitives CEng 477 Introduction to Computer Graphics METU, 2007 Filled Area Primitives Two basic approaches to area filling on raster systems: Determine the overlap intervals for scan lines

More information

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored. From Vertices to Fragments: Rasterization Reading Assignment: Chapter 7 Frame Buffer Special memory where pixel colors are stored. System Bus CPU Main Memory Graphics Card -- Graphics Processing Unit (GPU)

More information

Computer Graphics. Chapter 3 Computer Graphics Software

Computer Graphics. Chapter 3 Computer Graphics Software Computer Graphics Chapter 3 Computer Graphics Software Outline Graphics Software Packages Introduction to OpenGL Example Program 2 3 Graphics Software Software packages General Programming Graphics Packages

More information

Computer Graphics Course 2005

Computer Graphics Course 2005 Computer Graphics Course 2005 Introduction to GLUT, GLU and OpenGL Administrative Stuff Teaching Assistant: Rony Goldenthal Reception Hour: Wed. 18:00 19:00 Room 31 (Ross 1) Questions: E-mail: cg@cs Newsgroups:

More information

Computer Graphics. OpenGL

Computer Graphics. OpenGL Computer Graphics OpenGL What is OpenGL? OpenGL (Open Graphics Library) is a library for computer graphics It consists of several procedures and functions that allow a programmer to specify the objects

More information

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

GEOMETRIC OBJECTS AND TRANSFORMATIONS I Computer UNIT Graphics - 4 and Visualization 6 Hrs GEOMETRIC OBJECTS AND TRANSFORMATIONS I Scalars Points, and vectors Three-dimensional primitives Coordinate systems and frames Modelling a colored cube

More information

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW OpenGL Syntax Functions have prefix gl and initial capital letters for each word glclearcolor(), glenable(), glpushmatrix() glu for GLU functions glulookat(), gluperspective() constants begin with GL_,

More information

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by: Lecture 3 Output Primitives Assuming we have a raster display, a picture is completely specified by: - A set of intensities for the pixel positions in the display. - A set of complex objects, such as trees

More information

Computer Graphics, Chapt 08

Computer Graphics, Chapt 08 Computer Graphics, Chapt 08 Creating an Image Components, parts of a scene to be displayed Trees, terrain Furniture, walls Store fronts and street scenes Atoms and molecules Stars and galaxies Describe

More information

Topic #1: Rasterization (Scan Conversion)

Topic #1: Rasterization (Scan Conversion) Topic #1: Rasterization (Scan Conversion) We will generally model objects with geometric primitives points, lines, and polygons For display, we need to convert them to pixels for points it s obvious but

More information

CS 543: Computer Graphics. Rasterization

CS 543: Computer Graphics. Rasterization CS 543: Computer Graphics Rasterization Robert W. Lindeman Associate Professor Interactive Media & Game Development Department of Computer Science Worcester Polytechnic Institute gogo@wpi.edu (with lots

More information

Chapter 8: Implementation- Clipping and Rasterization

Chapter 8: Implementation- Clipping and Rasterization Chapter 8: Implementation- Clipping and Rasterization Clipping Fundamentals Cohen-Sutherland Parametric Polygons Circles and Curves Text Basic Concepts: The purpose of clipping is to remove objects or

More information

RECITATION - 1. Ceng477 Fall

RECITATION - 1. Ceng477 Fall RECITATION - 1 Ceng477 Fall 2007-2008 2/ 53 Agenda General rules for the course General info on the libraries GLUT OpenGL GLUI Details about GLUT Functions Probably we will not cover this part 3/ 53 General

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science INTERNAL ASSESSMENT TEST 2 Solution Date : 30.03.15 Max Marks : 50 Subject & Code : Computer Graphics and Visualization/10CS65 Section : A, B and C Name of faculty : Ms. Sarasvathi V/ Ms. Archana Time

More information

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling Downloaded from :www.comp.dit.ie/bmacnamee/materials/graphics/006- Contents In today s lecture we ll have a loo at:

More information

UNIT 2 GRAPHIC PRIMITIVES

UNIT 2 GRAPHIC PRIMITIVES UNIT 2 GRAPHIC PRIMITIVES Structure Page Nos. 2.1 Introduction 46 2.2 Objectives 46 2.3 Points and Lines 46 2.4 Line Generation Algorithms 48 2.4.1 DDA Algorithm 49 2.4.2 Bresenhams Line Generation Algorithm

More information

Overview of Computer Graphics

Overview of Computer Graphics Application of Computer Graphics UNIT- 1 Overview of Computer Graphics Computer-Aided Design for engineering and architectural systems etc. Objects maybe displayed in a wireframe outline form. Multi-window

More information

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs 91.427 Computer Graphics I, Fall 2008 1 1 Objectives Refine first program Alter default values Introduce standard program structure Simple viewing 2-D

More information

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007 OUTPUT PRIMITIVES CEng 477 Introduction to Computer Graphics METU, 007 Recap: The basic forward projection pipeline: MCS Model Model Modeling Transformations M M 3D World Scene Viewing Transformations

More information

Programming using OpenGL: A first Introduction

Programming using OpenGL: A first Introduction Programming using OpenGL: A first Introduction CMPT 361 Introduction to Computer Graphics Torsten Möller Machiraju/Zhang/Möller 1 Today Overview GL, GLU, GLUT, and GLUI First example OpenGL functions and

More information

Rasterization: Geometric Primitives

Rasterization: Geometric Primitives Rasterization: Geometric Primitives Outline Rasterizing lines Rasterizing polygons 1 Rasterization: What is it? How to go from real numbers of geometric primitives vertices to integer coordinates of pixels

More information

Assignment 1. Simple Graphics program using OpenGL

Assignment 1. Simple Graphics program using OpenGL Assignment 1 Simple Graphics program using OpenGL In this assignment we will use basic OpenGL functions to draw some basic graphical figures. Example: Consider following program to draw a point on screen.

More information

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line walters@buffalo.edu CSE 480/580 Lecture 8 Slide 1 2D Graphics Primitives II Additional issues in scan converting lines 1)Endpoint order Want algorithms to draw the same pixels for each line How handle?

More information

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into 2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into the viewport of the current application window. A pixel

More information

Line Drawing. Foundations of Computer Graphics Torsten Möller

Line Drawing. Foundations of Computer Graphics Torsten Möller Line Drawing Foundations of Computer Graphics Torsten Möller Rendering Pipeline Hardware Modelling Transform Visibility Illumination + Shading Perception, Interaction Color Texture/ Realism Reading Angel

More information

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York Building Models Prof. George Wolberg Dept. of Computer Science City College of New York Objectives Introduce simple data structures for building polygonal models - Vertex lists - Edge lists Deprecated

More information

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete Scan Conversion CMP 477 Computer Graphics S. A. Areete What is Scan-Conversion? 2D or 3D objects in real world space are made up of graphic primitives such as points, lines, circles and filled polygons.

More information

COMP371 COMPUTER GRAPHICS

COMP371 COMPUTER GRAPHICS COMP371 COMPUTER GRAPHICS LECTURE 14 RASTERIZATION 1 Lecture Overview Review of last class Line Scan conversion Polygon Scan conversion Antialiasing 2 Rasterization The raster display is a matrix of picture

More information

Realtime 3D Computer Graphics Virtual Reality

Realtime 3D Computer Graphics Virtual Reality Realtime 3D Computer Graphics Virtual Reality From Vertices to Fragments Overview Overall goal recapitulation: Input: World description, e.g., set of vertices and states for objects, attributes, camera,

More information

Computer Graphics. Lecture 3 Graphics Output Primitives. Somsak Walairacht, Computer Engineering, KMITL

Computer Graphics. Lecture 3 Graphics Output Primitives. Somsak Walairacht, Computer Engineering, KMITL Computer Graphics Lecture 3 Graphics Output Primitives Somsa Walairacht, Computer Engineering, KMITL Outline Line Drawing Algorithms Circle-, Ellipse-Generating Algorithms Fill-Area Primitives Polgon Fill

More information

CPSC / Scan Conversion

CPSC / Scan Conversion CPSC 599.64 / 601.64 Computer Screens: Raster Displays pixel rasters (usually) square pixels in rectangular raster evenly cover the image problem no such things such as lines, circles, etc. scan conversion

More information

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.

More information

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued CS 543 - Computer Graphics: OpenGL, Continued by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Last time. OpenGL set up Basic structure OpenGL skeleton Callback functions, etc. R.W.

More information

Computer Graphics Lecture Notes

Computer Graphics Lecture Notes Computer Graphics Lecture Notes UNIT- Overview of Computer Graphics. Application of Computer Graphics Computer-Aided Design for engineering and architectural systems etc. Objects maybe displayed in a wireframe

More information

Chapter 3. Sukhwinder Singh

Chapter 3. Sukhwinder Singh Chapter 3 Sukhwinder Singh PIXEL ADDRESSING AND OBJECT GEOMETRY Object descriptions are given in a world reference frame, chosen to suit a particular application, and input world coordinates are ultimately

More information

From Ver(ces to Fragments: Rasteriza(on

From Ver(ces to Fragments: Rasteriza(on From Ver(ces to Fragments: Rasteriza(on From Ver(ces to Fragments 3D vertices vertex shader rasterizer fragment shader final pixels 2D screen fragments l determine fragments to be covered l interpolate

More information

Unit 2 Output Primitives and their Attributes

Unit 2 Output Primitives and their Attributes Unit 2 Output Primitives and their Attributes Shapes and colors of the objects can be described internally with pixel arrays or with sets of basic geometric structures, such as straight line segments and

More information

Einführung in Visual Computing

Einführung in Visual Computing Einführung in Visual Computing 186.822 Rasterization Werner Purgathofer Rasterization in the Rendering Pipeline scene objects in object space transformed vertices in clip space scene in normalized device

More information

CHAPTER 1 Graphics Systems and Models 3

CHAPTER 1 Graphics Systems and Models 3 ?????? 1 CHAPTER 1 Graphics Systems and Models 3 1.1 Applications of Computer Graphics 4 1.1.1 Display of Information............. 4 1.1.2 Design.................... 5 1.1.3 Simulation and Animation...........

More information

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines COMP30019 Graphics and Interaction Scan Converting Polygons and Lines Department of Computer Science and Software Engineering The Lecture outline Introduction Scan conversion Scan-line algorithm Edge coherence

More information

Computer graphic -- Programming with OpenGL I

Computer graphic -- Programming with OpenGL I Computer graphic -- Programming with OpenGL I A simple example using OpenGL Download the example code "basic shapes", and compile and run it Take a look at it, and hit ESC when you're done. It shows the

More information

Chapter - 2: Geometry and Line Generations

Chapter - 2: Geometry and Line Generations Chapter - 2: Geometry and Line Generations In Computer graphics, various application ranges in different areas like entertainment to scientific image processing. In defining this all application mathematics

More information

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines Emmanuel Agu 2D Graphics Pipeline Clipping Object World Coordinates Applying world window Object subset window to viewport mapping

More information

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II Emmanuel Agu Recall: OpenGL Skeleton void main(int argc, char** argv){ // First initialize toolkit, set display mode and create window glutinit(&argc,

More information

Interaction. CSCI 480 Computer Graphics Lecture 3

Interaction. CSCI 480 Computer Graphics Lecture 3 CSCI 480 Computer Graphics Lecture 3 Interaction January 18, 2012 Jernej Barbic University of Southern California Client/Server Model Callbacks Double Buffering Hidden Surface Removal Simple Transformations

More information

Computer Graphics. - Rasterization - Philipp Slusallek

Computer Graphics. - Rasterization - Philipp Slusallek Computer Graphics - Rasterization - Philipp Slusallek Rasterization Definition Given some geometry (point, 2D line, circle, triangle, polygon, ), specify which pixels of a raster display each primitive

More information

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms Computer Graphics: Graphics Output Primitives Line Drawing Algorithms By: A. H. Abdul Hafez Abdul.hafez@hku.edu.tr, 1 Outlines 1. Basic concept of lines in OpenGL 2. Line Equation 3. DDA Algorithm 4. DDA

More information

GRAPHICS OUTPUT PRIMITIVES

GRAPHICS OUTPUT PRIMITIVES CHAPTER 3 GRAPHICS OUTPUT PRIMITIVES LINE DRAWING ALGORITHMS DDA Line Algorithm Bresenham Line Algorithm Midpoint Circle Algorithm Midpoint Ellipse Algorithm CG - Chapter-3 LINE DRAWING Line drawing is

More information

Interaction Computer Graphics I Lecture 3

Interaction Computer Graphics I Lecture 3 15-462 Computer Graphics I Lecture 3 Interaction Client/Server Model Callbacks Double Buffering Hidden Surface Removal Simple Transformations January 21, 2003 [Angel Ch. 3] Frank Pfenning Carnegie Mellon

More information

Introduction to Computer Graphics with OpenGL/GLUT

Introduction to Computer Graphics with OpenGL/GLUT Introduction to Computer Graphics with OpenGL/GLUT What is OpenGL? A software interface to graphics hardware Graphics rendering API (Low Level) High-quality color images composed of geometric and image

More information

Time: 3 hours Max. Marks: 80. Note: Answer FIVE full questions, choosing one full question from each module.

Time: 3 hours Max. Marks: 80. Note: Answer FIVE full questions, choosing one full question from each module. USN 6 th Semester CBCS Scheme Model Question Paper 1 Department of Computer Science and Engineering, C. Byregowda Institute of Technology Computer Graphics and Visualization Time: 3 hours Max. Marks: 80

More information

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller Line Drawing Introduction to Computer Graphics Torsten Möller / Mike Phillips Rendering Pipeline Hardware Modelling Transform Visibility Illumination + Shading Perception, Color Interaction Texture/ Realism

More information

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi Output Primitives Dr. S.M. Malaek Assistant: M. Younesi Output Primitives Output Primitives: Basic geometric structures (points, straight line segment, circles and other conic sections, quadric surfaces,

More information

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

This library uses only GL functions but contains code for creating common objects and simplifying viewing. PES Institute of Technology, Bangalore South Campus (Formerly PES School of Engineering) (Hosur Road, 1KM before Electronic City, Bangalore-560 100) INTERNAL TEST (SCHEME AND SOLUTION) 1 Subject Name:

More information

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Lecture 2 CISC440/640 Spring Department of Computer and Information Science Lecture 2 CISC440/640 Spring 2015 Department of Computer and Information Science Today s Topic The secrets of Glut-tony 2 So let s do some graphics! For the next week or so this is your world: -1 1-1 1

More information

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics Announcements Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class 1 Scan Conversion Overview of Rendering Scan Conversion Drawing Lines Drawing Polygons

More information

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Computer Graphics. Making Pictures. Computer Graphics CSC470 1 Computer Graphics Making Pictures Computer Graphics CSC470 1 Getting Started Making Pictures Graphics display: Entire screen (a); windows system (b); [both have usual screen coordinates, with y-axis y

More information

Input and Interaction. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Input and Interaction. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico 1 Objectives Introduce the basic input devices - Physical Devices

More information

2D Drawing Primitives

2D Drawing Primitives THE SIERPINSKI GASKET We use as a sample problem the drawing of the Sierpinski gasket an interesting shape that has a long history and is of interest in areas such as fractal geometry. The Sierpinski gasket

More information

Clipping and Scan Conversion

Clipping and Scan Conversion 15-462 Computer Graphics I Lecture 14 Clipping and Scan Conversion Line Clipping Polygon Clipping Clipping in Three Dimensions Scan Conversion (Rasterization) [Angel 7.3-7.6, 7.8-7.9] March 19, 2002 Frank

More information

EF432. Introduction to spagetti and meatballs

EF432. Introduction to spagetti and meatballs EF432 Introduction to spagetti and meatballs CSC 418/2504: Computer Graphics Course web site (includes course information sheet): http://www.dgp.toronto.edu/~karan/courses/418/fall2015 Instructor: Karan

More information

Building Models. Objectives Introduce simple data structures for building polygonal models. Vertex lists Edge lists

Building Models. Objectives Introduce simple data structures for building polygonal models. Vertex lists Edge lists Building Models Objectives Introduce simple data structures for building polygonal models Vertex lists Edge lists 1 Representing a Mesh Consider a mesh v 5 v 6 e e e 3 v 9 8 8 v e 4 1 e 11 v e v 7 7 1

More information

MET71 COMPUTER AIDED DESIGN

MET71 COMPUTER AIDED DESIGN UNIT - II BRESENHAM S ALGORITHM BRESENHAM S LINE ALGORITHM Bresenham s algorithm enables the selection of optimum raster locations to represent a straight line. In this algorithm either pixels along X

More information

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3) Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1 http://www.cs.columbia.edu/~cs4160 To Do Start thinking (now) about HW 3. Milestones are due soon. Course Course 3D Graphics Pipeline 3D Graphics

More information

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL Computer Graphics Chapter 6 The Two-Dimensional Viewing Somsak Walairacht, Computer Engineering, KMITL Outline The Two-Dimensional Viewing Pipeline The Clipping Window Normalization and Viewport Transformations

More information

COMPUTER GRAPHICS LAB # 3

COMPUTER GRAPHICS LAB # 3 COMPUTER GRAPHICS LAB # 3 Chapter 2: COMPUTER GRAPHICS by F.S HILLs. Initial steps in drawing figures (polygon, rectangle etc) Objective: Basic understanding of simple code in OpenGL and initial steps

More information

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1 Computer Graphics Chapter 4 Attributes of Graphics Primitives Somsak Walairacht, Computer Engineering, KMITL 1 Outline OpenGL State Variables Point Attributes Line Attributes Fill-Area Attributes Scan-Line

More information

Lecture 11: Callbacks. CITS 3003 Graphics & Animation

Lecture 11: Callbacks. CITS 3003 Graphics & Animation Lecture 11: Callbacks CITS 3003 Graphics & Animation Slides: E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 Objectives Learn to build interactive programs using GLUT callbacks

More information

Lecture 10: Input, Interaction & callbacks. CITS 3003 Graphics & Animation

Lecture 10: Input, Interaction & callbacks. CITS 3003 Graphics & Animation Lecture 10: Input, Interaction & callbacks CITS 3003 Graphics & Animation Slides: E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 Objectives Introduce the basic input devices

More information

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005 INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Renderer Implementation: Basics and Clipping David Carr Virtual Environments, Fundamentals Spring 2005 Feb-28-05 SMM009, Basics and Clipping 1

More information

Computer Graphics: Line Drawing Algorithms

Computer Graphics: Line Drawing Algorithms Computer Graphics: Line Drawing Algorithms 1 Graphics hardware The problem scan conversion Considerations Line equations Scan converting algorithms A very simple solution The DDA algorithm, Bresenham algorithm

More information

Rendering. A simple X program to illustrate rendering

Rendering. A simple X program to illustrate rendering Rendering A simple X program to illustrate rendering The programs in this directory provide a simple x based application for us to develop some graphics routines. Please notice the following: All points

More information

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing EECE 478 Rasterization & Scenes Rasterization Learning Objectives Be able to describe the complete graphics pipeline. Describe the process of rasterization for triangles and lines. Compositing Manipulate

More information

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves CSC 418/2504: Computer Graphics Course web site (includes course information sheet): http://www.dgp.toronto.edu/~elf Instructor: Eugene Fiume Office: BA 5266 Phone: 416 978 5472 (not a reliable way) Email:

More information

Scan Conversion. Drawing Lines Drawing Circles

Scan Conversion. Drawing Lines Drawing Circles Scan Conversion Drawing Lines Drawing Circles 1 How to Draw This? 2 Start From Simple How to draw a line: y(x) = mx + b? 3 Scan Conversion, a.k.a. Rasterization Ideal Picture Raster Representation Scan

More information

Rasterization, or What is glbegin(gl_lines) really doing?

Rasterization, or What is glbegin(gl_lines) really doing? Rasterization, or What is glbegin(gl_lines) really doing? Course web page: http://goo.gl/eb3aa February 23, 2012 Lecture 4 Outline Rasterizing lines DDA/parametric algorithm Midpoint/Bresenham s algorithm

More information

Output Primitives Lecture: 4. Lecture 4

Output Primitives Lecture: 4. Lecture 4 Lecture 4 Circle Generating Algorithms Since the circle is a frequently used component in pictures and graphs, a procedure for generating either full circles or circular arcs is included in most graphics

More information

521493S Computer Graphics Exercise 1 (Chapters 1-3)

521493S Computer Graphics Exercise 1 (Chapters 1-3) 521493S Computer Graphics Exercise 1 (Chapters 1-3) 1. Consider the clipping of a line segment defined by the latter s two endpoints (x 1, y 1 ) and (x 2, y 2 ) in two dimensions against a rectangular

More information

(Refer Slide Time: 00:03:51)

(Refer Slide Time: 00:03:51) Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 17 Scan Converting Lines, Circles and Ellipses Hello and welcome everybody

More information

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU FROM VERTICES TO FRAGMENTS Lecture 5 Comp3080 Computer Graphics HKBU OBJECTIVES Introduce basic implementation strategies Clipping Scan conversion OCTOBER 9, 2011 2 OVERVIEW At end of the geometric pipeline,

More information

Comp 410/510 Computer Graphics Spring Input & Interaction

Comp 410/510 Computer Graphics Spring Input & Interaction Comp 410/510 Computer Graphics Spring 2018 Input & Interaction Objectives Introduce the basic input devices - Physical Devices - Logical Devices Event-driven input Input Modes Programming event input with

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics r About the Tutorial To display a picture of any size on a computer screen is a difficult process. Computer graphics are used to simplify this process. Various algorithms and techniques are used to generate

More information

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Teacher Assistant : Tamir Grossinger   Reception hours: by  - Building 37 / office -102 Assignments: 4 programing using Teacher Assistant : Tamir Grossinger email: tamirgr@gmail.com Reception hours: by email - Building 37 / office -102 Assignments: 4 programing using C++ 1 theoretical You can find everything you need in

More information

Computer Graphics 1 Computer Graphics 1

Computer Graphics 1 Computer Graphics 1 Projects: an example Developed by Nate Robbins Shapes Tutorial What is OpenGL? Graphics rendering API high-quality color images composed of geometric and image primitives window system independent operating

More information

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm Drawing Circles In today s lecture we ll have a look at: Circle drawing algorithms A simple technique The mid-point circle algorithm Polygon fill algorithms Summary raster drawing algorithms A Simple Circle

More information

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k Idea 1 m 0 candidates last pixel Note that line could have passed through any part of this pixel Decision variable: d = x(a-b) d is an integer d < 0 use upper pixel d > 0 use lower pixel Incremental Form

More information