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

Lecture 9

Uploaded by

sahar kamal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture 9

Uploaded by

sahar kamal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Lecture #9

Hidden Surface & Lighting


Hidden Surface
 Hidden Surface Removal is very important in 3D scenes
 Only surfaces closest to the eye should be seen and objects that are hidden by
others should be eliminated.
 The use of a depth buffer facilitates hidden surface removal.
Hidden Surface Removal

 To use depth-buffering, you need to enable it:


 glutInitDisplayMode (GLUT_DEPTH | ..);
 glEnable (GL_DEPTH_TEST);
Hidden Surface Removal

 Initialize the depth buffer and color buffer by using:

 glClear(GL_DEPTH_BUFFER_BIT |
 GL_COLOR_BUFFER_BIT);
Hidden Surface Removal

 glutInitDisplayMode (GLUT_DEPTH | ..);


 glEnable (GL_DEPTH_TEST);
 ...
 //in display function
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 draw3DObjectA();
 draw3DObjectB();
Clipping defines parts of the scene that you do not want to display.

Modeling an object about its local origin involves defining it in terms of:
1.modeling coordinates
2.eye coordinates
3.euclidean coordinates
4.modeling transformations
hat is a 'depth buffer' and what does it accumulate?

Generally - what primitive polygon is used for creating a mesh to represent a complex object?
Triangle
Rectangle
Switches to material mode to add visual effects.
Square
Circle
Once shading is enabled - what happens to glColor() calls?
They are ignored.
They enhance the shading effects.
To scale a section of a buffer.
They function as normal.
A run-time error occurs if both are used.
When do you use glFlush and glFinish?
Yes
You use glFlush to clear the screen and glFinish to draw the screen to the display.
glFlush and glFinish should be called once and only once per application. Their utility has increased
over time and is required for any OpenGL application no matter how simple (a three line demo) or
complex (a 450 - 000 AAA video game).
glShader(ProgramID);
Usually around certain operations - such as during a glReadPixel after writing - or when OpenGL
must flush or finish its currently buffered calls. Their utility has decreased over time.

What are the four types of clearable buffers?


Color - Depth - Stencil - Accumulation
Color - HDR - LTR - VAO
int start() {}
Color - Depth - Stencil - Fragment
Fragment - Vertex - Vector - Color
Lighting Principles 11

 Lighting simulates how objects reflect light


 Lighting properties
 Light’s color and position
 Material composition of object
 Global lighting parameters
 ambient light
 two sided lighting
 available in RGBA mode
Lighting Properties:

 Light comes from light sources that can be turned on/off

 Ambient lighting comes from light that is so scattered there is no way to tell its original
location

 Example: Backlighting in a room


Lighting Properties:

 The diffuse component of lighting is light that comes from one direction.
 Once it hits a surface, it is scattered equally in all directions
Lighting Properties:

 Specular light comes from a particular direction.


 It bounces off the surface in a particular direction
RGB Values for Lights

 A light source is characterized by the amount of red, green, & blue light it emits.

 Examples: If R=G=B=1.0, the light is the brightest possible white.

 If R=G=B=.5, the color is still white, but only at half intensity, so it appears gray.

 If R=G=1.0 and B=0.0, the light appears yellow.


Setting Lighting Properties

 glLightfv( light, property, value );


 light specifies which light
 multiple lights (at least 8), starting with GL_LIGHT0

 properties
 Colors for ambient, diffuse, & specular components
 position and type
 attenuation

i goes from 0 to 7
Types of Lights

 OpenGL supports two types of Lights


 Local (Point) light sources
 Infinite (Directional) light sources
 Type of light controlled by w coordinate

w 0 Infinite Light directed along x y z


w 0 Local Light positioned at x w y
w
z
w 
Light Sources (cont.)


 Light
Light color
color properties
properties

 GL_AMBIENT
GL_AMBIENT

 GL_DIFFUSE
GL_DIFFUSE

 GL_SPECULAR
GL_SPECULAR
Turning
glEnable — enableon the
or disable Lights
server-side GL capabilities glGet or glIsEnabled
GL_ALPHA_TEST
Both glEnable and glDisable take a single argument
.If enabled, do alpha testing

GL_DEPTH_TEST

If enabled, do depth comparisons and update the depth buffer.


Note that even if the depth buffer exists and the depth mask is
non-zero, the depth buffer is not updated if the depth test is
disabled.

GL_LIGHTi

GL_TEXTURE_2D

Creating the light source Two-dimensional texturing is performed for the active texture unit.
Basic Lighting
Creating Light Sources .Light sources have a number of properties, such as color, position, and direction

;)(*To specify all properties of lights is glLight


To enable and disable lighting calculation, call glEnable and glDisable with argument GL_LIGHTING. Lighting is
initially disabled. When it is enabled, light sources that are enabled contribute to the lighting calculation. Light
source i is enabled and disabled using glEnable and glDisable with argument GL_LIGHTi.

GL_DIFFUSE GL_SPECULAR GL_POSITION GL_SPOT_DIRECTION

GL_SPOT_EXPONENT GL_SPOT_CUTOFF

GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION


glLightModel set the lighting model parameters
:There are three lighting model parameters GL_LIGHT_MODEL_AMBIENT

GL_LIGHT_MODEL_COLOR_CONTROL

GL_LIGHT_MODEL_LOCAL_VIEWER

GL_LIGHT_MODEL_TWO_SIDE
3 kind of lights

Positional and Directional source

a positional light source. This kind of light emits light from a particular location
(define by the property : GL_POSITION) and emits ray in all direction.

A directional light emits light from an infinite distance. The ray emitted are all
parallel and have the same direction (defined by the property GL_POSITION).

The property GL_POSITION is an array that contains the 4 values : (x, y, z, w)


The 3 first defines the position of the light or the direction of the ray depending
of the value of w. (x, y, z)
If w is equal to 0, the light is a directional one. If
w is different to 0, the light is a positional one (in
general, we take w = 1).
glMaterial — specify material parameters for the lighting model

glMaterial takes three arguments. The first, face, specifies whether the GL_FRONT materials, the GL_BACK materials, or
both GL_FRONT_AND_BACK materials will be modified.

The second, pname, specifies which of several parameters in one or both sets will be modified.

specifies what value or values will be assigned to the specified parameter.

You might also like