Interactive Shading

In this project, you will implement an interactive system for shading of a 3D object.

1 Assign normal vectors

In OpenGL, you need to specify a normal vector to each vertex of a face (polygon). For example, the following statements indicate that the vertex (1,1,1) is assigned with a normal vector (1,0,0).

glNormal3f(1, 0, 0);

glVertex3f(1, 1, 1);

If a face consists of 4 vertices, then there are 4 pairs of glNormal3f() and glVertex3f().

Strictly speaking, a normal vector of a vertex (that is a point) is not well-defined. In other words, we

may have different ways to assign a normal vector to a vertex v. A simple way is to assign the normal

vector of the face that v belongs to as v’s normal vector. Note that the normal vector of the face is

uniquely determined by any three vertices as long as these vertices are not in the same line. Therefore,

the same vertex can be assigned by different normal vectors because it may belong to multiple faces.

The above simple way can be used to assign normal vectors in flat shading. But for Gouraud shading,

you will need to average multiple normal vectors “inherited” from intersecting polygons to compute the

final normal vector of a vertex.

2 Create light sources

In OpenGL, you can create a light source with a specific property, such as position, color and direction

by a function called glLightfv() or glLightf(), as follows:

void glLightfv(GLenum light, GLenum pname, const TYPE *param);

void glLightf(GLenum light, GLenum pname, TYPE param);

glLightfv() has three function parameters. The first one indicates the identity of a light source, which

can be one of the values from GL LIGHT0 to GL LIGHT7. The second one indicates the name of a

property, which can be one of the following values





There are some other properties, such as GL SPOT EXPONENT, GL CONSTANT ATTENUATION,

etc. But we will only consider the properties of position, color and direction, in this project. The

third parameter indicates the values of a specific property of the light source. Note that the values of a

property of position, color or direction are usually reprsented as a vector, and thus we use the function

glLightfv(). For example, the following statement specifies the position of LIGHT0 to be (1.0, 1.0, 1.0,

1.0) (homogenous form).

GLfloat light_position = {1.0, 1.0, 1.0, 1.0};

void glLightfv(GL_LIGHT0, GL_POSITION, light_position);

In this project, you will create 2 light sources. One is initially located in (1.0, 0.0, 0.0, 1.0) and the

other is initially located in (-1.0, 0.0, 0.0, 1.0).

After a light source is created, you will need to enable the light source by glEnable(), such as the




3 Shading

In the class, we have learned three shading models: flat, Gouraud, and phong. With the flat model, the

colors of points in the same face are identical. So, it is common that the flat model is not good at retaining

3D strucutre of an object. With the Gouraud model, the colors of points in a face are interpolated by the

colors of the vertex of the face. Recall that the colors of different vertices of a face are usually different

even if they are assigned with the same normal vector. Therefore, the colors of points in a face are


OpenGL provides implementation of the flat and Gouraud shading. In OpenGL, you can specify a

shading model by the following function:

void glShadeModel(GLenum mode);

where mode can be GL FLAT or GL SMOOTH. GL SMOOTH implies the Gouraud shading model.

Kemahiran: Pengaturcaraan C, Pengaturcaraan C++, Linux, OpenGL

Lihat lagi: interactive timeline flash, as3 map interactive, interactive flash rom menu, fragment shader book, shader simulator, shader math, universe shader, fragment shader examples, shader code, shader tester, shader playground, interactive project download, interactive sofa wall color, adult interactive webcam sites, interactive pie chart maker, interactive widget, best interactive presentation, website java html add interactive map, metatrader interactive brokers api, create interactive projects

Tentang Majikan:
( 3 ulasan ) COLUMBUS, United States

ID Projek: #19213904

Dianugerahkan kepada:


Hi, I'd like to help with OpenGL programming. I write clean and commented code explaining each step.

$35 USD dalam sehari
(309 Ulasan)

5 pekerja bebas membida secara purata $51 untuk pekerjaan ini


Hi, I am full stack developer and have experience of C/OpenGL programming. I have done job as same as your requirement before. I checked your requirement. I'm sure that I can easily do this project. I will do my be Lagi

$111 USD dalam 3 hari
(19 Ulasan)

Hi, Hope you are doing well! Thanks for sharing your project requirement with us. It will be our great pleasure to work on your project. I have checked your requirement, yes we can do it, because we already wor Lagi

$66 USD dalam sehari
(5 Ulasan)

Do your school assignments on your own young boy! You will learn a lot. It's a simple assignment and there are tons of material out there to help you.

$10 USD dalam sehari
(1 Ulasan)

"Hi, Hope you are doing well! Thanks for sharing your project requirement with us. It will be our great pleasure to work on your project. I have checked your requirement, yes we can do it, because we already work on si Lagi

$34 USD dalam 7 hari
(1 Ulasan)