Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics 4Practical Lesson

Similar presentations


Presentation on theme: "Computer Graphics 4Practical Lesson"— Presentation transcript:

1 Computer Graphics 4Practical Lesson
Let there be light Computer Graphics 4Practical Lesson Lighting

2 Lighting purpose In openGL we can work without light definition – its how we worked until this session. In this mode object’s color is defined only by its drawing color. Its harder to understand object’s geometry without lighting.

3 Light Example 1 Keyboard key l turns on and off the lights.
Keyboard key d turns on and off depth test. The keys 1,2,3 allow turn on and of 3 light sources. Without lights, it looks like a simple 2d white circle. When we use lights definitions, we can see it’s a sphere.

4 Depth Test When depth test is on, in the addition to the color buffer, there is depth buffer. This buffer stores for every pixel ( not vertex ) what its distance from the camera. When a new pixel is drawn in color buffer , its distance to the camera is checked.

5 Depth Test(cont’) If its closer than current drawn point, it will be displayed and frame buffer will be updated. When there is no depth test, every pixel is drawn, so the last drawn polygon will erase previous polygons.

6 Depth Test In Light Example 1
In this version of OpenGL, the sphere is drawn from the front to the back. So if the depth test is cancelled, what we will see is the back of the sphere. In another version of OpenGL the results can be different.

7 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.

8 Light Source in Lights Example
If lights are cancelled, the sphere and the triangle will be shown in their original color white. We can disable or enable each light source separately with the keys 1,2,3

9 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

10 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

11 Light source angle In OpenGL we can control the angle of the light source. We can do it with the parameter GL_SPOT_CUTOFF. glLightf(GL_LIGHT2, GL_SPOT_CUTOFF ,90 );

12 Ambient Light Source Light source can be ambient – the light effects the entire scene. Not just the polygon in front of the light. In example light 1 – we can see that the little triangle on the top is not affected by light 0 and 1. Light 2 also doesn’t reach him. Light 2 only affects him as ambient light.

13 Color smoothness OpenGL allows giving the scene a more “smooth” appearance. It can calculate the color of each pixel of polygons on the scene and give the object a more “smooth” look. We turn smoothness on and off by: glShadeModel(GL_SMOOTH); glShadeModel(GL_FLAT);

14 Color smoothness The color is determined by the normal of the surface at the point. The normal is interpolation of normal of polygon points. We can make the object appear as round, although its built from surfaces.

15 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);

16 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.


Download ppt "Computer Graphics 4Practical Lesson"

Similar presentations


Ads by Google