0% found this document useful (0 votes)
6 views

chapter2 (2)

Uploaded by

deti1234erbamo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

chapter2 (2)

Uploaded by

deti1234erbamo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Chapter Two

COMPUTER SCIENCE DEPARTMENT


EIT-M

GRAPHICS PRIMITIVES
A primitive Objects
2

 A primitive is a low level object or operation


from which higher-level, more complex
objects and operations can be constructed.
 In graphics, primitives are basic elements,
such as lines, curves, and polygons, which
can be combined to create more complex
graphical images.

Computer Graphics- Computer science- EIT-M


3

 In programming, primitives are the basic operations


supported by the programming language.
 To creative any drawing in the computer these
primitives form a part of the software and the type of
display to store these in the form of data is
important.

Computer Graphics- Computer science- EIT-M


4

 Graphics Primitive is a basic object that is essential


for the creation or construction of complex images.
 Graphics is constructed from three basic elements, as
opposed to the great variety of graphics applications.
 The most basic of these elmental structures is the
pixel, short for picture element.

Computer Graphics- Computer science- EIT-M


Types of geometric primitives

GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP

GL_POLYGON GL_QUADS GL_TRIANGLES GL_TRIANGLE_FAN

5
pixels
6

 A pixel is a point of light. It is just one tiny dot on the


raster displays.
 Though it has no structure, it is definitely a building
block and hence it can be considered as the graphics
primitive.
 The resolution of CRT is related to the dot size, the
diameter of a single dot. A resolution of 100 dots
lines/inch implies a dot size of 0.01 inch.

Computer Graphics- Computer science- EIT-M


Lines
7

 Line, especially straight lines, constitute the basic


building block of Line graphs, bar and pie charts, two
and three-dimensional graphs of mathematical
functions, engineering drawings and architectural
plans.
 In computer graphics, straight line is so basic in
creating images that we call it a graphics primitive.
 Straight lines can be developed in two different ways.

Computer Graphics- Computer science- EIT-M


Positioning an object

 Points
 x,y
•Lines
 Two points
 Draw by drawing all points in between
9

 A structural method determines which pixels should


be set before drawing the line;
 a conditional method tests certain conditions to find
which pixel should be set next.

Computer Graphics- Computer science- EIT-M


Cont…
10

 In mathematics and computer science an algorithm


is a step by step procedure for making calculations.
 Algorithms are made for calculation, data processing
and automated reasoning.
 In order to draw lines on a computer screen,
the Bresenham line algorithm is used that
determines which order to form a close
approximation to a straight line between two given
points.

Computer Graphics- Computer science- EIT-M


11

 It uses only integer addition, subtraction and bit


shifting where the digits are moved or shifted left or
right, all of which are very cheap operations in
standard computer architectures.
 It is one of the earliest algorithms developed in the
field of computer graphics.
 A minor extension to the original algorithm also
deals with drawing circles.

Computer Graphics- Computer science- EIT-M


Cont….
12

 Another algorithm namely, Digital Differential


Analyzer is a scan conversion line algorithm based
on calculating either dy or dx. We sample the line at
unit intervals in one coordinate & determine
corresponding integer values nearest to the line path
for the other coordinate.

Computer Graphics- Computer science- EIT-M


Polygon
13

 A polygon is a closed area of image bounded by


straight or curved lines and filled with one solid
color.
 Since images are two dimensional, a polygon is a
closed planar figure. A polygon, is an important
graphics primitive.
 So often we want to handle polygon as a single entity,
as images of objects from the real world consist in
large, part of polygons.

Computer Graphics- Computer science- EIT-M


Cont…
14

Point Drawing in
OpenGL

Line Drawing
Algorithms

Circle Drawing
Algorithms

Fill-Area Primitives

Computer Graphics- Computer science- EIT-M


15
Lines

Point Drawing in
OpenGL

Line Drawing
Algorithms

