CGV Lab Manual 2021-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

C BYREGOWDA INSTITUTE OF TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


Affiliated to Visvesvaraya Technological University
“Jnana Sangama”, Belgaum – 560 018.

LABORATORY MANUAL
“COMPUTER GRAPHICS LABORATORY WITH MINI
PROJECT – 17CSL68 & 18CSL67”

Semester: VI Scheme: CBCS

Prepared By

Prof. JAYASHREE N
Assistant Professor, Dept. of CSE.

Scrutinized By

Dr. S N CHANDRASHEKARA
Professor & HOD, Dept. of CSE, CBIT

C BYREGOWDA INSTITUTE OF TECHNOLOGY


Department of Computer Science and Engineering
An ISO 9001:2015 Certified Institute
Kolar – Srinivaspur Road,
Kolar – 563101
2020-21
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT
[As per Choice Based Credit System (CBCS) scheme]
(Effective from the academic year 2017 -2018)
SEMESTER – VI
Subject Code 17CSL68/18CSL67 IA Marks 40
Number of Lecture 01I + 02P Exam Marks 60
Hours/Week
Total Number of 40 Exam Hours 03
Lecture Hours
Course objectives: This course will enable students to
• Demonstrate simple algorithms using OpenGL Graphics Primitives and attributes.
• Implementation of line drawing and clipping algorithms using OpenGL functions
• Design and implementation of algorithms Geometric transformations on both 2D
and 3D objects.

Lab Experiments

PART A
Design, develop, and implement the following programs using OpenGL API
1. Implement Brenham’s line drawing algorithm for all types of slope.
Refer:Text-1: Chapter 3.5 Refer:Text-2: Chapter 8
2. Create and rotate a triangle about the origin and a fixed point.
Refer:Text-1: Chapter 5-4
3. Draw a color cube and spin it using OpenGL transformation matrices.
Refer:Text-2: Modeling a Colored Cube
4. Draw a color cube and allow the user to move the camera suitably to experiment
with perspective viewing.
Refer:Text-2: Topic: Positioning of Camera
5. Clip a lines using Cohen-Sutherland algorithm.
Refer:Text-1: Chapter 6.7 Refer:Text-2: Chapter 8
6. To draw a simple shaded scene consisting of a tea pot on a table. Define suitably the
position and properties of the light source along with the properties of the surfaces of
the solid object used in the scene.
Refer:Text-2: Topic: Lighting and Shading
7. Design, develop and implement recursively subdivide a tetrahedron to form 3D
Sierpinski gasket. The number of recursive steps is to be specified by the user.
Refer: Text-2: Topic: Sierpinski gasket.
8. Develop a menu driven program to animate a flag using Bezier Curve algorithm.
Refer: Text-1: Chapter 8-10
9. Develop a menu driven program to fill the polygon using scan line algorithm.
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)
Project
PART –B ( MINI-PROJECT)
Student should develop mini project on the topics mentioned below or similar applications
using OpenGL API. Consider all types of attributes like color, thickness, styles, font,
background, speed etc., while doing mini project.
(During the practical exam: the students should demonstrate and answer Viva-Voce)
Sample Topics:
Simulation of concepts of OS, Data structures, algorithms etc.
Course outcomes: The students should be able to:
• Apply the concepts of computer graphics
• Implement computer graphics applications using OpenGL
• Animate real world problems using OpenGL
Conduction of Practical Examination:
1. All laboratory experiments from part A are to be included for practical examination.
2. Mini project has to be evaluated for 30 Marks as per 6(b)
3. Report should be prepared in a standard format prescribed for project work.
4. Students are allowed to pick one experiment from the lot.
5. Strictly follow the instructions as printed on the cover page of answer script.
6. Marks distribution:
a) Part A: Procedure + Conduction + Viva:10 + 35 +5 =50 Marks
b) Part B: Demonstration + Report + Viva voce = 15+10+05 = 30 Marks
7. Change of experiment is allowed only once and marks allotted to the procedure part
to be made zero.
Reference books
1. Donald Hearn & Pauline Baker: Computer Graphics-OpenGL Version,3rd Edition,
Pearson Education,2011
2. Edward Angel: Interactive computer graphics- A Top Down approach with OpenGL,
5th edition. Pearson Education, 2011.
3. M M Raikar, Computer Graphics using OpenGL, Fillip Learning / Elsevier,
Bangalore / New Delhi (2013).

Dept. of CSE, CBIT, Kolar. 2 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)

INTRODUCTION

OpenGL

OpenGL (Open Graphics Library) is an application program interface (API) that is used to define
2D and 3D computer graphics.
The interface consists of over 250 different function calls which can be used to draw
complex three-dimensional scenes from simple primitives. OpenGL was developed by Silicon
Graphics Inc. (SGI) in 1992 and is widely used in CAD, virtual reality, scientific visualization,
information visualization, and flight simulation.
OpenGL's basic operation is to accept primitives such as points, lines and polygons, and
convert them into pixels. This is done by a graphics pipeline known as the OpenGL state
machine.

FEATURES OF OpenGL
• Geometric Primitives Allow you to construct mathematical descriptions of objects.
• Color coding in RGBA (Red-Green-Blue-Alpha) or in color index mode.
• Viewing and Modeling permits arranging objects in a 3-dimensional scene, move our camera
around space and select the desired vantage point for viewing the scene to be rendered.
• Texture mapping helps to bring realism into our models by rendering images of realistic
looking surfaces on to the faces of the polygon in our model.
• Materials lighting OpenGL provides commands to compute the color of any point given the
properties of the material and the sources of light in the room.
• Double buffering helps to eliminate flickering from animations. Each successive frame in an
animation is built in a separate memory buffer and displayed only when rendering of the
frame is complete.
• Anti-aliasing reduces jagged edges in lines drawn on a computer display. Jagged lines often
appear when lines are drawn at low resolution. Anti-aliasing is a common computer graphics
technique that modifies the color and intensity of the pixels near the line in order to reduce the
artificial zig-zag.
• Gouraud shading is a technique used to apply smooth shading to a 3D object and provide
subtle color differences across its surfaces.
• Z-buffering keeps track of the Z coordinate of a 3D object. The Z-buffer is used to keep track
of the proximity of the viewer's object. It is also crucial for hidden surface removal
• Transformations: rotation, scaling, translations, perspectives in 3D, etc.

GLUT FUNCTIONS
The OpenGL Utility Toolkit (GLUT) is a programming interface with ANSI C and FORTRAN
bindings for writing window system independent OpenGL programs.

glutInit :- glutInit is used to initialize the GLUT library.

Syntax:- void glutInit(int *argcp, char **argv);

argcp
A pointer to the program's unmodified argc variable from main. Upon return, the value
pointed to by argcp will be updated, because glutInit extracts any command line options intended
for the GLUT library.
Dept. of CSE, CBIT, Kolar. 3 2020-21
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)
argv
The program's unmodified argv variable from main. Like argcp, the data for argv will be
updated because glutInit extracts any command line options understood by the GLUT library.

glutInitWindowPosition, glutInitWindowSize :-
glutInitWindowPosition and glutInitWindowSize set the initial window position and size
respectively.
Syntax:- void glutInitWindowSize(int width, int height);
void glutInitWindowPosition(int x, int y);

width : Width in pixels.


Height:- Height in pixels.
x :- Window X location in pixels.
Y :- Window Y location in pixels.

glutInitDisplayMode:- glutInitDisplayMode sets the initial display mode.

Syntax:- void glutInitDisplayMode(unsigned int mode);

mode :- Display mode, normally the bitwise OR-ing of GLUT display mode bit masks. Mode can
take following values.
Values Meaning
Bit mask to select an RGBA mode window. This is the
GLUT_RGBA default if neither GLUT_RGBA nor GLUT_INDEX
are specified.
GLUT_RGB An alias for GLUT_RGBA.
GLUT_INDEX Bit mask to select a color index mode window. This
overrides GLUT_RGBA if it is also specified.
GLUT_SINGLE Bit mask to select a single buffered window. This is
the default if neither
GLUT_DOUBLE Bit mask to select a double buffered window. This
overrides GLUT_SINGLE if it is also specified.
GLUT_DEPTH Bit mask to select a window with a depth buffer.

