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

Module 3

Uploaded by

Dr V N Manju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Module 3

Uploaded by

Dr V N Manju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 65

Module - 3

3.1 Clipping:
3.1.1Clipping window,
3.1.2 Normalization and Viewport transformations,
3.1.3 Clipping algorithms:
2D point clipping
2D line clipping algorithms:
Cohen-sutherland line clipping
Polygon fill area clipping:
Sutherland Hodgeman polygon clipping algorithm

18CS62 – Computer Graphics and Visualization. Dr. V 1


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Clipping,3D Geometric Transformations,
Color and Illumination Models
• Clipping: clipping window, normalization and viewport transformations, clipping
algorithms,2D point clipping, 2D line clipping algorithms: cohen-sutherland line
clipping, polygon fill area clipping: Sutherland-Hodgeman polygon clipping
algorithm only.
• 3DGeometric Transformations: 3D translation, rotation, scaling, composite 3D
transformations, other 3D transformations, affine transformations, OpenGL
geometric transformations functions.
• Color Models: Properties of light, color models, RGB and CMY color
models.
• Illumination Models: Light sources, basic illumination models-Ambient light,
diffuse reflection, specular and phong model, Corresponding openGL functions.

18CS62 – Computer Graphics and Visualization. Dr. V 2


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
The Clipping Window
• We can design our own clipping window with any shape, size, and orientation we
choose.
Viewing-Coordinate Clipping Window
• A general approach to the two-dimensional viewing transformation is to set up a
viewing-coordinate system within the world-coordinate frame

Vector V is called the two-dimensional view up vector.

18CS62 – Computer Graphics and Visualization. Dr. V 3


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Cont…
• Alternative method

Where,
T is the translation matrix,
R is the rotation matrix

(a)applying a translation matrix T to move the viewing origin to the world origin, then
(b)applying a rotation matrix R to align the axes of the two systems.

18CS62 – Computer Graphics and Visualization. Dr. V 4


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Normalization and Viewport Transformations

18CS62 – Computer Graphics and Visualization. Dr. V 5


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Example
• World Clipping
Viewport

0 1

18CS62 – Computer Graphics and Visualization. Dr. V 6


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Normalization and Viewport Transformations
• To transform the world-coordinate point into the same relative position within the
viewport, we require that

18CS62 – Computer Graphics and Visualization. Dr. V 7


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Cont…
• We could obtain the transformation from world coordinates to viewport
coordinates with the following sequence:
1.Scale the clipping window to the size of the viewport using a fixed-point
position of (xw , yw )
min min

2.Translate (xw , yw ) to (xv , yv ).


min min min min

• Solving these expressions for the viewport position (xv, yv), we have xv = sxxw +
tx, yv = syyw + ty

18CS62 – Computer Graphics and Visualization. Dr. V 8


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Cont…

Scaling: Translation:

18CS62 – Computer Graphics and Visualization. Dr. V 9


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Mapping the Clipping Window into a Normalized Square

18CS62 – Computer Graphics and Visualization. Dr. V 10


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Cont…
• The matrix for the normalization transformation is obtained by substituting −1
for xvmin and yvmin and substituting +1 for xvmax and yvmax.

18CS62 – Computer Graphics and Visualization. Dr. V 11


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Cont…
• This time, we get the transformation matrix by substituting −1 for xwmin and
ywmin and substituting +1 for xwmax and ywmax

18CS62 – Computer Graphics and Visualization. Dr. V 12


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
18CS62 – Computer Graphics and Visualization. Dr. V 13
.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Clipping Algorithms
• Any procedure that eliminates those portions of a picture that are either inside or
outside a specified region of space is referred to as a clipping algorithm or
simply clipping.
• Different objects clipping are
• Point clipping
• Line clipping (straight-line segments)
• Fill-area clipping (polygons)
• Curve clipping
• Text clipping

18CS62 – Computer Graphics and Visualization. Dr. V 14


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Two-Dimensional Point Clipping
(100,100)
xmax=100,ymax=100

P = (x, y)

xwmin ≤ x ≤ xwmax and yw min ≤ y ≤ ywmax

(50,50)
xmin=50,ymin=50