Circle Drawing
Algorithms

Fill-Area Primitives

m
 yend  y0  c  y  mx
xend  x0  δy = m.δx
0 0

δx = (1/m).δy
Computer Graphics- Computer science- EIT-M
16
Digital Differential Analyzer Algorithm
 Given (x0,y0) and (xend,yend)
Point Drawing in  Compute m
OpenGL  If |m| ≤ 1:
 δx = 1

Line Drawing  δy = m

Algorithms  If |m| > 1:


 δx = 1/m

DDA Algorithm  δy = 1

 Paint (x0,y0)
 Find successive pixel positions
Bresenham’s
 xk+1 = (xk + δx)
Algorithm
 yk+1 = (yk + δy)

 For each position (xk,yk) plot a


Circle Drawing
line point at
Algorithms
 (round(xk),round(yk))

Fill-Area Primitives

Computer Graphics- Computer science- EIT-M


17
Digital Differential Analyzer Algorithm
Example

Point Drawing in
 Given (x0,y0) = (10,10)
m
 yend  y0   (13  10)  3  0.6
OpenGL
 and (xend,yend) = (15,13)
xend  x0  (15  10) 5
 Compute m
Line Drawing  If |m| ≤ 1:
Algorithms  δx = 1
δx = 1
 δy = m δy = 0.6
 If |m| > 1:
DDA Algorithm
 δx = 1/m

 δy = 1
Bresenham’s  Paint (x0,y0) (xend,yend) = (15,13)
Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


18
Digital Differential Analyzer Algorithm
Example

Point Drawing in
 Given (x0,y0) = (10,10)
m
 yend  y0   (13  10)  3  0.6
OpenGL
 and (xend,yend) = (15,13)
xend  x0  (15  10) 5
 Compute m
Line Drawing  If |m| ≤ 1:
Algorithms  δx = 1
δx = 1
 δy = m δy = 0.6
 If |m| > 1:
DDA Algorithm
 δx = 1/m

 δy = 1
Bresenham’s  Paint (x0,y0) (xend,yend) = (15,13)
Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


19
Digital Differential Analyzer Algorithm
Example
 Paint (x0,y0) δx = 1
Point Drawing in  Find successive pixel δy = 0.6
OpenGL positions
 xk+1 = (xk + δx)

Line Drawing  yk+1 = (yk + δy)


(x1,y1) = (10+1,10+0.6)
Algorithms = (11,10.6)
 For each position (xk,yk)
plot a line point at
 (round(xk),round(yk))
colour pixel (11,11)
DDA Algorithm

Bresenham’s (xend,yend) = (15,13)


Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


20
Digital Differential Analyzer Algorithm
Example
 Paint (x0,y0) δx = 1
Point Drawing in  Find successive pixel δy = 0.6
OpenGL positions
 xk+1 = (xk + δx)

Line Drawing  yk+1 = (yk + δy)


(x2,y2) = (11+1,10.6+0.6)
Algorithms = (12,11.2)
 For each position (xk,yk)
plot a line point at
 (round(xk),round(yk))
colour pixel (12,11)
DDA Algorithm

Bresenham’s (xend,yend) = (15,13)


Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


21
Digital Differential Analyzer Algorithm
Example
 Paint (x0,y0) δx = 1
Point Drawing in  Find successive pixel δy = 0.6
OpenGL positions
 xk+1 = (xk + δx)

Line Drawing  yk+1 = (yk + δy)


(x3,y3) = (12+1,11.2+0.6)
Algorithms = (13,11.8)
 For each position (xk,yk)
plot a line point at
 (round(xk),round(yk))
colour pixel (13,12)
DDA Algorithm

Bresenham’s (xend,yend) = (15,13)


Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


22
Digital Differential Analyzer Algorithm
Example
 Paint (x0,y0) δx = 1
Point Drawing in  Find successive pixel δy = 0.6
OpenGL positions
 xk+1 = (xk + δx)

