Unit 4
Unit 4
FUNCTIONS
Submitted By:-
2K20/CO/415 Satyam Yadav
2K20/CO/423 Shaurya Garg
OpenGL 2D Viewing:
• OpenGL designed for 3D.
• Some 3D viewing routines can be adapted.
• Core library does support a viewport function
• GLU provides 2D clipping function
• GLUT allows one to manipulate display windows
OpenGL Projection Mode
• OpenGL does not support a separate viewing coordinate system
• Set clipping window as part of projection transformation.
• To specify projection transformation, first get into the correct
matrix mode:
glMatrixMode(GL_PROJECTION);
For good measure can also set identity matrix:
glLoadIdentity()
GLU Clipping Window
• To specify the clipping window do:
gluOrtho2D(xwmin, xwmax, ywmin, ywmax);
• Coordinates are doubles.
• For 3D the effect of the above is to project out the z-axis.
• Has no effect on 2D scenes except to map to normalized
coordinates.
• For OpenGL these have range between -1,1.
OpenGL Viewport Function
• To specify the viewport use:
glViewport(xvmin, yvmin, vpWidth, vpHeight);
• xvmin, yvmin specify the position of the lower left corner of the
viewport relative to the bottom of the display window.
• vpWidth, vpHeight give width and height.
• To get the info about the currently active viewport can use:
glGetIntegerv(GL_VIEWPORT, vpArray);
• vpArray is a four element array
GLUT Display Windows
• GLUT is used to manipulate display windows for the programs we
have been writing.
• To start up GLUT:
glutInit(&argc, argv);
• Then to set up the display window:
glutInitWindowPosition(xTopLeft, yTopLeft);
glutInitWindowSize(dwWidth, dwHeight);
glutCreateWindow(“Title”);
• The windowing system can choose to ignore info passed by GLUT
• At this point window is not yet displayed
Display Mode and Color
• Next we set the display window parameters with:
glutInitDisplayMode(mode);
• To set the background color:
glClearColor(red, green, blue, alpha);
or in index mode:
glClearIndex(index);
Window IDs
• When create a window can obtain its ID:
windowID = glutCreateWindow(“my window”);
• IDs start at 1.
• Can use ID to get rid of a display window:
glutDestroyWindow(windowID);
• Can use ID to set active display glutSetWindow(windowID);
• To get active window:
currentWindowID = glutGetWindow();
Repositioning and Resizing the Window
• To move the active window to a new position:
glutPositionWindow(x, y);
• To change its size:
glutReshapeWindow(width, height);
• To make the window fullscreen:
glutFullScreen();
• To set a callback which will be called whenever the position or
size of display is changed:
glutReshapeFunc(myfunc);
Managing Multiple Displays
• Glut has many function for manipulating the window. For example:
glutIconifyWindow(); //shrink window to an icon
glutSetWindowTitle(“new title”); // make window front window
glutSetWindow(windowID);
glutPopWindow(); //make window back window
glutSetWindow(windowID);
glutPushWindow();
glutHideWindow(); //take window offscreen
glutShowWindow(); // put onscreen / de-iconify
Thank you
The viewing pipeline and
viewing coordinate reference
frame
◈ Submitted by:
◈ MANAN KHURANA(2K19/CO/211)
◈ NITISH KASHNIA(2K20/CO/310)
◈ Submitted to: Rashmi Yadav
Window
• Area selected in world-coordinate for display is called
window.
Viewport
• Area on a display device in which window image is
display (mapped) is called viewport.
Viewing Transformation
• The mapping of a part of a world-coordinate scene to
device coordinates is referred to as a viewing
transformation.
Viewing pipeline
ywma yvma
x x
ywmi yvmi
n n
xwmi xwma xvmi xvma
ywma yvma
ywmi yvmi
Clipping window:
Panning…
2D Viewing
pipeline 2
World: Clipping window Screen: Viewport
ywma yvma
x
ywmi yvmi
n
xwmi xwma xvmi xvma
Clipping window:
Panning…
2D Viewing
pipeline 3
World: Clipping window Screen: Viewport
ywma yvma
ywmi yvmi
Clipping window:
Zooming…
2D Viewing
pipeline 3
World: Clipping window Screen: Viewport
ywma
yvma
yvmi
ywmi
xwmi xwma xvmi xvma
Clipping window:
Zooming…
Viewing-Coordinate Reference
Frame
• This coordinate system provides the reference frame for
specifying the world- coordinate window. We set up the viewing
coordinate system using transformations between coordinate
system.
Translation Rotation
WINDOW-TO-VIEWPORT
TRANSFORMATION
SATWIK SHRIDHAR (2K20/CO/412)
WINDOWPORT
VIEWPORT
WINDOW TO VIEWPORT MAPPING
TRANSFORMATION &
TRANSLATION
SCALING & SHEARING
INTRODUCTION
❖ Window-to-Viewport mapping is the process of mapping or
transforming a two-dimensional, world-coordinate scene to
device coordinates, In particular, objects inside the world or
clipping window are mapped to the viewport. The viewport
is rectangular area on screen where world coordinates are
mapped to be displayed.
❖ In other words, the clipping window is used to select the
part of the scene that is to be displayed. The viewport is
used to display selected portion of window on the output
device.
WINDOW TO
VIEWPORT
TRANSFORMATION
● WINDOW PORT: A world coordinate area selected
for display.
● WINDOW-TO-VIEWPORT TRANSFORMATION is
the process of transforming 2D world-coordinate
objects to device coordinates.
WINDOW TO VIEWPORT MAPPING
CONCEPT OF TRANSFORMATION
EXAMPLE
ADVANTAGES
APPLICATIONS
Line Clipping
Line clipping is technique in
computer graphics used to display a
given set of lines in our desired
window, computer screen on
rectangular area of interest.
It helps to remove those lines lying
outside the windows.
Liang-Barsky algorithm
The Liang-Barsky algorithm is a line clipping algorithm. This algorithm is more
efficient than Cohen–Sutherland line clipping algorithm and can be extended to
3-Dimensional clipping.
the above equations can be expressed as tpk <= qk, where p and q are defined as:
01 02 03 04
Write a specific Obtain pk and qk check which case find if the line
Set line for k =1: 4 is true for the can be rejected or
intersection and forming the corresponding intersection
parameters t- table. values of pk and parameters (t1 and
entry (t1) = 0.0 qk t2) must be
and t-leaving (t2) adjusted.
= 1.0
Step 1
Set line intersection parameters tentry (t1) = 0.0 and tleaving (t2) = 1.0
Step 2
Obtain pk and qk for k =1: 4
Step 3
If pk = 0, the line is parallel to the corresponding clipping boundary.
Where,
P0 = Initial Point of line
P1 = Ending Point of line
dx = horizontal distance between P0 and P 1
dy = vertical distance between P0 and P 1
Now check for :
p1 (LEFT EDGE )
Now check for :
p2 (RIGHT EDGE )
Now check for :
p3 (BOTTOM EDGE )
Now check for :
p4 (TOP EDGE )
CLIPPED
LINE
New P0 ( x0 + t1* dx , y0 + t1*dy )
= ( 30 + t1*250 , 20 + t1*140 )
= ( 101.425 , 59.998 )
New P1 ( x0 + t2*dx , y0 + t2*dy )
= ( 230 , 132 )
ADVANTAGES
More efficient.
Only requires one division to
update 𝑡1 and 𝑡2.
Window intersections of line
are calculated just once.
APPLICATIONS
Drawing and painting operations that allow parts of a
picture to be selected for copying, moving, erasing, or
duplicating.
Extracting part of a defined scene for viewing
Identifying visible surfaces in three-dimensional views
Antialiasing line segments or object boundaries
Creating objects using solid-modeling procedures
Displaying a multi window environment;
Thank you !
ALGORITHM FOR
POLYGON
CLIPPING
Sorabh Guliya (2K20/CO/444)
When we have to display a large portion of the picture, then not only scaling &
translation is necessary, the visible part of picture is also identified. This process is
not easy as certain parts of the image are inside, while others are partially inside.
The lines or elements which are partially visible are omitted.
For deciding the visible and invisible portion, a particular process called clipping is
used. Clipping determines each element into the visible and invisible portion.
Visible portion is selected and the invisible portion is discarded.
TYPES OF CLIPPING
Point Clipping
Line Clipping
Polygon Clipping (Area Clipping)
Curve Clipping
Text Clipping
Exterior Clipping
POLYGON CLIPPING
If the first vertex is outside the window & the second vertex
is inside the window. Then second vertex is added to the
output list. The point of intersection of window boundary and
polygon side (edge) is also added to the output line.
It was developed to clip a fill area that is either a convex polygon or a concave polygon. The basic idea
of this algorithm is that instead of proceeding around the polygon edges, we will follow the window
boundaries.
One of the drawbacks of Sutherland hodgeman algo was that it could clip the convex polygon correctly,
but there was an inclusion of extraneous lines while clipping concave polygon.
Cohen-Sutherland Wiler-Athurten
Algorithm Algorithm
New Convention:
Intersecting Polygon is called Subject Polygon and
Clipping Windows is called Clip Polygon
Clipping Polygon
Subject Polygon
Step – 01
Finding the Intersection of
Subject Polygon with Clipping
Polygon
Step 02: Marking the intersection point and
Adding the Points of Polygon to table in clockwise
Direction
C2 C3
A A’ B
C
D’
D
E’
E
G F’ F
C1 C4
Step 02: Marking the intersection point and
Adding the Points of Polygon to table in clockwise
Subject Clipping Direction
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
B E’
C D’
C
D’ A’
D’
D C2 D
E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 03: We traverse through the points until
intersection point is reached
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
B E’
C D’
C
D’ A’
D’
D C2 D
E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 03: We traverse through the points until
intersection point is reached
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
B E’
C D’
C
D’ A’
D’
D C2 D
E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 04: We keep on noting the Points in another
Table until another intersection point is
encountered.
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 B E’
A’ C D’
C
D’ A’
D’
D C2 D
E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 04: We keep on noting the Points in another
Table until another intersection point is
encountered.
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 B E’
A’ C D’
C
B D’ A’
D’
D C2 D
E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 04: We keep on noting the Points in another
Table until another intersection point is
encountered.
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 B E’
A’ C D’
C
B D’ A’
D’
C D C2 D
E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 04: We keep on noting the Points in another
Table until another intersection point is
encountered.
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 B E’
A’ C D’
C
B D’ A’
D’
C D C2 D
D’ E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 04: Then Move to the Clipping Polygon For
finding the end points.
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 B E’
A’ C D’
C
B D’ A’
D’
C D C2 D
D’ E’ C3
E’
E C4 E
F G F’ F
F’
G C1 C4
Step 04: Then Move to the Clipping Polygon For
finding the end points.
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 B E’
A’ C D’
C
B D’ A’
D’
C D C2 D
D’ E’ C3
E’
E C4 E
A’
F G F’ F
F’
G C1 C4
Step 05: Further Repeating the Steps 03 & 04 for
all the Points
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 B E’
A’ C D’
C
B D’ A’
D’
C D C2 D
D’ E’ C3
E’
E C4 E
A’
F G F’ F
F’
G C1 C4
Step 05: Further Repeating the Steps 03 & 04 for
all the Points
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 Poly. 2 B E’
A’ E’ C D’
C
B E D’ A’
D’
C F D C2 D
D’ F’ E’ C3
E’
E C4 E
A’
F G F’ F
F’
G C1 C4
Step 05: Further Repeating the Steps 03 & 04 for
all the Points
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 Poly. 2 B E’
A’ E’ C D’
C
B E D’ A’
D’
C F D C2 D
D’ F’ E’ C3
E’
E C4 E
A’
F G F’ F
F’
G C1 C4
Step 05: Further Repeating the Steps 03 & 04 for
all the Points
Subject Clipping
Polygon Polygon
A C1 C2 C3
A’ F’
A A’ B
Poly. 1 Poly. 2 B E’
A’ E’ C D’
C
B E D’ A’
D’
C F D C2 D
D’ F’ E’ C3
E’
E C4 E
A’ E’
F G F’ F
F’
G C1 C4
The Figure we get from Using Polygon-1 Table and
Polygon-2 Table
C2 C3
Poly. 1 Poly. 2 A A’ B
A’ E’
B E C
C F D’
D
D’ F’
A’ E’ E’
E
G F’ F
A’ B E’ C1 C4
C E
F’ F
D’
The Figure we get from Using Polygon-1 Table and
Polygon-2 Table
C2 C3
Poly. 1 Poly. 2
A’ E’
B E
A’ B
C F
D’ F’ C
A’ E’ No extra line like
D’ Cohen-Sutherland
Algorithm
A’ B E’ C1 C4
C E E’
E
F’ F
D’
F’ F
Made By:-
Tejas Jain
2K20/CO/460
&
TANMAY TANEJA
2K20/CO/456
THANK YOU!!!