18CS62 – Computer Graphics and Visualization. Dr. V 15


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Two-Dimensional Line Clipping
(100,100)
Window: xmax=100,ymax=100
xmin=50,ymin=50, xmax=100,ymax=100;

(50,50)
xmin=50,ymin=50

18CS62 – Computer Graphics and Visualization. Dr. V 16


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Cohen-Sutherland Line Clipping
• Processing time is reduced in the Cohen-Sutherland method by performing more testsbefore proceeding to the
intersection calculations.
• Initially, every line endpoint in a picture is assigned a four-digit binary value, called a region code, and each
bit position is used to indicate whether the point is inside or outside one of the clipping-window
boundaries.

18CS62 – Computer Graphics and Visualization. Dr. V 17


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Step 1: Compute Region Code or OutCode
• every line endpoint in a picture is assigned a four-digit binary value, called a
region code
Top left Top Top right
1001 1000 1010

Left Right
0001 0000 0010

Bottom left Bottom Bottom right


0101 0100 0110 const int RIGHT = 2
const int LEFT = 1
const int TOP = 8
const int BOTTOM = 4

18CS62 – Computer Graphics and Visualization. Dr. V 18


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Compute Outcode
#define outcode int
 A region code is referred to as an “out” code any bit outcode ComputeOutCode (double x, double y)
position indicates that the spatial point is outside the {
outcode code = 0;
clipping boundary. if (y > ymax) //above the clip window
code |= TOP;
else if (y < ymin) //below the clip window
code |= BOTTOM;
if (x > xmax) //to the right of clip window
const int RIGHT = 2
code |= RIGHT;
const int LEFT = 1
else if (x < xmin) //to the left of clip window
const int TOP = 8
code |= LEFT;
const int BOTTOM = 4
return code;
}

18CS62 – Computer Graphics and Visualization. Dr. V 19


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Step 2 – Trivial Condition - Reject or Accept

if (!(outcode0 | outcode1))
//logical or is 0 Trivially accept & exit
{
accept = true;
done = true;
}
else if (outcode0 & outcode1)
//logical and is not 0. Trivially reject and exit
done = true;

18CS62 – Computer Graphics and Visualization. Dr. V 20


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Step 3- Intersection Points – Top & Bottom

18CS62 – Computer Graphics and Visualization. Dr. V 21


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Step 3- Intersection Points – Top & Bottom
outcodeOut = outcode0? outcode0: outcode1;

if (outcodeOut & TOP)


{
y = ymax;
x = x0 + (y - y0)*(x1 - x0) /( y1 - y0);
}
else if (outcodeOut & BOTTOM)
{
y = ymin;
x = x0 + (y - y0)*(x1 - x0) /( y1 - y0);
}

18CS62 – Computer Graphics and Visualization. Dr. V 22


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Intersection Points – Right & Left

else if (outcodeOut & RIGHT)


{
x = xmax;
y = y0 + (x - x0)* (y1 - y0) /(x1 - x0);
}
else
{
x = xmin;
y = y0 + (x - x0)* (y1 - y0) /(x1 - x0);
}

18CS62 – Computer Graphics and Visualization. Dr. V 23


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
When Done=TRUE

if (outcodeOut == outcode0)
{
x0 = x;
y0 = y;
outcode0 = ComputeOutCode (x0, y0);
}
else
{
x1 = x;
y1 = y;
outcode1 = ComputeOutCode (x1, y1);
}

18CS62 – Computer Graphics and Visualization. Dr. V 24


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Polygon Clipping Algorithm

18CS62 – Computer Graphics and Visualization. Dr. V 25


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Sutherland-Hodgman Polygon Clipping
• An efficient method for clipping a convex-polygon fill area, developed by
Sutherland and Hodgman
• Send the polygon vertices through each clipping stage so that a single clipped
vertex can be immediately passed to the next stage.

18CS62 – Computer Graphics and Visualization. Dr. V 26


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Polygon Fill-Area Clipping

18CS62 – Computer Graphics and Visualization. Dr. V 27


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Sutherland--Hodgman Polygon Clipping
CASE : 1 CASE : 2 CASE : 3 CASE : 4