Line Drawing  yk+1 = (yk + δy)


(x4,y4) = (13+1,11.8+0.6)
Algorithms = (14,12.4)
 For each position (xk,yk)
plot a line point at
 (round(xk),round(yk))
colour pixel (14,12)
DDA Algorithm

Bresenham’s (xend,yend) = (15,13)


Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


23
Digital Differential Analyzer Algorithm
Example
 Paint (x0,y0) δx = 1
Point Drawing in  Find successive pixel δy = 0.6
OpenGL positions
 xk+1 = (xk + δx)

Line Drawing  yk+1 = (yk + δy)


(x5,y5) = (14+1,12.4+0.6)
Algorithms = (15,13)
 For each position (xk,yk)
plot a line point at
 (round(xk),round(yk))
colour pixel (15,13)
DDA Algorithm

Bresenham’s (xend,yend) = (15,13)


Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


24
Bresenham’s Line-Drawing Algorithm

 |m| < 1
Point Drawing in
OpenGL  Plot (x0,y0)
 Compute the first
Line Drawing decision variable:
Algorithms p0  2y  x
 For each k, starting with
DDA Algorithm k=0:
 If pk < 0:

Bresenham’s  Plot (xk+1,yk)


Algorithm
pk 1  pk  2y
Circle Drawing
 Otherwise:
Algorithms
 Plot (xk+1,yk+1)
pk 1  pk  2y  2x
Fill-Area Primitives

Computer Graphics- Computer science- EIT-M


25
Bresenham’s Line-Drawing Algorithm

 |m| < 1  |m| > 1


Point Drawing in
OpenGL  Plot (x0,y0)  Plot (x0,y0)
 Compute the first  Compute the first
Line Drawing decision variable: decision variable:
Algorithms p0  2y  x p0  2X  Y
 For each k, starting with  For each k, starting with
DDA Algorithm k=0: k=0:
 If pk < 0:  If pk < 0:

Bresenham’s  Plot (xk+1,yk)  Plot (xk+1,yk)


Algorithm
pk 1  pk  2y pk 1  pk  2X
Circle Drawing
 Otherwise:  Otherwise:
Algorithms
 Plot (xk+1,yk+1)  Plot (xk+1,yk+1)
pk 1  pk  2y  2x pk 1  pk  2X  2Y
Fill-Area Primitives

Computer Graphics- Computer science- EIT-M


26
Bresenham’s Line-Drawing Algorithm
Example
 |m| < 1 m = 0.6 < 1
Point Drawing in
OpenGL  Plot (x0,y0)
 Compute the first
Line Drawing decision variable:
Algorithms p0  2y  x

DDA Algorithm

Bresenham’s (xend,yend) = (15,13)


Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


27
Bresenham’s Line-Drawing Algorithm
Example
 |m| < 1 m = 0.6 < 1
Point Drawing in
OpenGL  Plot (x0,y0) Δx = 5
 Compute the first Δy = 3
Line Drawing decision variable: 2Δy = 6
Algorithms p0  2y  x 2Δy - 2Δx = -4

DDA Algorithm p0  2y  x  2  3  5  1


Bresenham’s (xend,yend) = (15,13)
Algorithm

Circle Drawing
Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


28
Bresenham’s Line-Drawing Algorithm
Example
m = 0.6 < 1
 |m| < 1 Δx = 5 Δy = 3 2Δy = 6
Point Drawing in
 Plot (x0,y0) 2Δy - 2Δx = -4
OpenGL
 For each k, starting with p0 ≥ 0, so
Line Drawing k=0: Plot (x1,y1) = (x0+1,y0+1) =
Algorithms  If pk < 0:
(11,11)

 Plot (xk+1,yk) p1  p0  2y  2x


DDA Algorithm
pk 1  pk  2y  1  4  3

Bresenham’s  Otherwise: (xend,yend) = (15,13)