glutMainLoop:- glutMainLoop enters the GLUT event processing loop.


Syntax:- void glutMainLoop(void);
glutCreateWindow:- glutCreateWindow creates a top-level window.
Syntax:- int glutCreateWindow(char *name);
name :- ASCII character string for use as window name.

glutPositionWindow:- glutPositionWindow requests a change to the position of the current


window.
Syntax:- void glutPositionWindow(int x, int y);
x :- New X location of window in pixels.
Y :- New Y location of window in pixels.

glutReshapeFunc :- glutReshapeFunc sets the reshape callback for the current window.
Syntax:- void glutReshapeFunc(void (*func)(int width, int height));
func :- The new reshape callback function.

Dept. of CSE, CBIT, Kolar. 4 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)
glutDisplayFunc:- glutDisplayFunc sets the display callback for the current window.
Syntax:- void glutDisplayFunc(void (*func)(void));
func :- The new display callback function.

glutKeyboardFunc :- glutKeyboardFunc sets the keyboard callback for the current window.
Syntax:- void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y));
func :- The new keyboard callback function.

glutMouseFunc:- glutMouseFunc sets the mouse callback for the current window.
Syntax:- void glutMouseFunc(void (*func)(int button, int state, int x, int y));
func :- The new mouse callback function.
GL FUCTIONS
glBegin & glEnd :- The glBegin and glend functions delimit the vertices of a primitive or a
group of like primitives.
Syntax :- void glBegin( GLenum mode );
mode :- The primitive or primitives that will be created from vertices presented
between glBeginand the subsequent glEnd. The following are accepted symbolic constants and
their meanings:

Value Meaning
GL_POINTS Treats each vertex as a single point. Vertex n defines
point n. N points are drawn.
GL_LINES Treats each pair of vertices as an independent line
segment. Vertices 2n - 1 and 2ndefine line n. N/2 lines are
drawn.
GL_LINE_STRIP Draws a connected group of line segments from the first
vertex to the last. Vertices n and n+1 define line n. N -
1 lines are drawn.
GL_LINE_LOOP Draws a connected group of line segments from the first
vertex to the last, then back to the first. Vertices n and n +
1 define line n. The last line, however, is defined by
vertices N and 1. N lines are drawn.
GL_TRIANGLES Treats each triplet of vertices as an independent triangle.
Vertices 3n - 2, 3n - 1, and 3n define
triangle n. N/3 triangles are drawn.
GL_TRIANGLE_STRIP Draws a connected group of triangles. One triangle is
defined for each vertex presented after the first two
vertices. For odd n, vertices n, n + 1, and n + 2 define
triangle n. For even n, vertices n + 1, n, and n + 2 define
triangle n. N - 2 triangles are drawn.
GL_TRIANGLE_FAN Draws a connected group of triangles. one triangle is
defined for each vertex presented after the first two
vertices. Vertices 1, n + 1, n + 2 define triangle n. N -
2triangles are drawn.
GL_QUADS Treats each group of four vertices as an independent
quadrilateral. Vertices 4n - 3, 4n - 2, 4n - 1, and 4n define

Dept. of CSE, CBIT, Kolar. 5 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)

quadrilateral n. N/4 quadrilaterals are drawn.


GL_QUAD_STRIP Draws a connected group of quadrilaterals. One
quadrilateral is defined for each pair of vertices presented
after the first pair. Vertices 2n - 1, 2n, 2n + 2, and 2n +
1define quadrilateral n. N/2 - 1 quadrilaterals are drawn.
Note that the order in which vertices are used to construct
a quadrilateral from strip data is different from that used
with independent data.
GL_POLYGON Draws a single, convex polygon.
Vertices 1 through N define this polygon.

glclear :- The glClear function clears buffers to preset values.


Syntax:- void glClear(GLbitfield mask);
mask :- Bitwise OR operators of masks that indicate the buffers to be cleared. The four masks are
as follows.

Value Meaning
GL_COLOR_BUFFER_BIT The buffers currently enabled for color writing.
GL_DEPTH_BUFFER_BIT The depth buffer.
GL_ACCUM_BUFFER_BIT The accumulation buffer.
GL_STENCIL_BUFFER_BIT The stencil buffer.

glClearColor:- The glClearColor function specifies clear values for the color buffers.
Syntax :-void glClearColor(red, green, blue, alpha);
red :- The red value that glClear uses to clear the color buffers. The default value is zero.
green :-The green value that glClear uses to clear the color buffers. The default value is zero.
blue :- The blue value that glClear uses to clear the color buffers. The default value is zero.
alpha :-The alpha value that glClear uses to clear the color buffers. The default value is zero.

glColor3i :- Sets the current color.


Syntax :- void glColor3i(GLint red, GLint green, GLint blue);
red :- The new red value for the current color.
green :-The new green value for the current color.
blue :- The new blue value for the current color.

glColor3fv:- Sets the current color from an already existing array of color values.
Syntax :- void glColor3fv(const GLfloat *v);
V:- A pointer to an array that contains red, green, and blue values.

glEnable, glDisable :- The glEnable and glDisable functions enable or disable OpenGL
capabilities.
Syntax :- void glEnable(GLenum cap);
void glDisable(GLenum cap);
cap :- Both glEnable and glDisable take a single argument, cap, which can assume one of the
following values:

Dept. of CSE, CBIT, Kolar. 6 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)

Value Meaning
GL_DEPTH_TEST If enabled, do depth comparisons and update the depth buffer.
See glDepthFuncand glDepthRange.
GL_LINE_SMOOTH If enabled, draw lines with correct filtering. If disabled, draw
aliased lines. See glLineWidth.
GL_LINE_STIPPLE If enabled, use the current line stipple pattern when drawing lines.
See glLineStipple.
GL_NORMALIZE If enabled, normal vectors specified with glNormal are scaled to
unit length after transformation. See glNormal.
GL_POINT_SMOOTH If enabled, draw points with proper filtering. If disabled, draw
aliased points. See glPointSize.

glFlush:- The glFlush function forces execution of OpenGL functions in finite time.
Syntax:- void glFlush(void);
This function has no parameters.

glFrustum:- The glFrustum function multiplies the current matrix by a perspective matrix.
Syntax :- void glFrustum(GLdouble left, GLdouble right, GLdouble bottom,
GLdouble top, GLdouble zNear, GLdouble zFar);
left :- The coordinate for the left-vertical clipping plane.
right :- The coordinate for the right-vertical clipping plane.
bottom :- The coordinate for the bottom-horizontal clipping plane.
top :- The coordinate for the bottom-horizontal clipping plane.
zNear :-The distances to the near-depth clipping plane. Must be positive.
zFar :- The distances to the far-depth clipping planes. Must be positive.

glLightfv:- The glLightfv function returns light source parameter values.


Syntax:- void glLightfv(GLenum light, GLenum pname, const GLfloat *params);
Light:- The identifier of a light. The number of possible lights depends on the implementation,
but at least eight lights are supported. They are identified by symbolic names of the form
GL_LIGHTiwhere i is a value: 0 to GL_MAX_LIGHTS - 1.
pname :- A single-valued light source parameter for light. The following symbolic names are
accepted.

Value Meaning
GL_AMBIENT The params parameter contains four floating-point
values that specify the ambient RGBA intensity of the
light. Floating-point values are mapped directly.
Neither integer nor floating-point values are clamped.
The default ambient light intensity is (0.0, 0.0, 0.0,
1.0).
GL_DIFFUSE The params parameter contains four floating-point
values that specify the diffuse RGBA intensity of the
light. Floating-point values are mapped directly.
Neither integer nor floating-point values are clamped.
The default diffuse intensity is (0.0, 0.0, 0.0, 1.0) for

