Professional Documents
Culture Documents
Chapter 4
Chapter 4
Chapter Four
GL_LINES
Unconnected line segments
GL_LINE_STRIP
Connected line segments(a polyline)
GL_LINE_LOOP
Connected line segments, and last
point connected to first point
12/15/22 Computer Graphics Getie B. MAU – CS
Line Drawing Algorithms
10
Example:
m=3/5=0.6
|m|≤1, so
δx=1, δy=0.6
Summary
Width - tickness
Specify in pixels and proportion of a
standard line width
Issues:
Line have different thickness on the slope
Problem with
End of the line
Joining the two lines (polygon)
Width
simplest and most common technique for
increasing the width of a line
plot a line of width 1 pixel, and then
add extra pixels in either the horizontal or
vertical directions
these two approaches we use depends on
gradient m of line
If |m| ≤ 1: line more horizontal than vertical
plot extra pixels vertically, i.e. same x-
coordinate, different y-coordinate, as
If |m| > 1 :Computer
12/15/22
line Graphics
more vertical Getie
than horizontal
B. MAU – CS
Contd…
21
Width
Width
Two problems with
technique:
- Thickness depends on
slope, e.g.
If slope = 0, plotting
n pixels gives
thickness n
If slope = 1 (45o),
plotting n pixels
gives thickness of
n/√2
- Ends of lines:
depending on whether
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
23
Width
Answer to the second problem – use line caps
Line cap is a shape that is applied to the end of
the line only to give them a better appearance
Three types of line cap are common in computer
graphics:
- Butt cap - is formed by drawing a line through
each end-point at an orientation of 90o to the
direction of the line
- Round cap - formed by drawing a semi-circle at
each end-point with radius equal to half the line
width
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
24
Width
Types of line cap
Style
Solid
Dotted – very short dash with spacing
equal to or greater than dash itself
Dashed – displayed by generating an interdash spacing
normal approach to change line style – define a
pixel mask
- Pixel mask means a sequence of bit values that
determine whether pixels in the plotted line should be
on or off, e.g.,
- Mask 11111000 specifies a dash length of 5 pixels
followed by a spacing of 3 pixels
- In other words,
12/15/22 if bit in PM plot pixel Getie B. MAU – CS
is 1Graphics
Computer
OpenGL Line Functions
28
glEnable(GL_LINE_STIPPLE);
glLineWidth(3.0);
glLineStipple(1, 0x00FF);
glBegin(GL_LINE_STRIP);
glVertex2i(100,100);
glVertex2i(150,100);
glVertex2i(150,200);
glVertex2i(250,250);
glEnd();
glDisable(GL_LINE_STIPPLE);
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
32
Writing Assignments
Discuss about
- Circle Generating Algorithms
- Ellipse Generating Algorithms
Write pseudo codes and flowchart for DDA line
generating algorithm.
Texture Fill
Solid Fill Pattern Fill
Assignments
Concave and Convex Polygons
Identify concave polygons
Splitting concave polygons
Polygon Inside-Outside Tests
Representing polygons
Polygon Front and Back faces
Polygon Normal Vectors
glRect*
Because rectangles are a common primitive to display,
OpenGL provides a special routine that takes 2-D
points only.
glRect* (x1, y1, x2, y2)
where (x1,y1) and (x2,y2) define opposite corners of
the rectangle. Actually when we call the glRect*
routine, OpenGL will construct a polygon with
vertices defined in the following order:
(x1,y1), (x2,y1), (x2,y2), (x1,y2).
Specify opposite corners of the rectangle,
e.g: glRecti(200,100,50,250);
Can draw rectangles with other functions,
but glRect*can be
12/15/22
more efficient Getie B. MAU – CS
Computer Graphics
Contd…
41
GL_POLYGON:
Displays a single convex polygon
Vertices of the polygon are specified in anti-clockwise
direction
E.g.
glBegin(GL_POLYGON);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
glVertex2iv(p5);
glVertex2iv(p6);
glEnd();
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
43
GL_TRIANGLES:
Vertex list treated as groups of three triangle vertices
Vertices must be specified in anti-clockwise order
E.g.
glBegin(GL_TRIANGLES);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p6);
glVertex2iv(p3);
glVertex2iv(p4);
glVertex2iv(p5);
glEnd();
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
44
GL_TRIANGLE_STRIP:
Displays set of connected triangles
First triangle vertices must be anti-clockwise
E.g.
glBegin(GL_TRIANGLE_STRIP);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p6);
glVertex2iv(p3);
glVertex2iv(p5);
glVertex2iv(p4);
glEnd();
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
45
GL_TRIANGLE_FAN:
First vertex is the ‘source’ of the fan
Subsequent pairs of vertices form triangles with the first
one
E.g.
glBegin(GL_TRIANGLE_FAN);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
glVertex2iv(p5);
glVertex2iv(p6);
glEnd();
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
46
GL_QUADS:
Vertex list treated as groups of four quadrilateral
vertices
Vertices must be specified in anti-clockwise order, E.g.
glBegin(GL_QUADS);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
glVertex2iv(p5);
glVertex2iv(p6);
glVertex2iv(p7);
glVertex2iv(p8);
glEnd();
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
47
GL_QUAD_STRIP:
One quadrilateral drawn for each pair of vertices after
the first two
E.g.
glBegin(GL_QUAD_STRIP);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
glVertex2iv(p5);
glVertex2iv(p6);
glVertex2iv(p7);
glVertex2iv(p8);
glEnd();
12/15/22 Computer Graphics Getie B. MAU – CS
Character Primitives
48
00111000
01101100
11000110
11000110
11111110
11000110
11000110
00000000
12/15/22 Computer Graphics Getie B. MAU – CS
Contd…
51
Stroke(outline)
Defined using line/curve primitives
Each character represented (stored) as a series of
line segments
Scalable – coordinates are multiplied by some
scaling factor.
Takes longer time draw than bitmap fonts
we can change the font, colour, and also line width
and line style
Therefore the width of these lines can be changed
using
glLineWidth
style of the lines using
12/15/22 Computer Graphics Getie B. MAU – CS
OpenGL Character Primitives
52
glutInitDisplayMode, e.g.
- glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
glColor*, e.g.
- glColor3f(1.0,1.0,1.0); white foreground
glClearColor, e.g.
- glClearColor(0,0,0,0) black background
WHITE
Question
s?
Thank You!
12/15/22 Computer Graphics Getie B. MAU – CS