Algorithm  Plot (xk+1,yk+1)

Circle Drawing pk 1  pk  2y  2x


Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


29
Bresenham’s Line-Drawing Algorithm
Example
m = 0.6 < 1
 |m| < 1 Δx = 5 Δy = 3 2Δy = 6
Point Drawing in
 Plot (x0,y0) 2Δy - 2Δx = -4
OpenGL
 For each k, starting with p1 < 0,
Line Drawing k=0: Plot (x2,y2) = (x1+1,y1) =
Algorithms  If pk < 0: (12,11)
 Plot (xk+1,yk)
p2  p1  2y
DDA Algorithm
pk 1  pk  2y  3  6  3
Bresenham’s  Otherwise: (xend,yend) = (15,13)
Algorithm  Plot (xk+1,yk+1)

Circle Drawing pk 1  pk  2y  2x


Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


30
Bresenham’s Line-Drawing Algorithm
Example
m = 0.6 < 1
 |m| < 1 Δx = 5 Δy = 3 2Δy = 6
Point Drawing in
 Plot (x0,y0) 2Δy - 2Δx = -4
OpenGL
 For each k, starting with p2 ≥ 0,
Line Drawing k=0: Plot (x3,y3) = (x2+1,y2+1)
Algorithms  If pk < 0: = (13,12)
 Plot (xk+1,yk)
p3  p2  2y  2x
DDA Algorithm
pk 1  pk  2y  3  4  1

Bresenham’s  Otherwise: (xend,yend) = (15,13)


Algorithm  Plot (xk+1,yk+1)

Circle Drawing pk 1  pk  2y  2x


Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


31
Bresenham’s Line-Drawing Algorithm
Example
m = 0.6 < 1
 |m| < 1 Δx = 5 Δy = 3 2Δy = 6
Point Drawing in
 Plot (x0,y0) 2Δy - 2Δx = -4
OpenGL
 For each k, starting with p3 < 0,
Line Drawing k=0: Plot (x4,y4) = (x3+1,y3) =
Algorithms  If pk < 0: (14,12)
 Plot (xk+1,yk)
DDA Algorithm p4  p3  2y
pk 1  pk  2y  1  6  5
Bresenham’s  Otherwise: (xend,yend) = (15,13)
Algorithm  Plot (xk+1,yk+1)

Circle Drawing pk 1  pk  2y  2x


Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


32
Bresenham’s Line-Drawing Algorithm
Example
m = 0.6 < 1
 |m| < 1 Δx = 5 Δy = 3 2Δy = 6
Point Drawing in
 Plot (x0,y0) 2Δy - 2Δx = -4
OpenGL
 For each k, starting with p4 ≥ 0,
Line Drawing k=0: Plot (x5,y5) = (x4+1,y4+1)
Algorithms  If pk < 0: = (15,13)
 Plot (xk+1,yk)
DDA Algorithm
pk 1  pk  2y
Bresenham’s  Otherwise: (xend,yend) = (15,13)
Algorithm  Plot (xk+1,yk+1)

Circle Drawing pk 1  pk  2y  2x


Algorithms

Fill-Area Primitives (x0,y0) = (10,10)

Computer Graphics- Computer science- EIT-M


33
Bresenham’s vs. DDA
 Bresenham’s algorithm use only integer operations
Point Drawing in  Bresenham’s algorithm is more efficient than DDA
OpenGL  Bresenham’s algorithm preferable for line drawing
than DDA in computer Graphics.
Line Drawing
Algorithms

DDA Algorithm OpenGL Line Drawing


Glint p1[] = {200,100}; Glint p2[] = {50,0}
Glint p3[] = {100,200}; Glint p4[] = {150,0};
Glint p5[] = {0,100};
Bresenham’s
(GL_LINE_STRIP)
Algorithm glBegin(GL_LINES);
glVertex2iv(p1);
glVertex2iv(p2);
Circle Drawing glVertex2iv(p3);
Algorithms glVertex2iv(p4);
glVertex2iv(p5);
glEnd();
Fill-Area Primitives
(GL_LINE_LOOP)