Dept. of CSE, CBIT, Kolar. 7 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)

all lights other than light zero. The default diffuse


intensity of light zero is (1.0, 1.0, 1.0, 1.0).
GL_SPECULAR The params parameter contains four floating-point
values that specify the specular RGBA intensity of the
light. Floating-point values are mapped directly.
Neither integer nor floating-point values are clamped.
The default specular intensity is (0.0, 0.0, 0.0, 1.0) for
all lights other than light zero. The default specular
intensity of light zero is (1.0, 1.0, 1.0, 1.0).
GL_POSITION The params parameter contains four floating-point
values that specify the position of the light in
homogeneous object coordinates. Both integer and
floating-point values are mapped directly. Neither
integer nor floating-point values are clamped.

param :- Specifies the value that parameter pname of light source light will be set to.
glLoadIdentity :- The glLoadIdentity function replaces the current matrix with the identity
matrix.
Syntax :- void WINAPI glLoadIdentity(void);
glMatrixMode:- The glMatrixMode function specifies which matrix is the current matrix.
Syntax:- void glMatrixMode(GLenum mode);
mode :- The matrix stack that is the target for subsequent matrix operations. The mode parameter
can assume one of three values.
Value Meaning
GL_MODELVIEW Applies subsequent matrix operations to the modelview matrix
stack.
GL_PROJECTION Applies subsequent matrix operations to the projection matrix
stack.
GL_TEXTURE Applies subsequent matrix operations to the texture matrix
stack.

glOrtho:- The glOrtho function multiplies the current matrix by an orthographic matrix.
Syntax:- void glOrtho(GLdouble left, GLdouble right, GLdouble bottom,
GLdouble top, GLdouble zNear, GLdouble zFar);
left :-The coordinates for the left vertical clipping plane.
right :- The coordinates for theright vertical clipping plane.
Bottom:- The coordinates for the bottom horizontal clipping plane.
top :- The coordinates for the top horizontal clipping plans.
zNear :- The distances to the nearer depth clipping plane. This distance is negative if the plane is
to be behind the viewer.
zFar :- The distances to the farther depth clipping plane. This distance is negative if the plane is
to be behind the viewer.

glPointSize :- The glPointSize function specifies the diameter of rasterized points.


Syntax :- void glPointSize(GLfloat size);
Size:-The diameter of rasterized points. The default is 1.0.
Dept. of CSE, CBIT, Kolar. 8 2020-21
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)
glPushMatrix & glPopMatrix:- The glPushMatrix and glPopMatrix functions push and pop the
current matrix stack.
Syntax:- void WINAPI glPopMatrix(void);
glRotatef:- The glRotatef function multiplies the current matrix by a rotation matrix.
Syntax :- void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
angle :- The angle of rotation, in degrees.
X :- The x coordinate of a vector.
y :- The y coordinate of a vector.
z :- The z coordinate of a vector.

glScalef :- The glScaled and glScalef functions multiply the current matrix by a general scaling
matrix.
Syntax :- void glScalef(GLfloat x, GLfloat y, GLfloat z);
x :- Scale factors along the x axis.
y :- Scale factors along the y axis.
z :- Scale factors along the z axis.

glTranslatef :- The glTranslatef function multiplies the current matrix by a translation matrix.
Syntax:- void glTranslatef(GLfloat x, GLfloat y, GLfloat z);
x :- The x coordinate of a translation vector.
y :- The y coordinate of a translation vector.
z :- The z coordinate of a translation vector.

glVertex2d :- Specifies a vertex.


Syntax:- void glVertex2d(GLdouble x, GLdouble y);
x :- Specifies the x-coordinate of a vertex.
y :-Specifies the y-coordinate of a vertex.

glViewport :- The glViewport function sets the viewport.


Syntax:- void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
x :- The lower-left corner of the viewport rectangle, in pixels. The default is (0,0).
y :- The lower-left corner of the viewport rectangle, in pixels. The default is (0,0).
Width :-The width of the viewport. When an OpenGL context is first attached to a
window, widthand height are set to the dimensions of that window.
height :- The height of the viewport. When an OpenGL context is first attached to a
window, widthand height are set to the dimensions of that window.
GLU FUNCTIONS
gluLookAt :- The gluLookAt function defines a viewing transformation.
Syntax:- void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery,GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz);
eyex :- The position of the eye point.
eyey :-The position of the eye point.
eyez :- The position of the eye point.
centerx :- The position of the reference point.
centery :- The position of the reference point.
centerz :- The position of the reference point.
upx :- The direction of the up vector.
upy :- The direction of the up vector.
upz :- The direction of the up vector.

Dept. of CSE, CBIT, Kolar. 9 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17CSL68/18CSL67)

gluOrtho2D :- The gluOrtho2D function defines a 2-D orthographic projection matrix.


Syntax :- void gluOrtho2D(GLdouble left, GLdouble right, GLdouble
top, GLdouble bottom);
left :- The coordinate for the left vertical clipping plane.
right :- The coordinate for the right vertical clipping plane.
top :- The coordinate for the top horizontal clipping plane.
bottom :- The coordinate for the bottom horizontal clipping plane.

Dept. of CSE, CBIT, Kolar. 10 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

EXECUTION STEPS

1. Open TERMINAL.

2. Command to create program file

gedit program.cpp

3. Command to compile

g++ program.cpp –o PrgExec –lglut –lGLU -lGL

4. To execute

./PrgExec

Department of CSE, CBIT, Kolar. Page | 11 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

Lab Experiment-1
Implement Bresenham’s line drawing algorithm for all types of slope.

Brenham’s line drawing algorithm


Given coordinate of two points A(x1, y1) and B(x2, y2). The task to find all the intermediate points
required for drawing line AB on the computer screen of pixels. Note that every pixel has integer
coordinates.

• It is an improvement upon DDA algorithm to use integer arithmetic only.

• It is applicable to circle drawing too.

• Also called as midpoint line drawing algorithm.

To apply midpoint criterion, compute,

F(M) = F(xp + 1, yp + ½ )

since the he decision is based on the value of the function at (xp + 1, yp + ½ )

The decision variable,

d=F(xp + 1, yp + ½ )

By definition

D=a(xp + 1) + b( yp + ½ )+c

Therefore, the value of d for next grid line depends on whether E is chosen or NE.

Location of M!

i. If E is chosen, M is incremented by on step in x direction

Figure: mid-point lies above the line, East pixel chosen

dnew =F(xp + 2, yp + ½ ) = a(xp + 2) + b( yp + ½ )+c

dold = a(xp + 1) + b( yp + ½ )+c


Department of CSE, CBIT, Kolar. Page | 12 2020-21
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
subtracting dold from dnew → incremental difference

dnew - dold = a

dnew = dold + a

call increament to add after E, ΔE

ΔE = a = dy

The value of decision variable is derived at the next step incrementally from the value at
the current step without having to compute F(M) directly by merely adding ΔE.

ii. If NE is chosen, M is incremented by one step each in both the x and y directions.

Figure: mid-point lies below the line, North-East pixel chosen

dnew =F(xp + 2, yp + 3/2) = a(xp + 2) + b( yp + 3/2 )+c

subtracting dold from dnew → incremental difference

dnew - dold = a + b

dnew = dold + a + b

call increment to add to d after NE is chosen, ΔNE

ΔNE = dy – dx.
Summary and Algorithm
At each step, the algorithm chooses between two pixels, based on sign of the decision variable
and then updates d by wither adding ΔE or ΔNE.
First pixel (x0, y0)
First midpoint (x0+1, y0 + ½ )
F(x0 + 1, y0 + 1/2) = a(x0 + 2) + b( y0 + 1/2 )+c
= ax0 + by0 +c + a + b/2
= 0 + a + b/2
dstart = a + b/2
dstart = dy – dx/2

