21CSL66 Lab Manual
21CSL66 Lab Manual
21CSL66 Lab Manual
VI Semester
Course Code: 21CSL66
Editorial Committee
Computer Graphics Lab Faculty, Dept. of CSE
Approved by
H.O.D, Department of CSE
Document Log
Laboratory
Scheme 2021
Subject code 21CSL66
Editorial Committee Dr. Shalini S
Dr. Nagaraj M
Lutimath
Prof. Manasa
Sandeep
Computer Programmer Mr. Vinay Kumar
Approved by HOD, Dept. of CSE
Table of Contents
4 CHAPTER 1 Introduction 11
PART A
List of problems for which student should develop program and execute in the
Laboratory using openGL/openCV/ Python
Program 1 Develop a program to draw a line using Bresenham’s 26
line drawing technique
Program 2 Develop a program to demonstrate basic geometric 31
operations on the 2D object
Program 3 Develop a program to demonstrate basic geometric 33
operations on the 3D object
Program 4 Develop a program to demonstrate 2D transformation 36
on basic objects
Develop a program to demonstrate 3D transformation 39
Program 5
on 3D objects
Develop a program to demonstrate Animation effects 43
Program 6
on simple objects.
Write a Program to read a digital image. Split and
45
Program 7 display image into 4 quadrants, up, down, right and
left.
Write a program to show rotation, scaling, and 48
Program 8
translation on an image.
Read an image and extract and display low-level
53
Program 9 features such as edges, textures using filtering
techniques
Write a program to blur and smoothing an image.
Program 10
M2: Enhancing the knowledge in the changing technology trends by giving hands-on
experience through continuous education and by making them to organize & participate in
various events.
M3: Impart skills in the field of IT and its related areas with a focus on developing the
required competencies and virtues to meet the industry expectations.
M4: Ensure quality research and innovations to fulfill industry, government & social needs.
M5: Impart entrepreneurship and consultancy skills to students to develop self-sustaining life
skills in multi-disciplinary areas.
PSO2: Foundation of Computer System: Ability to interpret the fundamental concepts and
methodology of computer systems. Students can understand the functionality of hardware and
software aspects of computer systems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
Syllabus
Laboratory Experiments:
Practice Programs
Installation of OpenGL /OpenCV/ Python and required headers
Simple programs using OpenGL (Drawing simple geometric object like line, circle,
rectangle, square)
Simple programs using OpenCV (operation on an image/s)
PART A – PROGRAMS
List of problems for which student should develop program and execute in the
Laboratory using openGL/openCV/ Python
1. Develop a program to draw a line using Bresenham’s line drawing technique
2. Develop a program to demonstrate basic geometric operations on the 2D object
3. Develop a program to demonstrate basic geometric operations on the 3D object
4. Develop a program to demonstrate 2D transformation on basic objects
5. Develop a program to demonstrate 3D transformation on 3D objects
6. Develop a program to demonstrate Animation effects on simple objects.
7. Write a Program to read a digital image. Split and display image into 4 quadrants,
up, down,
right and left.
8. Write a program to show rotation, scaling, and translation on an image.
9. Read an image and extract and display low-level features such as edges, textures
using
filtering techniques.
10. Write a program to blur and smoothing an image.
11. Write a program to contour an image.
12. Write a program to detect a face/s in an image.
Student should develop a mini project and it should be demonstrate in the laboratory
examination, Some of the projects are listed and it is not limited to:
Recognition of License Plate through Image Processing
Recognition of Face Emotion in Real-Time
Detection of Drowsy Driver in Real-Time
Recognition of Handwriting by Image Processing
Detection of Kidney Stone
Verification of Signature
Compression of Color Image
Classification of Image Category
Detection of Skin Cancer
Marking System of Attendance using Image Processing
Detection of Liver Tumor
IRIS Segmentation
Detection of Skin Disease and / or Plant Disease
Biometric Sensing System
CO-PO-PSO MAPPING
Course PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
21CSL66.1 3 3 3 - - - - - - - - - 3 -
21CSL66.2 3 3 3 - - - - - - - - - 3 -
21CSL66.3 3 3 3 - - - - - - - - - 3 -
21CSL66.4 3 3 3 - - - - - - - - - 3 -
Avg 3 3 3 - - - - - - - - - 3 -
The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam (SEE) is 50%.
The minimum passing mark for the CIE is 40% of the maximum marks (20 marks). A student shall be deemed
to have satisfied the academic requirements and earned the credits allotted to each course. The student has to
secure not less than 35% (18 Marks out of 50) in the semester-end examination (SEE).
General rubrics suggested for SEE are mentioned here, writeup-20%, Conduction procedure and
result in -60%, Viva-voce 20% of maximum marks. SEE for practical shall be evaluated for 100 marks
and scored marks shall be scaled down to 50 marks (however, based on course type, rubrics shall be
decided by the examiners)
Students can pick one experiment from the questions lot of PART A with equal choice to all the
students in a batch.
PART B : Student should develop a mini project and it should be demonstrated in the laboratory
examination (with report and presentation).
Weightage of marks for PART A is 60% and for PART B is 40%. General rubrics suggested to be
followed for part A and part B.
Change of experiment is allowed only once (in part A) and marks allotted to the procedure part to be
made zero.
The duration of SEE is 03 hours.
OpenGL is a software interface to graphics hardware. This interface consists of about 150
distinct commands that you use to specify the objects and operations needed to produce
interactive three-dimensional applications.
OpenGL programs can work across a network even if the client and server are different
kinds of computers. If an OpenGL program isn't running across a network, then there's only
one computer, and it is both the client and the server.
Advantages of OpenGL
Software’s required:
1. Codeblocks
2. The important files and libraries for running the OpenGL application are:
gl.h glu.h opengl32.libglu32.lib
1. Click start
2. Choose All Programs
3. Select Codeblocks
4. Choose File → New → Project. You get the following Dialogbox
Note: By default, the window has a size of (300, 300) pixels, and its position
is up to the window manager to choose.
#include<glut.h>
void display () /* callback function which is called when OpenGL needs to update the display */
{
glClearColor (1.0,1.0,0.0,0.0); /*defaultcolor–black… .................... Now set to YELLOW*/
glClear (GL_COLOR_BUFFER_BIT); /*Clear the window-set the color of pixels in buffer*/
glFlush(); /* Force update of screen */
}
#include<glut.h>
void display (void)
{
glClearColor (0.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void main (int argc, char **argv)
{
glutInit (&argc, argv); /* Initialise OpenGL */
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
2. Drawing pixels/points
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2i(100,300);
glVertex2i(201,300);
glEnd();
glFlush();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0); // set the window color to white
glColor3f(1.0,0.0,0.0); // set the point color to red (RGB)
glPointSize(5.0); // set the pixel size
gluOrtho2D(0.0,500.0,0.0,500.0); // coordinates to be used with the
//viewport(left,right,bottom,top)
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); // sets the initial display mode, GLUT single-default
glutInitWindowSize(300,300);
glutInitWindowPosition(0,0);
glutCreateWindow("Example2");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
#include<GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2i(10,10);
glVertex2i(250,250);
glVertex2i(10,490);
glVertex2i(490,490);
glVertex2i(490,10);
glEnd();
glFlush();
}
voidmyinit()
{
glClearColor(0.0,0.0,1.0,0.0); // set the window color to blue
glColor3f(0.0,1.0,1.0); // set the point color to cyan (RGB)
glPointSize(10.0);
gluOrtho2D(0.0,500.0,0.0,500.0); // coordinates to be used with the viewport left, right,
bottom, top)
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Activity2");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
3. Drawing lines
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
#include<glut.h>
void display()
{
#include<GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glLineWidth(3.0);
glBegin(GL_LINE_LOOP); // If you put GL_LINE_LOOP, it is only boundary.
glVertex2f(50, 50);
glVertex2f(200, 50);
glVertex2f(200, 200);
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 1.0, 0.0); // set line color to green
glLineWidth(3.0);
glBegin(GL_POLYGON);
glVertex2f(50, 50);
glVertex2f(200, 50);
glVertex2f(200, 200);
glVertex2f(50, 200);
glEnd();
glFlush();
}
void myinit()
{
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glLineWidth(3.0);
glBegin(GL_TRIANGLES);
glVertex2i(100,100);
glVertex2i(250,100);
glVertex2i(250,300);
glEnd();
glFlush();
}
void myinit()
{
glClearColor(0.0,0.0,0.0,0.0);
gluOrtho2D(0.0,499.0,0.0,499.0);
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(300,300);
glutInitWindowPosition(0,0);
glutCreateWindow("TRIANGLE");
glutDisplayFunc(display);
myinit();
6. Writing Text
#include<glut.h>
void output(GLfloat x,GLfloat y,char *text)
{
char*p;
glPushMatrix();
glTranslatef(x,y,0);
glScaled(0.2,0.2,0);
for(p=text;*p;p++)
glutStrokeCharacter(GLUT_STROKE_ROMAN,*p);
glPopMatrix();
}
void display
{
glClear(GL_COLOR_BUFFER_BIT);
output(10,300,"GLOBAL ACADEMY OF TECHNOLOGY");
glFlush();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
gluOrtho2D(0.0,499.0,0.0,499.0);
}
void main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("DSATM");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
#include<glut.h>
#include<string.h>
#include<glut.h>
void output(GLfloat x,GLfloat y,char *text)
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 1.0, 0.0); // Green
glBegin(GL_POLYGON);
glVertex2f(100, 100);
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glViewport (5,-150,400,400);
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex2f(90,250);
glColor3f(0.0,1.0,0.0);
glVertex2f(250,250);
glColor3f(0.0,0.0,1.0);
glVertex2f(175,400);
glEnd();
glViewport (300,300,400,400);
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
Output:
Bresenham's line algorithm is named after Jack Elton Bresenham who developed it in 1962 at IBM. It is
commonly used to draw line primitives in a bitmap image (e.g. on a computer screen), as it uses only
integer addition, subtraction and bit shifting, all of which are very cheap operations in standard computer
architectures. It is an incremental error algorithm.
#include<windows.h>
#include<stdio.h>
#include<math.h>
#include<gl/glut.h>
GLint X1,Y1,X2,Y2;
void LineBres(void)
{
glClear(GL_COLOR_BUFFER_BIT);
int dx=abs(X2-X1),dy=abs(Y2-Y1);
int p=2*dy-dx;
int twoDy=2*dy,twoDyDx=2*(dy-dx);
int x,y;
if(X1>X2)
{
x=X2;
y=Y2;
X2=X1;
}
else
{
x=X1;
y=Y1;
X2=X2;
}
glBegin(GL_POINTS);
glVertex2i(x,y);
while(x<X2)
{
x++;
if(p<0)
void Init()
{
glClearColor(1.0,1.0,1.0,0);
glColor3f(0.0,0.0,0.0);
glPointSize(4.0);
glViewport(0,0,50,50);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,50,0,50);
}
int main(int argc,char **argv)
{
printf("enter two points for draw lineBresenham:\n");
printf("\n enter point1(X1,Y1):");
scanf("%d%d",&X1,&Y1);
printf("\n enter point2(X2,Y2):");
scanf("%d%d",&X2,&Y2);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(300,400);
glutInitWindowPosition(0,0);
glutCreateWindow("LineBresenham");
Init();
glutDisplayFunc(LineBres);
glutMainLoop();
}
#include<windows.h>
#include<stdio.h>
#include<math.h>
#include<gl/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0, 1.0, 1.0, 1);
glMatrixMode(GL_MODELVIEW);
glColor3f(0.0,0.0,1.0);
glBegin(GL_TRIANGLES);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_TRIANGLES);
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glEnd();
glFlush();
}
void idlefunc()
{
theta[flag]++;
if(theta[flag]>360)theta[flag]=0;
glutPostRedisplay();
}
void mousefunc(int button,int status,int x,int y)
{
if(button==GLUT_LEFT_BUTTON&&status==GLUT_DOWN)
flag=2;
if(button==GLUT_MIDDLE_BUTTON&&status==GLUT_DOWN)
flag=1;
if(button==GLUT_RIGHT_BUTTON&&status==GLUT_DOWN)
flag=0;
}
void drawpoly(int a,int b,int c1,int d)
{
glBegin(GL_POLYGON);
glColor3fv(c[a]);
glVertex3fv(v[a]);
glColor3fv(c[b]);
glVertex3fv(v[b]);
glColor3fv(c[c1]);
Dept. of CSE, DSATM 36 CG Lab with mini Project – 18CSL67
glVertex3fv(v[c1]);
glColor3fv(c[d]);
glVertex3fv(v[d]);
glEnd();
}
void colorcube()
{
drawpoly(0,1,2,3);
drawpoly(0,1,5,4);
drawpoly(1,5,6,2);
drawpoly(4,5,6,7);
drawpoly(3,2,6,7);
drawpoly(0,4,7,3);
}
void display()
{
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,0,0);
glEnable(GL_DEPTH_TEST);
glLoadIdentity();
glRotatef(theta[0],1,0,0);//x
glRotatef(theta[1],0,1,0);//y
glRotatef(theta[2],0,0,1);//z
colorcube();
glFlush();
glutSwapBuffers();
}
void main()
{
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE |GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow("cube rotation");
myinit();
glutDisplayFunc(display);
glutMouseFunc(mousefunc);
glutIdleFunc(idlefunc);
glutMainLoop();
}
Program 4
#include<windows.h>
#include<stdio.h>
#include<math.h>
#include<gl/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(1.0, 1.0, 1.0, 1);
glMatrixMode(GL_MODELVIEW);
glColor3f(0.0,0.0,1.0);
glRecti(250,300,400,350);
glPushMatrix();
/* Translate Operation*/
glColor3f(1.0,0.0,0.0);
glTranslatef(-100.0,-50,0.0);
glRecti(250,300,400,350);
glPushMatrix();
/* Rotate Operation*/
glRotatef(20, 0.0, 0.0, 1.0);
glRecti(250,300,400,350);
glPopMatrix();
glPushMatrix();
/* Scale Operation*/
glScalef(0.5, 1.0, 1.0);
glRecti(250,300,400,350);
glPopMatrix();
glFlush();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1000, 1000);
glutCreateWindow("Geometric Operations on 2D Objects");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 500, 0, 500);
glutDisplayFunc(display);
glutMainLoop();
}
OUTPUT
#include<stdio.h>
#include<GL/glut.h>
float v[4][3] = { {-1,-0.25,0},{1,-0.25,0}, {0,1,0}, {0,0,1} };
int n;
void myinit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2, 2, -2, 2, -2, 2);
glMatrixMode(GL_MODELVIEW);
}
void draw_triangle(float *a,float *b, float * c)
{
glBegin(GL_POLYGON);
glVertex3fv(a);
glVertex3fv(b);
glVertex3fv(c);
glEnd();
}
}
// consider midpoints as vertex and divide bigger triangle
// to 3 parts recursively
divide_tetrahedron(a, ab, ac, ad, m - 1);
divide_tetrahedron(ab, b, bc, bd, m - 1);
divide_tetrahedron(ac, bc, c, cd, m - 1);
divide_tetrahedron(ad, bd, cd, d, m - 1);
//note if u want the colors of phases to align just adjudt the above points
}
//draw the sub divided traingles
else {
draw_tetera(a, b, c, d);
}
}
n = 2;
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("3DGasket"); //window with a title
myinit();
glutDisplayFunc(display);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0, 1.0, 1.0, 1.0);
glutMainLoop();
}
OUTPUT
#include<glut.h>
#include<stdio.h>
#include<math.h>
#define PI 3.1416
typedef structwcPt3D
{
GLfloat x, y,z;
};
voiddisplayFunc()
{
GLint nCtrlPts = 4, nBezCurvePts = 20;
static float theta =0;
wcPt3DctrlPts[4] ={
{ 20, 100, 0},
{ 30, 110, 0},
{ 50, 90, 0 },
{ 60, 100, 0 } };
ctrlPts[1].x += 10 * sin(theta * PI / 180.0);
ctrlPts[1].y += 5 * sin(theta * PI / 180.0);
ctrlPts[2].x -= 10 * sin((theta + 30) * PI / 180.0);
ctrlPts[2].y -= 10 * sin((theta + 30) * PI / 180.0);
ctrlPts[3].x -= 4 * sin((theta)* PI / 180.0);
ctrlPts[3].y += sin((theta - 30) * PI / 180.0);
voidmenu(int num)
{
if(num == 0)
{
glutDestroyWindow(window);
exit(0);
}
else
{
value = num;
}
glutPostRedisplay();
}
voidcreateMenu(void)
{
submenu_id = glutCreateMenu(menu);
glutAddMenuEntry("draw a flag", 2);
menu_id = glutCreateMenu(menu);
glutAddMenuEntry("Clear", 1);
glutAddSubMenu("Draw", submenu_id);
glutAddMenuEntry("Quit", 0);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
OUTPUT
Write a Program to read a digital image. Split and display image into 4 quadrants, up, down, right
and left.
import cv2
img = cv2.imread("D:/DSATM/CG/CG&DIP/Lab_Images/Prog7_flower.jpg")
original= img
h, w, channels = img.shape
half_width = w//2
half_height = h//2
cv2.imshow('originalImage',original)
cv2.imshow('TopLeft_Quadrant', TopLeft_quadrant)
cv2.imshow('TopRight_Quadrant', TopRight_quadrant)
cv2.imshow('BottomLeft_Quadrant', BottomLeft_quadrant)
cv2.imshow('BottomRight_Quadrant', BottomRight_quadrant)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
import cv2
import numpy as np
image = cv2.imread('D:/DSATM/CG/CG&DIP/Lab_Images/Prog7_flower.jpg')
# Apply rotation
rotated_image = apply_rotation(image, angle)
# Apply scaling
scaled_image = apply_scaling(image, scale_x, scale_y)
# Apply translation
translated_image = apply_translation(image, tx, ty)
OUTPUT
Read an image and extract and display low-level features such as edges, textures using filtering
techniques.
import cv2
import numpy as np
# Edge detection
edges = cv2.Canny(gray, 100, 200)
# Texture extraction
kernel = np.ones((5, 5), np.float32) / 25 # Define a 5x5 averaging kernel
texture = cv2.filter2D(gray, -1, kernel) # Apply the averaging filter for texture extraction
OUTPUT
import cv2
# Gaussian Blur
gaussian_blur = cv2.GaussianBlur(image, (5, 5), 0)
# Median Blur
median_blur = cv2.medianBlur(image, 5)
Program 11
Write a program to contour an image.
import cv2
import numpy as np
# Find contours
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
OUTPUT
import cv2
OUTPUT
2. What would happen to the RGB color values set to 3.0 OR-7.0?
If the color is set to 3.0, it is reset to 1.0 If the
color is set to -7.0, it is reset to 0.0
Each color takes a min value as 0.0 and max value as 1.0
3. List differentprimitives.
GL_POINTS: Each vertex is displayed at a size of at least one pixel.
GL_LINES: Successive pairs of vertices would be connected as aline.
GL_LINE_STRIP: Connects the successive vertices using line segments. However the final vertex would
not be connected to the initialvertex.
GL_LINE_LOOP: Connects the successive vertices using line segments to form a closedpath.
GL_POLYGON: Connects the successive vertices using line segments to forma closed path. The interior
is filled according to the state of the relevantattributes.
GL_QUADS: Special case of polygon where successive group of 4 vertices are interpreted
asquadrilaterals.
GL_TRIANGLES: Special case of polygon where successive group of three vertices would be interpreted
as atriangle.
GL_TRIANGLE_STRIP: Each additional vertex is combined with the previous two vertices to define a
newtriangle.
GL_QUAD_STRIP: Wecombine two new vertices with the previous two verticesto design a
newquadrilateral.
GL_TRIANGLE_FAN: Based on one fixed point. The next two points determine the first triangle. The
subsequent triangles are formed from one new point, the previous point and the first (fixed)point.
gluOrtho2D()
gluOrtho2D sets up a two-dimensional orthographic viewing region. This is equivalent to calling
glOrtho with near = -1 and far = 1 .
Syntax :
glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
Parameters
left, right : Specify the coordinates for the left and right vertical clipping planes.
bottom, top : Specify the coordinates for the bottom and top horizontal clippingplanes.
15. In Sierpinski gasket, if the no. of divisions=2, how many triangles areformed?
Sierpinski gasket is a tetrahedran, hence there are 4 triangles.
If no. of divisions n=0, the no. of triangles=4, If n=1, the no. of triangles=4*3=12
If n=2, the no. of triangles=4*3*3=4*32 Hence if n is the no. of divisions, triangles formed = 4 * 3n
22. In Cohen-Sutherland line clipping algorithm, what is the condition for trivial accept and
trivial reject?
Trivial accept:
a. Both end points have to be in the region with code0000.
b. Trivial accept happens only if code1 | code2 = 0000
Trivial reject:
a. Codes of both end points will have 1 in the same bitposition.
b. Trivial reject happens only if code1 & code2 != 0000