Computer Graphics- Computer science- EIT-M


Drawing primitive objects by
using graphics.h
Drawing primitive objects by using
graphics.h

 There are a number of libraries used to draw graphic


objects. To name a few –
 graphics.h.
 OpenGL
 DirectX
 SDL
 SFML
 Allegro
 Dev c++ needs graphics.h header file to provide
graphics capability to computers.
How to add graphics in dev C++ (follow
these steps)

 Step 1: Download/update the latest version of


dev C++
 It’s a good idea to have the latest version of the Dev C++
application.
Cont…

 Step 2: Add header source files into Dev C++


directory
 Next, you need to download graphics library files and add
them to the appropriate folders under the MinGW64 directory.
Cont….
Step 3: Change compiler suit in Dev
C++
 Compiler suites combine the latest stable release of
the GCC toolset and open-source MinGW runtime
APIs to build an open-source alternative to
Microsoft’s compiler.
 You need to set the TDM – GCC version to 4.9.2 32-
bit release.
Cont…
Step 4: Configure required linkers for
graphics
 This program will help to link object modules of a
program into a single object file.
 For graphics.h setup you will need these linkers to be
set for the selected compiler suite, aka TDM – GCC
4.9.2 32-bit release.
-libgcc -lbgi -lgdi32 -lcomdlg32 -luuid -
loleaut32 -lole32
Builtin functions in graphics

 void putpixel( int x, int y, int color );


 void line( int x1, int y1, int x2, int y2 );
 void arc( int x, int y, int stangle, int
endangle, int radius );
 void cleardevice( );
void circle( int x, int y, int radius );
46

 #include<graphics.h>
 int main()
{
 initwindow(700,500,"Olompyc");
 setcolor(YELLOW);
 circle(80,100,50);
 setcolor(RED);

Computer Graphics- Computer science- EIT-M


47

 circle(160,130,50);
 setcolor(BLUE);
 circle(240,100,50);
 setcolor(RED);
 circle(320,130,50);
 setcolor(YELLOW);
 circle(400,100,50);
 getch();
 }

Computer Graphics- Computer science- EIT-M


48

 void ellipse( int x, int y, int stangle, int endangle, int


xradius, int yradius );

Computer Graphics- Computer science- EIT-M


49

 void fillellipse( int x, int y, int xradius, int yradius


);
 void bar( int left, int top, int right, int bottom );
 void rectangle( int left, int top, int right, int bottom
);

Computer Graphics- Computer science- EIT-M


 void bar3d( int left, int top, int right, int bottom, int
depth, int topflag );
 void clearviewport( );
 void drawpoly(int n_points, int* points);
 void fillpoly(int n_points, int* points);
 void floodfill( int x, int y, int border );
 void linerel( int dx, int dy );
 void lineto( int x, int y );
 void pieslice( int x, int y, int stangle, int endangle, int
radius );
 void sector( int x, int y, int stangle, int endangle, int
xradius, int yradius );
51
Circle Drawing Algorithms
Circle
Point Drawing in
OpenGL

Line Drawing
Algorithms

Circle Drawing
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives

Computer Graphics- Computer science- EIT-M


52
Circle Drawing Algorithms
1. Plotting Points Using Cartesian Coordinates
Point Drawing in  Incrimenting x and computing y
OpenGL

y  yc  r 2  xc  x
2
Line Drawing
Algorithms 2. Plotting Points Using Polar Coordinates
Circle Drawing  r will be constant and only changing θ
Algorithms  Compute x and y
x  xc  r cos y  yc  r sin
Basic Algorithms
 More efficient than
Midpoint Cartesian one
Algorithms  Even more efficient
with a little cost in
Fill-Area Primitives quality