18CS62 – Computer Graphics and Visualization. Dr. V 28


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
The selection of vertex edge of intersection for each
clipper
1. If the first input vertex is outside this clipping-window
border and the second vertex is inside, both the CASE RULE OUTPUT

intersection point of the polygon edge with the window CASE 1 OUT->IN V1’,V2
border and the second vertex are sent to the next clipper.
CASE 2 IN->IN V2
2. If both input vertices are inside this clipping-window
border, only the second vertex is sent to the next clipper. CASE 3 IN->OUT V1’

CASE 4 OUT->OUT NONE


3. If the first vertex is inside this clipping-window border
and the second vertex is outside, only the polygon edge-
intersection position with the clipping-window border is
sent to the next clipper.
4. If both input vertices are outside this clipping-window
border, no vertices are sent to the next clipper.

18CS62 – Computer Graphics and Visualization. Dr. V 29


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Problem

18CS62 – Computer Graphics and Visualization. Dr. V 30


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
CASE RULE OUTPUT

2’ 2’ CASE 1 OUT->IN V1’,V2

CASE 2 IN->IN V2
3’ 2” 1’
CASE 3 IN->OUT V1’

CASE 4 OUT->OUT NONE

18CS62 – Computer Graphics and Visualization. Dr. V 31


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Disadvantage
• When a concave polygon is clipped with the Sutherland-Hodgman algorithm,
extraneous lines may be displayed
• Solution:
1.Split a concave polygon into two or more convex polygons and process each
convex polygon separately using the Sutherland- Hodgman algorithm
2.Modify the Sutherland- Hodgman method so that the final vertex list is
checked for multiple intersection points along any clipping-window
boundary.
*. If we find more than two vertex positions - separate the list of vertices into
two or more lists
3.Use a more general polygon clipper that has been designed to process concave
polygons correctly
18CS62 – Computer Graphics and Visualization. Dr. V 32
.N. Manju, Dept. of CSE, CMRIT, Bangalore.
18CS62 – Computer Graphics and Visualization. Dr. V 33
.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Three-Dimensional Geometric
Transformations
• Methods for geometric transformations in three dimensions are extended from two
dimensional methods by including considerations for the z coordinate.
• A three-dimensional position, expressed in homogeneous coordinates, is
represented as a four-element column vector

18CS62 – Computer Graphics and Visualization. Dr. V 34


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Three-Dimensional Translation
• A position P = (x, y, z) in three-dimensional space is translated to a location P’=
(x’, y’, z’) by adding translation distances tx, ty, and tz to the Cartesian coordinates
of P:

18CS62 – Computer Graphics and Visualization. Dr. V 35


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Three-Dimensional Rotation
• By convention, positive rotation angles produce counterclockwise rotations about
a coordinate axis.
• Positive rotations about a coordinate axis are counterclockwise, when looking
along the positive half of the axis toward the origin.

18CS62 – Computer Graphics and Visualization. Dr. V 36


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Three-Dimensional Coordinate-Axis
Rotations
• Along z axis:

18CS62 – Computer Graphics and Visualization. Dr. V 37


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Rotation
• x→ y→ z→ x

Along y axis
Along z axis Along x axis

18CS62 – Computer Graphics and Visualization. Dr. V 38


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
General Three-Dimensional Rotations
1. Translate the object so that the rotation axis
coincides with the parallel coordinate axis.
2. Perform the specified rotation about that axis.
3. Translate the object so that the rotation axis is
moved back to its original position

18CS62 – Computer Graphics and Visualization. Dr. V 39


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Rotated about an axis that is not parallel to
one of the coordinate axes - Important
1. Translate the object so that the rotation
axis passes through the coordinate origin.
2. Rotate the object so that the axis of
rotation coincides with one of the
coordinate axes.
3. Perform the specified rotation about the
selected coordinate axis.
4. Apply inverse rotations to bring the
rotation axis back to its original
orientation.
5. Apply the inverse translation to bring the
rotation axis back to its original spatial
position.

18CS62 – Computer Graphics and Visualization. Dr. V 40


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Three-Dimensional Scaling

