CHAPTER 4 (2)
CHAPTER 4 (2)
2
LINE GENERATION/DROWING ALGORITHM
• A line connects two points.
• It is a basic element in graphics.
• To draw a line, you need two points between
which you can draw a line.
• we refer the one point of line as X0, Y0 and
the second point of line as X1, Y1.
Cont..
• Line drawing algorithm
– Programmer specifies (x,y) values of end pixels
– Need algorithm to figure out which intermediate
pixels are on line path
– Pixel (x,y) values constrained to integer values
– Actual computed intermediate line values may be
floats
– Rounding may be required. E.g. computed point
(10.48, 20.51) rounded to (10, 21)
Cont..
Cont..
LINE EQUASION
• Slope-intercept line equation (Cartesian equation)
𝑦 = 𝑓(𝑥) = 𝑚𝑥 + 𝑏
written as
=
Cont..
Cont.…
Cont.…
Cont.…
Point and Lines
• Points
glBegin(GL_POINTS);
Vertex2i(100,50);
• Lines
glBegin(GL_LINES);
Vertex2i(100,50);
Vertex2i(200,250);
Computer Graphics 45
Plotting curves
– Plotting General Curves
Syntax
drawArc(Point Centre,
Float Radius,
a
Float Angle_a, b
Float Angle_b)
Computer Graphics 46
Line thickness
– Line Thickness (Width)
Syntax
void glLineWidth( GLfloat width);
• width Specifies the width of rasterized lines. The initial
value is 1.
Computer Graphics 47
Line style
– Line Stipple
Syntax
void glLineStipple(Glint factor, Glushort pattern);
• sets the current stippling patten for lines
– the pattern argument is a 16 bit series of 0s and 1s, and it is
repeated as necessary
– the pattern can be stretched out by using factor (factor is
clamped between 1 and 256)
glLineStipple(1, 0x3F07);
glEnable(GL_LINE_STIPPLE);
Computer Graphics 48
Con…
polygons
– Polygon
• Polygon refer to an object that has border that can be described
by a line loop.
• Types
• GL_Polygon (more than four angles in an object)
• GL_Quads (four different angles in an object)
• GL_Triangles (three different angles in an object)
50
Polygons (contd…)
• Attributes in Polygons
– STRIP and FAN
o GL_TRIANGLES_STRIP
o GL_TRIANGLES_FAN
o GL_QUAD_STRIP
Computer Graphics 51
filling
• Filling Area
• A basic fill-area attribute provided by a general graphics
library is the display style of the interior.
void glShadeModel(GLenum mode);
• mode Accepted values are GL_FLAT and GL_SMOOTH. The
initial value is GL_SMOOTH.
Computer Graphics 52
Text in graphics
• Text
• Combination or collection of characters which is meaningful
called text(s).
• There are two forms of text is available in Graphics,
– Stoke Text (from predefined FONT)
glutStrokeCharacter(GLUT_STROKE_ROMAN, Char Text);
(Roman Font)
– Raster Text (creating with Vertices)
glutBitmapCharacter(GLUT_BITMAP_8_BY_13 , Char Text);
( 8 x 13 size)
53
Colors
• Color
• Color is one of the most interesting aspects of both human
perception and computer graphics.
– Subtractive -CMY Model
– Additive - RGB Model
54
Cont..
• Color combinations that result from combining
primary colors available in the two situations additive
color and subtractive color.
a): RGB is used to specify additive color. (b): CMY is used to specify subtractive
color
Color values
Red Green Blue Color as Output
56
End of Chapter 4