Computer Graphics- Computer science- EIT-M


53
Circle Drawing Algorithms
3. Plotting Points Using Cartesian Coordinates
and Symmetry of Circles
Point Drawing in
OpenGL

Line Drawing
Algorithms

Circle Drawing
Algorithms

Basic Algorithms

 Generates extra 7 points by re-arrangment


Midpoint
Algorithms  Need only completion for one octant of the
circle
Fill-Area Primitives  Still have square root operations and
trigonometric calculations
Computer Graphics- Computer science- EIT-M
54
Midpoint Algorithm
 Given the center and r
Point Drawing in  Plot the start-point of the
OpenGL circle (x0,y0) = (xc,r)
 Compute the first decision
Line Drawing variable:
Algorithms p0  1  r
 For each k, starting with
Circle Drawing k=0:
Algorithms If pk < 0:
Plot (xk+1,yk)
Basic Algorithms pk 1  pk  2 xk 1  1
Otherwise:
Midpoint Plot (xk+1,yk-1)
Algorithms
pk 1  pk  2 xk 1  1  2 yk 1
Fill-Area Primitives

Computer Graphics- Computer science- EIT-M


55
Midpoint Algorithm Example
 Given the center (0,0) and r = 10
 Plot the start-point of the circle (x0,y0) = (xc,r) = (0,10)
Point Drawing in
 Compute the first decision variable:
OpenGL
p0  1  r
Line Drawing
Algorithms (10,10)

Circle Drawing P = -9
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


56
Midpoint Algorithm Example
p0 < 0,
Point Drawing in Plot (x1,y1) = (x0+1,y0) = (1,10)
OpenGL
p1  p0  2 x1  1  9  3  6
Line Drawing
Algorithms (10,10)

Circle Drawing p0 = -9
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


57
Midpoint Algorithm Example
p1 < 0,
Plot (x2,y2) = (x1+1,y1) = (2,10)
Point Drawing in
OpenGL p2  p1  2x2  1  6  5  1
Line Drawing
Algorithms (10,10)

Circle Drawing p1 = -6
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


58
Midpoint Algorithm Example
p2 < 0,
Plot (x3,y3) = (x2+1,y2) = (3,10)
Point Drawing in
OpenGL p3  p2  2 x3  1  1  7  6
Line Drawing
Algorithms (10,10)

Circle Drawing p2 = -1
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


59
Midpoint Algorithm Example
p3 ≥ 0
Plot (x4,y4) = (x3+1,y3-1) = (4,9)
Point Drawing in
OpenGL p4  p3  2 x4  1  2 y4  6  9  3
Line Drawing
Algorithms (10,10)

Circle Drawing p3 = 6
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


60
Midpoint Algorithm Example
p4 < 0,
Plot (x5,y5) = (x4+1,y4) = (5,9)
Point Drawing in
OpenGL p5  p4  2 x5  1  3  11  8
Line Drawing
Algorithms (10,10)

Circle Drawing p4 = -3
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


61
Midpoint Algorithm Example
p5 ≥ 0,
Plot (x6,y6) = (x5+1,y5-1) = (6,8)
Point Drawing in
OpenGL p 6  p5  2 x 6  1  2 y 6  8  3  5
Line Drawing
Algorithms (10,10)

Circle Drawing p5 = 8
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


62
Midpoint Algorithm Example
p6 ≥ 0,
Plot (x7,y7) = (x6+1,y6-1) = (7,7)
Point Drawing in
OpenGL p7  p6  2 x7  1  2 y7  19 13  6
Line Drawing
Algorithms (10,10)

Circle Drawing p6 = 5
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


63
Midpoint Algorithm Example
p7 ≥ 0,
Plot (x8,y8) = (x7+1,y7-1) = (8,6)
Point Drawing in
OpenGL p8  p7  2 x8  1  2 y8  22 11  11
Line Drawing
Algorithms (10,10)