18CS62 – Computer Graphics and Visualization. Dr. V 41


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Scaling transformation with respect to any
selected fixed position (xf , yf , zf )

18CS62 – Computer Graphics and Visualization. Dr. V 42


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Three-Dimensional Reflections

18CS62 – Computer Graphics and Visualization. Dr. V 43


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Three-Dimensional Shears

18CS62 – Computer Graphics and Visualization. Dr. V 44


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Affine Transformations
• A coordinate transform of the form

• Affine transformations (in two dimensions, three dimensions, or higher


dimensions) have the general properties that parallel lines are transformed into
parallel lines, and finite points map to finite points.
• Translation, rotation, scaling, reflection and shear are examples of affine
transformations

18CS62 – Computer Graphics and Visualization. Dr. V 45


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
3.3 Illumination and Color
• 3.3.1 Illumination models
• 3.3.2 Light sources,
• 3.3.3 Basic illumination models-Ambient light, diffuse reflection, specular and
phong model,
• 3.3.4 Corresponding openGL functions.
• 3.3.5 Properties of light,
• 3.3.6 Color models, RGB and CMY color models.

18CS62 – Computer Graphics and Visualization. Dr. V 46


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
3.3.2 Light Sources
• Point Light Sources

18CS62 – Computer Graphics and Visualization. Dr. V 47


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
• Infinitely Distant Light Sources

18CS62 – Computer Graphics and Visualization. Dr. V 48


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
• Radial Intensity Attenuation
light source travels outwards through space

18CS62 – Computer Graphics and Visualization. Dr. V 49


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Directional Light Sources and Spotlight
Effects
• A local light source can be modified easily to produce a directional, or spotlight,
beam of light.

Vobj ·Vlight = cos α


If Vobj ·Vlight < cos θl , however, the object is outside the light cone.

18CS62 – Computer Graphics and Visualization. Dr. V 50


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Basic Illumination Models

18CS62 – Computer Graphics and Visualization. Dr. V 51


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Illumination Model

18CS62 – Computer Graphics and Visualization. Dr. V 52


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
18CS62 – Computer Graphics and Visualization. Dr. V 53
.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Lighting in OpenGL

18CS62 – Computer Graphics and Visualization. Dr. V 54


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
OpenGL Illumination Functions

OpenGL Point Light-Source Function


glLight* (lightName, lightProperty, propertyValue);

 A suffix code of i or f is appended to the function name, depending on the data type of the property value
 lightName: GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, . . . , GL_LIGHT7
 lightProperty: must be assigned one of the OpenGL symbolic property constants

glEnable (lightName);à turn on that light with the command


glEnable (GL_LIGHTING);à activate the OpenGL lighting routines

18CS62 – Computer Graphics and Visualization. Dr. V 55


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
void light(GLfloat a,GLfloat b, GLfloat c)
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}

18CS62 – Computer Graphics and Visualization. Dr. V 56


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Specifying an OpenGL Light-Source
position and Type
GL_POSITION:
 specifies light-source position

 this symbolic constant is used to set two light-source properties at the same time: the light-source
position and the light-source type
Example:
GLfloat light1PosType [ ] = {2.0, 0.0, 3.0, 1.0};
GLfloat light2PosType [ ] = {0.0, 1.0, 0.0, 0.0};

glLightfv (GL_LIGHT1, GL_POSITION, light1PosType); glEnable (GL_LIGHT1);

glLightfv (GL_LIGHT2, GL_POSITION, light2PosType); glEnable (GL_LIGHT2);