Department of CSE, CBIT, Kolar. Page | 13 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
Eliminate the fraction in above equation by multiplying F by 2.
F(x,y)= 2(ax+bx+c)
Hence,
dstart = 2dy – dx
ΔE = 2dy
ΔNE = 2(dy - dx)
CODE:
#include <iostream>
#include<GL/glut.h>
#include<math.h>
//Input vairables
GLint xOne, yOne, xTwo, yTwo;
//Funtion declaration
void resize(int, int);
void setPixel(GLint, GLint);
void lineBres_L1(GLint, GLint, GLint, GLint, GLfloat) ;
void lineBres_GE1(GLint, GLint, GLint, GLint, GLfloat);
void display();
int main(int argc, char**argv)
{
std::cout<<"*********Bresenham's Line Drawing Algorithm
************";
std::cout<<"\nEnter starting vertex (x1, y1):";
std::cin>>xOne>>yOne;
std::cout<<"\nEnter starting vertex (x2, y2):";
std::cin>>xTwo>>yTwo;
glutInit(&argc,argv); //initialize GLUT
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //initialize display
mode
glutInitWindowSize(500,500); //set display-window width & height
glutInitWindowPosition(0,0); //set display-window lower-left
position
//create display-window with a title
glutCreateWindow("Bresenhams Line Drawing Algorithm");
glutDisplayFunc(display); //call graphics to be displayed on the
window
glutReshapeFunc(resize); //calls whenever frame buffer window is
resized
glutMainLoop(); //display everything and wait
}
void resize(int w, int h)
{
//set projection paramaters
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,w,0.0,h);
glViewport(0.0, 0.0, w, h);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
GLfloat m;
m=(float)(yTwo-yOne)/(xTwo-xOne); //compute slope

Department of CSE, CBIT, Kolar. Page | 14 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
//call required function based on value of slope
if(fabs(m)>=1)
lineBres_GE1(xOne,yOne,xTwo,yTwo,m);
else
lineBres_L1(xOne, yOne, xTwo,yTwo, m);
}
//Bresenham line-drawing procedure for |m| < 1.0
void lineBres_L1(GLint x0, GLint y0, GLint xEnd, GLint yEnd, GLfloat
m)
{
GLint dx = abs(xEnd - x0);
GLint dy = abs(yEnd - y0);
GLint p = 2 * dy - dx;
GLint twoDy = 2 * dy;
GLint twoDyMinusDx = 2 * (dy-dx);
GLint x=x0,y=y0;
// determine which point to use as start position
if (x0 > xEnd)
{
x = xEnd;
y = yEnd;
xEnd = x0;
}
else
{
x = x0;
y = y0;
}
setPixel(x,y);
while(x<xEnd)
{
x++;
if(p<0)
p += twoDy;
else
{
if(m<0)
y--;
else
y++;
p += twoDyMinusDx;
}
setPixel(x,y);
}
}
//Bresenham line-drawing procedure for |m| >= 1.0
void lineBres_GE1(GLint x0, GLint y0, GLint xEnd, GLint yEnd, GLfloat
m)
{
GLint dx = abs(xEnd - x0);
GLint dy = abs(yEnd - y0);
GLint p=2*dx-dy;
GLint twoDx = 2*dx;
GLint twoDxMinusDy=2*(dx-dy);
GLint x=x0,y=y0;
// determine which point to use as start position
if (y0 > yEnd)
{

Department of CSE, CBIT, Kolar. Page | 15 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
x = xEnd;
y = yEnd;
yEnd = y0;
}
else
{
x = x0;
y = y0;
}
setPixel(x,y);
while(y<yEnd)
{
y++;
if(p<0)
p+=twoDx;
else
{
if(m<0)
x--;
else
x++;
p+=twoDxMinusDy;
}
setPixel(x,y);
}
}
void setPixel(GLint xCoordinate, GLint yCoordinate)
{
glBegin(GL_POINTS);
glVertex2i(xCoordinate,yCoordinate);
glEnd();
glFlush(); //executes all OpenGL functions as quickly as possible
}
OUTPUT
1. Left to right→ increase up→ Slope > 0

Department of CSE, CBIT, Kolar. Page | 16 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

2. Left to right → decrease down→Slope <0

3. Horizontal→Slope=0

Department of CSE, CBIT, Kolar. Page | 17 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

4. Vertical→Slope undefined

Department of CSE, CBIT, Kolar. Page | 18 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-2
Create and rotate a triangle about the origin and a fixed point
Homogenous co-ordinates representation for rotation of (x,y) is
𝑐𝑜𝑠𝜃 −𝑠𝑖𝑛𝜃 𝑚
[ 𝑠𝑖𝑛𝜃 𝑐𝑜𝑠𝜃 𝑛]
0 0 1
CODE
#include <iostream>
#include<GL/glut.h>
#include<math.h>

using namespace std;


GLfloat triangle[3][3]={{0,175,350},
{0,300,0},
{1,1,1}};
GLfloat rot_mat[3][3]={{0},{0},{0}};
GLfloat result[3][3]={{0},{0},{0}};

GLfloat h,k,theta;
int ch;
void multiply()
{
int i, j, k;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
result[i][j]=0;
for(k=0;k<3;k++)

result[i][j]=result[i][j]+rot_mat[i][k]*triangle[k][j];
}
}

void rotate(int h,int k)


{
GLfloat m, n;
m=-h*(cos(theta)-1)+k*(sin(theta));
n=-k*(cos(theta)-1)-h*(sin(theta));
rot_mat[0][0] = cos(theta);
rot_mat[0][1] = -sin(theta);
rot_mat[0][2] = m;
rot_mat[1][0] = sin(theta);
rot_mat[1][1] = cos(theta);
rot_mat[1][2] = n;
rot_mat[2][0] = 0;
rot_mat[2][1] = 0;
rot_mat[2][2] = 1;
multiply();
}

void drawTriangle()
{
int i;
glColor3f(0,0,1);

Department of CSE, CBIT, Kolar. Page | 19 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
glBegin(GL_TRIANGLES);
for(i=0;i<=2;i++)
glVertex2f(triangle[0][i],triangle[1][i]);
glEnd();
}

void drawrotatedTriangle()
{
int i;

glColor3f(1,1,0);
glBegin(GL_TRIANGLES);
for(i=0;i<=2;i++)
glVertex2f(result[0][i],result[1][i]);
glEnd();
}
void drawPoint(int h, int k)
{
//display the point about which the triangle is rotated
glColor3f(0,0,0);
glPointSize(7);
glBegin(GL_POINTS);
glVertex2f(h,k);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
drawTriangle();
rotate(h,k);
drawrotatedTriangle();
drawPoint(h,k);
glFlush();

}
void myinit()
{
glClearColor(1,1,1,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,499,0,499);
}
int main(int argc, char *argv[])
{
cout<<"Enter rotation angle: ";
cin>>theta;
cout<<"Do you want to rotate about \n 1.Origin or \n2.Fixed
point? Enter your choice:";
cin>>ch;
if(ch==2)
{
cout<<"Enter the vale of x and y";
cin>>h>>k;
}
else
{
h=0;
k=0;

Department of CSE, CBIT, Kolar. Page | 20 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
}
theta=theta*(3.14/180);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Triangle Rotate");
myinit();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
OUTPUT 1- ROTATE ABOUT ORIGIN

OUTPUT 2- ROTATE ABOUT FIXED POINT

Department of CSE, CBIT, Kolar. Page | 21 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-3
Draw a color cube and spin it using OpenGL transformation matrices
ALGORITHM
i. Choose 8 three-dimensional coordinate points such that will make a cube.
ii. Select the axes to rotate
iii. Rotate the cube by a small angle every small interval of time.
glRotate*(angle,x,y,z)
is used to rotate an object by an angle in degrees about vecor x,y,z.
to rotate about x-axis, x=1, y=0, and z=0. Example, glRotatef(angle,1,0,0)
iv. Repeat step iii as long as axis is not changed.

CODE
#include <iostream>
#include<stdlib.h>
#include<GL/glut.h>

using namespace std;

GLfloat vertices[][3]= {{-1,-1,-1},{1,-1,-1},{1,1,-1},{-1,1,-1},{-1,-


1,1},{1,-1,1},{1,1,1},{-1,1,1}};
GLfloat colors[][3]=
{{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1},{1,1,1},{0,1,1}};

void polygon(int a, int b, int c, int d)


{

glBegin(GL_POLYGON);
glColor3fv(colors[a]);
glVertex3fv(vertices[a]);
glColor3fv(colors[b]);
glVertex3fv(vertices[b]);
glColor3fv(colors[c]);
glVertex3fv(vertices[c]);
glColor3fv(colors[d]);
glVertex3fv(vertices[d]);
glEnd();
}

void colorcube()
{
polygon(0,3,2,1);
polygon(2,3,7,6);
polygon(0,4,7,3);
polygon(1,2,6,5);
polygon(4,5,6,7);
polygon(0,1,5,4);
}

static GLfloat theta[]= {0.0,0.0,0.0};


static GLint axis=1;

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

Department of CSE, CBIT, Kolar. Page | 22 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
glLoadIdentity();
glRotatef(theta[0],1.0,0.0,0.0);
glRotatef(theta[1],0.0,1.0,0.0);
glRotatef(theta[2],0.0,0.0,1.0);
colorcube();
glFlush();
glutSwapBuffers();
}
void spincube()
{
theta[axis]+=1.0;
if(theta[axis]>360.0)
theta[axis]-=360.0;
display();
glutPostRedisplay();
}