Circle Drawing p7 = 6
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


64
Midpoint Algorithm Example
p8 ≥ 0,
Plot (x9,y9) = (x8+1,y8-1) = (9,5)
Point Drawing in
OpenGL

Line Drawing
Algorithms (10,10)

Circle Drawing p8 = 11
Algorithms

Basic Algorithms

Midpoint
Algorithms

Fill-Area Primitives
(0,0)

Computer Graphics- Computer science- EIT-M


Scan line polygon fill algorithm
65

Computer Graphics- Computer science- EIT-M


Flood Fill Algorithm
66

Computer Graphics- Computer science- EIT-M


67
OpenGL Fill-Area Functions 1.

Polygons

Polygon
Representation

Polygon Normal
Vectors

OpenGL Fill-Area
Functions glRecti(200,100,50,250);

Front face is away from


the camera

Computer Graphics- Computer science- EIT-M


68
OpenGL Fill-Area Functions 2.
glBegin(GL_POLYGON);
glVertex2iv(p1);
Polygons glVertex2iv(p2); Front face is towards the
glVertex2iv(p3); camera . The points are
Polygon glVertex2iv(p4); given in anti-clockwise
Representation glVertex2iv(p5);
glVertex2iv(p6);
Polygon Normal glEnd();
Vectors

OpenGL Fill-Area
Functions

Computer Graphics- Computer science- EIT-M


69
OpenGL Fill-Area Functions 3.
glBegin(GL_TRIANGLES);
glVertex2iv(p1);
Polygons Front face is towards the
glVertex2iv(p2);
glVertex2iv(p6); camera . The points are
Polygon glVertex2iv(p3); given in anti-clockwise
Representation glVertex2iv(p4);
glVertex2iv(p5);
Polygon Normal glEnd();
Vectors

OpenGL Fill-Area
Functions

Computer Graphics- Computer science- EIT-M


70
OpenGL Fill-Area Functions 4.
glBegin(GL_TRIANGLE_STRIP);
glVertex2iv(p1);
Polygons
glVertex2iv(p2);
glVertex2iv(p6);
Polygon glVertex2iv(p3);
Representation glVertex2iv(p5); The points for only first
glVertex2iv(p4); triangle are given in anti-
Polygon Normal glEnd(); clockwise
Vectors

OpenGL Fill-Area
Functions

Computer Graphics- Computer science- EIT-M


71
OpenGL Fill-Area Functions 5.

glBegin(GL_TRIANGLE_FAN);
Polygons glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3); The first point of the first
Polygon
glVertex2iv(p4); triangle is the beginning
Representation
glVertex2iv(p5); of the fan. points are
glVertex2iv(p6); given in anti-clockwise
Polygon Normal glEnd();
Vectors

OpenGL Fill-Area
Functions

Computer Graphics- Computer science- EIT-M


72
OpenGL Fill-Area Functions 6.
glBegin(GL_QUADS);
glVertex2iv(p1);
Polygons
glVertex2iv(p2);
glVertex2iv(p3);
Polygon The quadrilateral points
glVertex2iv(p4);
Representation are given in anti-clockwise
glVertex2iv(p5);
glVertex2iv(p6);
Polygon Normal glVertex2iv(p7);
Vectors glVertex2iv(p8);
glEnd();
OpenGL Fill-Area
Functions

Computer Graphics- Computer science- EIT-M


73
OpenGL Fill-Area Functions 7.

glBegin(GL_QUAD_STRIP);
Polygons glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3); The first quadrilateral
Polygon glVertex2iv(p4);
Representation points are given in anti-
glVertex2iv(p5); clockwise
glVertex2iv(p6);
Polygon Normal glVertex2iv(p7);
Vectors glVertex2iv(p8);
glEnd();
OpenGL Fill-Area
Functions

Computer Graphics- Computer science- EIT-M

You might also like