18CS62 – Computer Graphics and Visualization. Dr. V 57


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
void light(GLfloat a,GLfloat b, GLfloat c)
{
GLfloat lightint[]={0.7f,0.7f,0.7f,1.0f};
GLfloat lightpos[]={2.0f,6.0f,3.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
glLightfv(GL_LIGHT0,GL_SHININESS,lightint);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}

18CS62 – Computer Graphics and Visualization. Dr. V 58


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Specifying OpenGL Light-Source
Colors
 Unlike an actual light source, an OpenGL light has three different color properties the
symboliccolor-propertyconstantsGL_AMBIENT,GL_DIFFUSE,and GL_SPECULAR
Example:
GLfloat blackColor [ ] = {0.0, 0.0, 0.0, 1.0};
GLfloat whiteColor [ ] = {1.0, 1.0, 1.0, 1.0};
glLightfv (GL_LIGHT3, GL_AMBIENT, blackColor);
glLightfv (GL_LIGHT3, GL_DIFFUSE, whiteColor);
glLightfv (GL_LIGHT3, GL_SPECULAR, whiteColor);

18CS62 – Computer Graphics and Visualization. Dr. V 59


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
void light(GLfloat a,GLfloat b, GLfloat c)
{
GLfloat mat_ambient[]={a,b,c,1.0f};
GLfloat mat_diffuse[]={a,b,c,1.0f};
GLfloat mat_specular[]={a,b,c,0.0f};
GLfloat mat_shininess[]={10.0f};
glShadeModel(GL_SMOOTH);
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);
GLfloat lightint[]={0.7f,0.7f,0.7f,1.0f};
GLfloat lightpos[]={2.0f,6.0f,3.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
glLightfv(GL_LIGHT0,GL_SHININESS,lightint);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}

18CS62 – Computer Graphics and Visualization. Dr. V 60


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Specifying Radial-Intensity
Attenuation Coefficients
 For an OpenGL Light Source we could assign the radial-attenuation coefficient values as
 glLightf (GL_LIGHT6, GL_CONSTANT_ATTENUATION, 1.5);

glLightf (GL_LIGHT6, GL_LINEAR_ATTENUATION, 0.75);


glLightf (GL_LIGHT6, GL_QUADRATIC_ATTENUATION, 0.4);

18CS62 – Computer Graphics and Visualization. Dr. V 61


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
void light(GLfloat a,GLfloat b, GLfloat c)
{
GLfloat mat_ambient[]={a,b,c,1.0f};
GLfloat mat_diffuse[]={a,b,c,1.0f};
GLfloat mat_specular[]={a,b,c,0.0f};
GLfloat mat_shininess[]={10.0f};
glShadeModel(GL_SMOOTH);
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);
GLfloat lightint[]={0.7f,0.7f,0.7f,1.0f};
GLfloat lightpos[]={2.0f,6.0f,3.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
glLightfv(GL_LIGHT0,GL_SHININESS,lightint);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}

18CS62 – Computer Graphics and Visualization. Dr. V 62


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
OpenGL Directional Light Sources
(Spotlights)
è Thereare three OpenGL propertyconstants for directional effects:
GL_SPOT_DIRECTION, GL_SPOT_CUTOFF, and GL_SPOT_EXPONENT

GLfloat dirVector [ ] = {1.0, 0.0, 0.0};

glLightfv (GL_LIGHT3, GL_SPOT_DIRECTION, dirVector);


glLightf (GL_LIGHT3, GL_SPOT_CUTOFF, 30.0);
glLightf (GL_LIGHT3, GL_SPOT_EXPONENT, 2.5);

18CS62 – Computer Graphics and Visualization. Dr. V 63


.N. Manju, Dept. of CSE, CMRIT, Bangalore.
OpenGL Global Lighting Parameters
glLightModel* (paramName, paramValue);
 We append a suffix code of i or f, depending on the data type of the parameter value.
 In addition, for vector data, we append the suffix code v.

 Parameter paramName is assigned an OpenGL symbolic constant that identifies the global property to be set,
and parameter paramValue is assigned a single value or set of values.
globalAmbient [ ] = {0.0, 0.0, 0.3, 1.0);
glLightModelfv (GL_LIGHT_MODEL_AMBIENT, globalAmbient);

glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

 turn off this default and use the actual viewing position (which is the viewing-coordinate origin) to calculate
V
18CS62 – Computer Graphics and Visualization. Dr. V 64
.N. Manju, Dept. of CSE, CMRIT, Bangalore.
Texture

 patterns are combined only with the nonspecular color, and then the two colors are combined.
 We select this two-color option with

glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);

18CS62 – Computer Graphics and Visualization. Dr. V 65


.N. Manju, Dept. of CSE, CMRIT, Bangalore.

You might also like