void mouse(int button, int state, int x, int y)


{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
axis=0;
if(button==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
axis=1;
if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
axis=2;
}
void myreshape(int w, int h)
{

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-2.0,2.0,-
2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-
2.0,2.0,-10.0,10.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char *argv[])


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("Rotate a cube");
glClearColor(1,1,1,1);
glutReshapeFunc(myreshape);
glutDisplayFunc(display);
glutIdleFunc(spincube);
glutMouseFunc(mouse);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}

Department of CSE, CBIT, Kolar. Page | 23 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
OUTPUT

Department of CSE, CBIT, Kolar. Page | 24 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-4
Draw a color cube and allow the user to move the camera suitably to experiment with
perspective viewing
PROCEDURE
i. Choose appropriate coordinates to make a cube
ii. Rotate or move the cube by a small variation on user input provided using keyboard and
mouse.
iii. Repeat step 2.

CODE
#include <iostream>
#include<stdlib.h>
#include<GL/glut.h>

using namespace std;

GLfloat vertices[][3]= {{-1,-1,-1},{1,-1,-1},{1,1,-1},{-1,1,-1},{-1,-


1,1},{1,-1,1},{1,1,1},{-1,1,1}};
GLfloat colors[][3]=
{{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1},{1,1,1},{0,1,1}};

void polygon(int a, int b, int c, int d)


{

glBegin(GL_POLYGON);
glColor3fv(colors[a]);
glVertex3fv(vertices[a]);
glColor3fv(colors[b]);
glVertex3fv(vertices[b]);
glColor3fv(colors[c]);
glVertex3fv(vertices[c]);
glColor3fv(colors[d]);
glVertex3fv(vertices[d]);
glEnd();
}

void colorcube()
{
polygon(0,3,2,1);
polygon(2,3,7,6);
polygon(0,4,7,3);
polygon(1,2,6,5);
polygon(4,5,6,7);
polygon(0,1,5,4);
}

static GLfloat theta[]= {0.0,0.0,0.0};


static GLint axis=2;
static GLdouble viewer[]= {0,0,5};

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

Department of CSE, CBIT, Kolar. Page | 25 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
glLoadIdentity();
gluLookAt(viewer[0],viewer[1],viewer[2],0,0,0,0,1,0);
glRotatef(theta[0],1.0,0.0,0.0);
glRotatef(theta[1],0.0,1.0,0.0);
glRotatef(theta[2],0.0,0.0,1.0);
colorcube();
glFlush();
glutSwapBuffers();
}

void keyboard(unsigned char key, int x, int y)


{
if(key=='x') viewer[0]-=1;
if(key=='X') viewer[0]+=1;
if(key=='y') viewer[1]-=1;
if(key=='Y') viewer[1]+=1;
if(key=='z') viewer[2]-=1;
if(key=='Z') viewer[2]+=1;
display();
}

void mouse(int button, int state, int x, int y)


{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
axis=0;
if(button==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN)
axis=1;
if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
axis=2;
theta[axis]+=1.0;
if(theta[axis]>360.0)
theta[axis]-=360.0;
display();
}

void myreshape(int w, int h)


{

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glFrustum(-2.0,2.0,-
2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,2.0,20.0);
else
glFrustum(-2.0,2.0,-
2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,2.0,20.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char* argv[])


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("Prespective viewing");
glutReshapeFunc(myreshape);

Department of CSE, CBIT, Kolar. Page | 26 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}

OUTPUT

Department of CSE, CBIT, Kolar. Page | 27 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-5
Clip a lines using Cohen-Sutherland algorithm
In computer graphics, line clipping is the process of removing lines or portions of lines
outside an area of interest. Typically, any line or part thereof which is outside of the
viewing area is removed.
The Cohen–Sutherland algorithm is a computer graphics algorithm used for line
clipping. The algorithm divides a two-dimensional space into 9 regions and then
efficiently determines the lines and portions of lines that are visible in the center region
of interest (the viewport). The algorithm quickly detects and dispenses with two common
trivial cases. To clip a line, only its end points are to be considered. If both end points of
a line lie inside the window, the entire line lies inside the window. It is trivially accepted
and needs no clipping. On the other hand, if both end points of a line, lie entirely to one
side of a window, the line must lie entirely outside the window. It is trivially rejected and
needs to be neither clipped nor displayed.

ALGORITHM

i. End-points pairs are check for trivial acceptance or trivial rejected using the outcode.
ii. If not trivial-accepance or trivial-rejected, divided into two segments at a clip edge.
iii. Iteratively clipped by testing trivial-acceptance or trivial-rejected, and divided into two
segments until completely inside or trivial-rejected

NOTE:
Outcodes: Region and Outcode

Each region of the nine regions is assigned a 4-bit code, the nine regions and their outcodes
are shown below:

iv. To perform trivial accept and reject tests, we extend the edges of the clip
rectangle to divide the plane of the clip rectangle into nine regions. Each
region is assigned a 4-bit code determined by where the region lies with

Department of CSE, CBIT, Kolar. Page | 28 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
respect to the outside half-planes of the clip-rectangle edges. Each bit in the
outcode is set to either 1 (true) or 0 (false); the 4 bits in the code correspond
to the following conditions:

• Bit 1 : outside half-plane of top edge, above top edge


Y > Ymax
• Bit 2 : outside half-plane of bottom edge, below bottom edge
Y < Ymin
• Bit 3 : outside half-plane of right edge, to the right of right edge
X > Xmax
• Bit 4 : outside half-plane of left edge, to the left of left edge
X < Xmin

CODE
#include<stdio.h>
#include<iostream>
#include<GL/glut.h>

using namespace std;

#define outcode int

double xmin=50,ymin=50,xmax=100,ymax=100;
double xvmin=200,yvmin=200,xvmax=300,yvmax=300;

double x0[10], y0[10];


double x1[10], y1[10];
int n,i;

const int RIGHT=2;


const int LEFT=1;
const int TOP=8;
const int BOTTOM=4;

outcode ComputeOutCode(double x, double y);

void CohenSutherland(double x0, double y0, double x1, double y1)


