1
Sri Raghavendra Educational Institutions Society (R)
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
Sri Krishna Institute of Technology
www.skit.org.in
Department of Computer Science & Engineering
21CS63-Computer graphics and Fundamental of Image Processing
MODULE-1
� Computer Graphics Software and Hardware, Introduction to OpenGL
2
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
INTRODUCTION
3
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
INTRODUCTION
Fig. A Graphics system
4
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
INTRODUCTION
Advantages of CG :
5
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Applications of CG
6
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Applications of CG
7
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Video Display Devices
8
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Cathode-Ray Tube(CRT)
Fig. Refresh cathode ray tube
9
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Phosphors
10
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Raster-Scan Displays
❖ The refreshing rate, called the frame rate.
11
Fig.2 - A raster-scan system displays an object as a set of discrete points across each scan line.
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Raster-Scan Systems
12
Figure. Organization of a simple raster system
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Random-Scan Displays/Vector-scan
13
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Color CRT Moitors
— High resolution
— Good color fidelity
— High contrast
— High update rates
Techniques for producing color :
— Beam penetration method
— Shadow mask method
14
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Beam Penetration Method
15
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Shadow Masks Method
16
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Introduction To OpenGL
What is OpenGL?
17
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Introduction To OpenGL
18
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Basic OpenGL Syntax
For eg:- glBegin, glClear, glCopyPixels, glPolygonMode
19
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL Interface
Components of the OpenGL Interface
Eg:- Apple GL(AGL), Windows-to-OpenGL(WGL), Presentation Manager to OpenGL(PGL), GLX.
20
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
✓ In windows to include OpenGL core libraries and GLU we can use the following header files:-
#include <windows.h> //precedes other header files
for including Microsoft windows ver
of OpenGL libraries
#include<GL/gl.h>
#include <GL/glu.h>
✓ The above lines can be replaced by using GLUT header file which ensures gl.h and glu.h are included correctly,
✓ #include <GL/glut.h> //GL in windows
✓ In Apple OS X systems, the header file inclusion statement will be,
✓ #include <GLUT/glut.h>
21
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Coordinate Reference Frames
22
Y Axis
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Coordinate Reference Frames
23
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Specifying a 2D World-Coordinate RF
➢ The gluOrtho2D command.
➢ Orthogonal projection.
ymin, ymax);
24
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL Functions
25
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL Point Functions
OpenGL Point Functions
➢ The type within glBegin() specifies the type of the object and its value can be as follows:
GL_POINTS
➢ The default color for primitives is white, and the default point size is equal to the size of a single screen pixel.
Syntax: Case 1:
glBegin (GL_POINTS);
glVertex2i (50, 100);
glVertex2i (75, 150);
glVertex2i (100, 200);
glEnd ( );
26
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL Point Functions
Case 2:
➢ We 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 (point1);
glVertex2iv (point2);
glVertex2iv (point3);
glEnd ( );
27
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL Point Functions
Case 3:
➢ specifying two point positions in a three dimensional world reference frame. In this case, we give the coordinates as explicit floating-point values:
glBegin (GL_POINTS);
glVertex3f (-78.05, 909.72, 14.60);
glVertex3f (261.91, -5200.67, 188.33);
glEnd ( );
28
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL LINE FUNCTIONS
29
➢ Case 1: Lines
glBegin (GL_LINES);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL LINE FUNCTIONS
30
glBegin (GL_LINES_STRIP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
Case 2: GL_LINE_STRIP:
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL LINE FUNCTIONS
Case 3: GL_LINE_LOOP:
31
glBegin (GL_LINES_LOOP);
glVertex2iv (p1);
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5);
glEnd ( );
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL Attributes
32
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Point Attribute
➔ In a state system: The displayed color and size of a point is determined by the current values stored in the attribute list.
➔ For a raster system: Point size is an integer multiple of the pixel size, so that a large point is displayed as a square block of pixels.
33
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Line Attribute
34
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Curve Attribute
35
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
➔ Raster curves of various widths can be displayed using the method of horizontal or vertical pixel spans.
36
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
�OpenGL Point-Attribute Functions �
1.Color:glColor(r,g,b);
2. Size: glPointSize (size);
glPointSize(GLfloat size);
Example : glColor3f ( 1.0, 0.0,0.0);
37
glBegin(GL_POINTS);
glVertex2i(50,100);
glPointSize(2.0);
glColor3f ( 0.0, 1.0, 0.0);
glVertex2i(75,150);
glPointSize(3.0);
glColor3f ( 0.0, 0.0, 1.0);
glVertex2i(100,200);
glEnd ( );
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
OpenGL Line-Attribute Functions
( 0xFFFF with each bit position 1 )
default is a solid line Repeat
factor specifies how many
times each bit in the
pattern is repeated before
the next bit in the pattern
is applied.- Default value is 1
38
Example:
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0x00FF); // Plot dashed double width line
glLineWidth(2.0);
lineplot( ) ; // plot the line
glLineStipple(1, 0x0101); \\Plot dotted triple width line
glLineWidth(3.0);
lineplot();
glDisable(GL_LINE_STIPPLE);
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Line Drawing Algorithm
39
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Line Drawing Algorithm
Where,(x, y) = axis of the line.
and (xend, yend), then m and b
can be calculated as:
m = y / x = (yend – y0) / (xend – x0)
b = y0 - m . x0
40
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Line Drawing Algorithm
41
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Digital Differential Analyzer
42
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
y = mx + c
m = (y2 – y1)/ (x2– x1)
43
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
�
44
m = (y
2
–
y
1
)/ (x
2
–
x
1
)
Now, we consider one point
(x
k
, y
k
)
and
(x
k+1
, y
k+1
)
as the next point
.
Then the slope
m = (y
k+1
–
y
k
)/ (x
k+1
–
x
k
)
Now, we have to find the slope between the starting point and ending point. There can be following three cases todiscuss:
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Algorithm of (DDA) Line Drawing
45
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Advantages of Digital Differential Analyzer
46
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Disadvantages of Digital Differential Analyzer
47
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Bresenham’s Algorithm
48
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Bresenham’s Algorithm
1.The distance between y and yk+1= d
2. Now, we have to decide which point is nearest to the intersection point.
49
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
y=yk +1{Unit Interval}
As we know the equation of a line- y = mx +b
y = m(xk +1) +b …………. (1)
50
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Bresenham’s Algorithm
51
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Bresenham’s Algorithm
52
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Bresenham’s Algorithm
53
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Bresenham’s Algorithm
54
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Bresenham’s Algorithm Steps
55
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Advantages of Bresenham’s Line Drawing Algorithm
�
56
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
Disadvantages of Bresenham’s Line Drawing Algorithm:
57
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in
58
Sri Krishna Institute of Technology
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
/skit.org.in
/skit.org.in