Download presentation
Presentation is loading. Please wait.
1
Computer Graphics 5Practical Lesson
Let there be light Computer Graphics 5Practical Lesson Lighting part 2
2
Defining Light Source To use lighting in OpenGL we first must enable lighting with the command glEnable(GL_LIGHTING) In OpenGL we can define up to 8 light sources. We can enable each light source seperatly by using the command glEnable(GL_LIGHT<0..7>) . We can disable with the command glDisable.
3
Light Source There are 3 types of effects of light source:
Diffuse – this is the color of the light , affects objects the objects that are on direct line from the light source Ambient – light that affects the entire scene, and not only object that have direct line to him. Specular – makes the object “shine” – return light to camera. Also requires object to be set as specular
4
Light source color We can set the color of light using the parameter diffuse: glLightfv(GL_LIGHT1,GL_DIFFUSE,light_color); Where light color is a vector of 3 floats
5
Light Example 3 In this example we see 2 robots.
Using the mouse, The user can rotate the robots. There 2 light sources, one on each side. The lights are rotating with the robots, creating fixed color.
6
Light Example 3(cont’) By clicking ‘f’, the lights are set to fixed position, and this changes the color of the robots by their position. Like in light example 2, user can switch between flat and smooth shading by clicking ‘s’.
7
Coloring Objects To allow coloring of objects:
glEnable(GL_COLOR_MATERIAL). If this option is not set, then the light of objects comes only from the light sources. If its enables the color is effected by both the light source and color of object.
8
Objects Specular To make objects specular, both light source and object must have specular property set. In light example 1 in light sources 1 and 2 are creating specular effect. The commands are: glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glLightfv(GL_LIGHT1,GL_SPECULAR,mat_specular2); The third parameter is vector represent color, the 4th member defines if its single source or “surrounding” light.
9
Normal's and lighting By Default OpenGL calculates the normal for each triangle. In OpenGL we can set normal for each triangle ourselves by using the command glNormal() before entering the vertices of the triangle. For every polygon, can also set normal for each vertex separately.
10
Normal's and lighting(cont)
Normal’s direction determine the effect of lighting. If the normal is not in the direction of the light source, the light source won’t affect the object. If the normal's of the points are not on the same direction, OpenGL makes interpolation, which can create illusions.
11
Loading BMP files In the site, I added the class BMPLoader.cpp
It will allow you loading BMP files. With this class, you can load bmp images and access the cells directly. BMPClass bmp; BMPLoad(file_name,bmp);
12
Using BMPLoader.cpp This class properties are initialized with all the needed information to use the image. We will the information for assignment 2 and for textures.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.