{
outcode outcode0, outcode1, outcodeOut;
bool accept=false, done=false;
outcode0=ComputeOutCode(x0,y0);
outcode1=ComputeOutCode(x1,y1);
do
{
if(!(outcode0|outcode1))
{
accept=true;
done=true;
}
else if(outcode0&outcode1)
done=true;
else
{
double x, y;
outcodeOut=outcode0?outcode0:outcode1;
if(outcodeOut&TOP)

Department of CSE, CBIT, Kolar. Page | 29 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
{
x=x0+(x1-x0)*(ymax-y0)/(y1-y0);
y=ymax;
}
else if(outcodeOut&BOTTOM)
{
x=x0+(x1-x0)*(ymin-y0)/(y1-y0);
y=ymin;
}
else if(outcodeOut&RIGHT)
{
y=y0+(y1-y0)*(xmax-x0)/(x1-x0);
x=xmax;
}
else
{
y=y0+(y1-y0)*(xmin-x0)/(x1-x0);
x=xmin;
}
if(outcodeOut==outcode0)
{
x0=x;
y0=y;
outcode0=ComputeOutCode(x0,y0);
}
else
{
x1=x;
y1=y;
outcode1=ComputeOutCode(x1,y1);
}
}
} while(!done);
if(accept)
{
double sx=(xvmax-xvmin)/(xmax-xmin);
double sy=(yvmax-yvmin)/(ymax-ymin);
double vx0=xvmin+(x0-xmin)*sx;
double vy0=yvmin+(y0-ymin)*sy;
double vx1=xvmin+(x1-xmin)*sx;
double vy1=yvmin+(y1-ymin)*sy;
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(xvmin, yvmin);
glVertex2f(xvmax, yvmin);
glVertex2f(xvmax, yvmax);
glVertex2f(xvmin, yvmax);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINES);
glVertex2d(vx0,vy0);
glVertex2d(vx1,vy1);
glEnd();
}
}
outcode ComputeOutCode(double x, double y)
{
outcode code=0;

Department of CSE, CBIT, Kolar. Page | 30 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
if(y>ymax)
code=TOP;
else if(y<ymin)
code=BOTTOM;
if(x>xmax)
code=RIGHT;
else if(x<xmin)
code=LEFT;
return code;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINES);
for(i=0;i<n;i++)
{
glVertex2d(x0[i],y0[i]);
glVertex2d(x1[i],y1[i]);
}
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(xmin, ymin);
glVertex2f(xmax, ymin);
glVertex2f(xmax, ymax);
glVertex2f(xmin, ymax);
glEnd();
for(i=0;i<n;i++)
CohenSutherland(x0[i],y0[i],x1[i],y1[i]);
glFlush();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);
}
int main(int argc, char* argv[])
{
cout<<"Enter the number of lines: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the endpoints for line"<<i+1<<":\n";
cin>>x0[i]>>y0[i]>>x1[i]>>y1[i];
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Cohen-Sutherland Line Clipping");
myinit();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Department of CSE, CBIT, Kolar. Page | 31 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

OUTPUT

Department of CSE, CBIT, Kolar. Page | 32 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-6
To draw a simple shaded scene consisting of a tea pot on a table. Define suitably the
position and properties of the light source along with the properties of the surfaces of the
solid object used in the scene

PROCEDURE
i. Use the function glutSolidCube() to draw wall and table.
ii. Use the same function to draw 4 cubes and then scale it in downward direction to
make it look like table legs.
iii. glutSolidTeapot() is used to draw teapot.

CODE
#include <iostream>
#include <GL/glut.h>

using namespace std;

GLfloat x=2.3, y=1.3;

void wall(double thickness)


{
glPushMatrix();
glTranslated(0.5,0.5*thickness,0.5);
glScaled(1.0,thickness,1.0);
glutSolidCube(1.0);
glPopMatrix();
}

//draw one table leg


void tableleg(double thick, double len)
{
glPushMatrix();
glTranslated(0,len/2,0);
glScaled(thick,len,thick);
glutSolidCube(1.0);
glPopMatrix();
}
void table(double topWid,double topThick,double legThick,double legLen)
{
//draw the table - a top and 4 legs
//draw the top first
glPushMatrix();
glTranslated(0,legLen,0);
glScaled(topWid,topThick,topWid);
glutSolidCube(1.0);
glPopMatrix();
double dist=0.95*topWid/2.0-legThick/2.0;
glPushMatrix();
glTranslated(dist,0,dist);
tableleg(legThick,legLen);
glTranslated(0,0,-2*dist);
tableleg(legThick,legLen);

Department of CSE, CBIT, Kolar. Page | 33 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
glTranslated(-2*dist,0,2*dist);
tableleg(legThick,legLen);
glTranslated(0,0,-2*dist);
tableleg(legThick,legLen);
glPopMatrix();
}
void displaySolid()
{
//set proporties for surface material
GLfloat mat_ambient[]={0.7f,0.7f,0.7f,1.0f};
GLfloat mat_diffuse[]={0.5f,0.5f,0.5f,1.0f};
GLfloat mat_specular[]={1.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
//set light source properties
GLfloat lightIntensity[]={0.7f,0.7f,0.7f,1.0f};
GLfloat lightPosition[]={2.0f,6.0f,3.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,lightPosition);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);

//set the camera


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double winHt=1.0; //half-height of window
glOrtho(-winHt*64/48.0,winHt*64/48.0,-winHt,winHt,0.1,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(x,y,2.0,0.0,0.25,0.0,0.0,1.0,0.0);

//start drawing
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glTranslated(0.6,0.38,0.5);
glRotated(30,0,1,0);
glutSolidTeapot(0.08);
glPopMatrix();

glPushMatrix();
glTranslated(0.4,0,0.4);
table(0.6,0.02,0.02,0.3);
glPopMatrix();
wall(0.02);
glPushMatrix();
glRotated(90,0,0,1);
wall(0.02);
glPopMatrix();
glPushMatrix();
glRotated(-90,1,0,0);
wall(0.02);
glPopMatrix();

glutPostRedisplay();
glutSwapBuffers();
glFlush();

Department of CSE, CBIT, Kolar. Page | 34 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
}

void motion(int x1, int y1)


{
x=x1/100;
y=y1/100;
}

int main(int argc, char *argv[])


{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("Teapot");
glutDisplayFunc(displaySolid);
glutMotionFunc(motion);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glClearColor(0.1,0.1,0.1,0.0);
glViewport(0,0,640,480);
glutMainLoop();
return 0;
}

‘OUTPUT

Department of CSE, CBIT, Kolar. Page | 35 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-7
Design, develop and implement recursively subdivide a tetrahedron to form 3D
Sierpinski gasket. The number of recursive steps is to be specified by the user
A geometric method of creating the gasket is to start with a triangle and cut out the middle
piece as shown in the generator below. This results in three smaller triangles to which the
process is continued. The nine resulting smaller triangles are cut in the same way, and so
on, indefinitely. The gasket is perfectly self-similar, an attribute of many fractal images.
Any triangular portion is an exact replica of the whole gasket. The construction of the 3
dimensional version of the gasket follows similar rules for the 2D case except that the
building blocks are square based pyramids instead of triangles.

ALGORITHM

i. Start with a single triangle.


ii. Inside this triangle, draw a smaller upside-down- triangle. Its corners should be
exactly in the centers of the sides of the large triangle.
iii. Now, draw 3 smaller triangles in each of the 3 triangles that are pointing upwards,
again with the corners in the centers of the sides of the triangle that points upwards.
iv. Now there are 9 triangles pointing upwards. In each of these 9, draw again smaller
upside-down-triangles.
v. Repeat

CODE

#include <iostream>
#include<stdlib.h>
#include<GL/glut.h>

using namespace std;

GLfloat v[4][3]= {{0.0,0.0,1.0},{0,1,-1},{-0.8,-0.4,-1},{0.8,-0.4,-1}};


int n;

void triangle(GLfloat* a, GLfloat* b, GLfloat* c)


{
glBegin(GL_POLYGON);
glVertex3fv(a);
glVertex3fv(b);
glVertex3fv(c);
glEnd();
}

void divide_triangle(GLfloat* a, GLfloat* b, GLfloat* c, int m)


{
GLfloat v1[3], v2[3], v3[3];
int i;
if(m>0)
{
for(i=0; i<3; i++) v1[i]=(a[i]+b[i])/2;
for(i=0; i<3; i++) v2[i]=(a[i]+c[i])/2;
for(i=0; i<3; i++) v3[i]=(b[i]+c[i])/2;
divide_triangle(a,v1,v2,m-1);
divide_triangle(c,v2,v3,m-1);

Department of CSE, CBIT, Kolar. Page | 36 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
divide_triangle(b,v3,v1,m-1);
}
else (triangle(a,b,c));
}
void tetrahedron(int m)
{
glColor3f(1.0,0.0,0.0);
divide_triangle(v[0],v[1],v[2],m);
glColor3f(0.0,1.0,0.0);
divide_triangle(v[3],v[2],v[1],m);
glColor3f(0.0,0.0,1.0);
divide_triangle(v[0],v[3],v[1],m);
glColor3f(1.0,1.0,0.0);
divide_triangle(v[0],v[2],v[3],m);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
tetrahedron(n);
glFlush();
}

void reshape(int w, int h)


{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
{
glOrtho(-2.0,2.0,-
2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0);
}
else
{
glOrtho(-2.0*(GLfloat)w/(GLfloat)h,2.0*(GLfloat)w/(GLfloat)h,-
2.0,2.0,-10.0,10.0);
}
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}

int main(int argc, char* argv[])


{
cout<<"Enter the number of divisions: ";
cin>>n;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("3D Gasket");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glEnable(GL_DEPTH_TEST);
glClearColor(1.0,1.0,1.0,1.0);
glutMainLoop();
return 0;
}

Department of CSE, CBIT, Kolar. Page | 37 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
OUTPUT

Department of CSE, CBIT, Kolar. Page | 38 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-8
Develop a menu driven program to animate a flag using Bezier Curve algorithm

The Bezier curve was originally used by Pierre Bezier for CAD/CAM operations are Renault
motor car company. Bezier curves are the basis of the entire Adobe PostScript drawing model.

The curve fitting technique is ineffective for interactive curve generation.

The Bezier curve is determined by defining a polygon, as shown below.

Figure: Bezier Curve

Several properties of Bezier curves are as follows:

1. The basic functions are real

2. The degree of the polynomial defining the curve segment is one less than the number of
defining polygon points

3. The curve generally follows the shape of the defining polygon.

4. The first and last points on the curve are coincident with the first and last points of the
defining polygon.

5. The tangent vectors at the ends of the curve have the same direction as the first and the
last polygon spans respectively.

6. The curve is contained within the convex hull of the defining polygon, i.e., within the
largest convex polygon obtainable with the polygon vertices. (dashed lines in figure →
convex hull)

7. The curve exhibits the variation diminishing property. Basically this means that the
curve does not oscillate about any straight line more often that the defining polygon.

8. The curve is invariant under an offline transformation.

Mathematically a parametric Bezier curve is defined by


Department of CSE, CBIT, Kolar. Page | 39 2020-21
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
𝑛

𝑃(𝑡) = ∑ 𝐵𝑖 𝐽𝑛,𝑖 (𝑡), 0 ≤ 𝑡 ≤ 1


𝑖=0

Where the Bezier or Bernstein basis or blending function is


𝑛
𝐽𝑛,𝑖 (𝑡) = [ ] 𝑡 𝑖 (𝑖 − 𝑡)𝑛−𝑖 , 𝑓𝑜𝑟𝑖 = 0,1,2, … , 𝑛
𝑖
𝑛 𝑛!
Where, [ 𝑖 ] = 𝑖!(𝑛−𝑖)!

When i=0, n=3, J(n,i) = (1) t0(1-t)3-0

Bernstein basis function: here, n, the degree of the defining Bernstein basis function and thus of
the polynomial curve segment, is one less than the number of points in the defining Bezier
polygon. The vertices of the Bezier polygon are numbered from 0 to n as shown above.

Construction of the Bezier curve

A cubic Bezier curve is defined by 4 points. Two of the points are endpoints to the curve, (x 0,y0)
if the starting point and (x3,y3) is the destination point. The points (x1,y1) and (x2,y2) are control
points or handles.

The parametric formula for the curve is


𝑛 𝑛−1,𝑓𝑜𝑟𝑖=0,1,2,…,𝑛,
𝑃(𝑡) = 𝐵𝑖 [ ] 𝑡 𝑖 (1 − 𝑡) 𝑤ℎ𝑒𝑟𝑒
𝑖
𝑛 𝑛!
Where, [ 𝑖 ] = 𝑖!(𝑛−𝑖)!

When n=3, X[t] = (1-t)3X0 + 3(1-t)2tX1 + 3(1-t)t2 X2 + t3X3 and i=0,1,2,3.


CODE
#include<GL/glut.h>
#include<stdio.h>
#include<math.h>
#define PI 3.1416
GLsizei winWidth = 500, winHeight = 500;
GLfloat xwcMin = 0.0, xwcMax = 130.0;
GLfloat ywcMin = 0.0, ywcMax = 130.0;
int ch;
struct wcPt3D
{
GLfloat x, y, z;
};
void bino(GLint n, GLint *C)
{
GLint k, j;
for(k=0;k<=n;k++)
{
C[k]=1;
for(j=n;j>=k+1; j--)
C[k]*=j;
for(j=n-k;j>=2;j--)
C[k]/=j;

Department of CSE, CBIT, Kolar. Page | 40 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
}
}
void computeBezPt(GLfloat u, wcPt3D *bezPt, GLint nCtrlPts, wcPt3D
*ctrlPts, GLint *C)
{
GLint k, n=nCtrlPts-1;
GLfloat bezBlendFcn;
bezPt ->x =bezPt ->y = bezPt->z=0.0;
for(k=0; k< nCtrlPts; k++)
{
bezBlendFcn = C[k] * pow(u, k) * pow( 1-u, n-k);
bezPt ->x += ctrlPts[k].x * bezBlendFcn;
bezPt ->y += ctrlPts[k].y * bezBlendFcn;
bezPt ->z += ctrlPts[k].z * bezBlendFcn;
}
}
void bezier(wcPt3D *ctrlPts, GLint nCtrlPts, GLint nBezCurvePts)
{
wcPt3D bezCurvePt;
GLfloat u;
GLint *C, k;
C= new GLint[nCtrlPts];
bino(nCtrlPts-1, C);
glBegin(GL_LINE_STRIP);
for(k=0; k<=nBezCurvePts; k++)
{
u=GLfloat(k)/GLfloat(nBezCurvePts);
computeBezPt(u, &bezCurvePt, nCtrlPts, ctrlPts, C);
glVertex2f(bezCurvePt.x, bezCurvePt.y);
}
glEnd();
delete[]C;
}
void menu(int id)
{
switch(id)
{
case 1:
ch=1;
break;
case 2:
ch=2;
break;
case 3:
exit(0);
break;
}
glutPostRedisplay();
}
void wave(int m)
{
GLint nCtrlPts = 4, nBezCurvePts =20;
static float theta = 0;
wcPt3D ctrlPts[4] = {
{20, 100, 0},
{30, 110, 0},
{50, 90, 0},
{60, 100, 0}};

Department of CSE, CBIT, Kolar. Page | 41 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
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);
theta+=0.5;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPointSize(5);
glPushMatrix();
glLineWidth(5);
glColor3f(1,1,0); //Karnataka flag: yellow color code
for(int i=0;i<8;i++)
{
glTranslatef(0, -0.8, 0);
bezier(ctrlPts, nCtrlPts, nBezCurvePts);
}
glColor3f(1, 0, 0); //Karnataka flag: red color code
for(int i=0;i<8;i++)
{
glTranslatef(0, -0.8, 0);
bezier(ctrlPts, nCtrlPts, nBezCurvePts);
}
glPopMatrix();
glColor3f(0.7, 0.5,0.3);
glLineWidth(5);
glBegin(GL_LINES);
glVertex2f(20,100);
glVertex2f(20,40);
glEnd();
glFlush();
if(m==1)
glutPostRedisplay();
glutSwapBuffers();
}
void displayFcn()
{
if(ch==1)
wave(1);
else
wave(2);
}
void winReshapeFun(GLint newWidth, GLint newHeight)
{
glViewport(0, 0, newWidth, newHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(xwcMin, xwcMax, ywcMin, ywcMax);
glClear(GL_COLOR_BUFFER_BIT);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(0, 0);
glutInitWindowSize(winWidth, winHeight);
glutCreateWindow("Bezier Curve");

Department of CSE, CBIT, Kolar. Page | 42 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
glutDisplayFunc(displayFcn);
glutCreateMenu(menu);
glutAddMenuEntry("Animate Flag",1);
glutAddMenuEntry("Stop Animation",2);
glutAddMenuEntry("Exit",3);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutReshapeFunc(winReshapeFun);
glutMainLoop();
}
OUTPUT

Department of CSE, CBIT, Kolar. Page | 43 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

LAB EXPERIMENT-9
Develop a menu driven program to fill the polygon using scan line algorithm

To make the addition of edges to the Active Edge Table (AET) efficient, initially create
global Edge Table (ET) containing all the edges sorted by their smaller y co-ordinates. The ET is
typically built by using a bucket sort with as many buckets as there are scan lines. Within each
bucket, edges are kept in order of increasing x co-ordinate of the ower end point. Each entry
in the ET contains the ymax co-ordinate of the edge, the x co-ordinate of the bottom end point
(xmin), and the x increment 1/m.

The AET for the given polygon processing is done as follows:

1. Set y to the smallest y co-ordinate that has an entry in ET; i.e., y for the first nonempty
bucket.

2. Initialize the AET to be empty.

3. Repeat until AET and ET are empty.

a. Move from ET bucket y to the AET those edges whose ymin=y (entering edge).

b. Remove from the AET those entries for which y=ymax (edges not involved in the next
scan line), the sort the AET on x.

c. Fill in desired pixel values on scan line y by using pairs of x coordinate from the
AET.

d. Increment y by 1 (to the coordinate of the next scan line).

e. For each non-vertical edge remaining in the AET, update x for the new y.
ALGORITHM
For each scan line
i. Find the intersections of the scan line with all edges of the polygon
Department of CSE, CBIT, Kolar. Page | 44 2020-21
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
ii. Sort the intersections by increasing x-coordinate
iii. Fill in all pixels between pairs of intersections
CODE
#include <iostream>
#include <GL/glut.h>
using namespace std;
float x1,x2,x3,x4,y1,y2,y3,y4;
int red=0;
int green=0;
int blue=0;
void myinit()
{
glClearColor(1,1,1,1);
glColor3f(1,0,0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,499,0,499);
}
void getVal()
{
cout<<"Enter enter point 1: ";
cin>>x1>>y1;
cout<<"Enter enter point 2: ";
cin>>x2>>y2;
cout<<"Enter enter point 3: ";
cin>>x3>>y3;
cout<<"Enter enter point 4: ";
cin>>x4>>y4;
}
void setcolor(bool r, bool g, bool b)
{
red=r;
green=g;
blue=b;
}
int sub_menu;
void color_menu(int id)
{

switch(id)
{
case 2:
setcolor(1,0,0);
break;
case 3:
setcolor(0,1,0);
break;
case 4:
setcolor(0,0,1);
break;
case 5:
setcolor(1,1,0);
break;
case 6:
setcolor(1,0,1);
break;
case 7:
Department of CSE, CBIT, Kolar. Page | 45 2020-21
COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
setcolor(0,1,1);
break;
}
glutPostRedisplay();
}
void top_menu(int id)
{
switch(id)
{
case 1:
exit(0);
break;
default:color_menu(id);
break;
}
}
void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)
{
float mx,x,temp;
int i;
if((y2-y1)<0)
{
temp=y1; y1=y2; y2=temp;
temp=x1; x1=x2; x2=temp;
}
if((y2-y1)!=0)
mx=(x2-x1)/(y2-y1);
else
mx=x2-x1;
x=x1;
for(i=y1;i<=y2;i++)
{
if(x<(float)le[i])
le[i]=(int)x;
if(x>(float)re[i])
re[i]=(int)x;
x+=mx;
}
}
void draw_pixel(int x, int y)
{
glColor3f(red,green,blue);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void scanfill(float x1,float y1,float x2,float y2,float x3,float
y3,float x4,float y4)
{
int le[500], re[500];
int i,y;
for(i=0;i<500;i++)
{
le[i]=500;
re[i]=0;
}
edgedetect(x1,y1,x2,y2,le,re);
edgedetect(x2,y2,x3,y3,le,re);

Department of CSE, CBIT, Kolar. Page | 46 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
edgedetect(x3,y3,x4,y4,le,re);
edgedetect(x4,y4,x1,y1,le,re);
for(y=0;y<=500;y++)
{
if(le[y]<=re[y])
for(i=(int)le[y];i<=(int)re[y];i++)
draw_pixel(i,y);
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(red,green,blue);
glBegin(GL_LINE_LOOP);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glVertex2f(x3,y3);
glVertex2f(x4,y4);
glEnd();
scanfill(x1,y1,x2,y2,x3,y3,x4,y4);
glFlush();
}
int main(int argc, char *argv[])
{
getVal();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Scan-Line Algorithm");
glutDisplayFunc(display);
myinit();
sub_menu=glutCreateMenu(color_menu);
glutAddMenuEntry("RED",2);
glutAddMenuEntry("GREEN",3);
glutAddMenuEntry("BLUE",4);
glutAddMenuEntry("YELLOW",5);
glutAddMenuEntry("MAGENTA",6);
glutAddMenuEntry("CYAN",7);
glutCreateMenu(top_menu);
glutAddMenuEntry("QUIT",1);
glutAddSubMenu("COLOR",sub_menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}

Department of CSE, CBIT, Kolar. Page | 47 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)
OUTPUT

Department of CSE, CBIT, Kolar. Page | 48 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

Department of CSE, CBIT, Kolar. Page | 49 2020-21


COMPUTER GRAPHICS LABORATORY WITH MINI PROJECT (17/18CSL68)

SAMPLE VIVA QUESTIONS

1. What is OpenGL?
2. What are OpenGL utilities and Libraries?
3. What is the use of glut.h?
4. What is the method generation of sierpinski gasket?
5. Write the code to generate the sierpinski gasket in a 2D co-ordinate system.
6. Differentiate additive color model from subtractive color model
7. What are the two classes of primitives openGL supports?
8. What is openGL interface?
9. List out different openGL primitives, giving examples.
10. What are different openGLframes?
11. Define the following 2 dimensional transformations
1) translation 2)rotation 3)scaling 4)reflection
12. What are the basic transformations in 3D?
13. What is concatenation?
14. What are the advantages of quaternion?
15. What is projection normalization?
16. Explain with the help of opengl functions perspective and parallel viewing opengl?
17. What is gluLookAt() function?
18. What are different types of light sources support by opengl?
19. What is aliasing?
20. What are four major tasks in a pipeline implementation?
21. What is Cohen Sutherland line clipping?
22. What do you understand by clipping?
23. What is Z-buffer algorithm for removing hidden faces?
24. What are orthographic projections? When do we need them?
25. What is antialiasing? Explain different methods of minimizing its effect? What is
polygon clipping?
26. What is polygon clipping?
27. What. are windowing and clipping?
28. List the advantages of interactive Graphics.
29. What do you mean by composite transformation? How it is useful?
30. What is a projection matrix?

Department of CSE, CBIT, Kolar. Page | 50 2020-21

You might also like