OpenGL programming based on MFC Part 9 lighting

Source: Internet
Author: User

This article on the basis of the 8th article, to add the lighting effect.

Materials

OpenGL materials are description of what objects are made of. It basically specifies how much of the light they reflect and this are what we would be seeing. OpenGL lighting goes a long way towards modeling real world lighting. In the order achieve proper lighting effects in OpenGL We need to specify properties. Material properties are of the following types-diffuse and ambient properties, specular and shininess properties and Emi Ssive Properties. These are the properties this specify how a surface dissipates light.

Diffuse and ambient Properties

The diffuse and ambient reflective material properties are a type of reflective effect this is independent of the Viewpoin T. Diffuse lighting is light the from a particular direction and ambient lighting is light this is coming to all directions. A particular light source can have both a diffuse and an ambient component. These material properties describe how the material reflects diffuse and ambient light on it.

Specular and Shininess Properties

The specular and the shininess properties of the surface describe the reflective effects that are affected by the position of the viewpoint. Specular light is reflected to surface that produces the reflective of highlights in a surface. The shininess is a value this describes how focussed the reflective properties are.

Emissive Property

This is the light-an object gives from itself. A typical example of the is a light source itself.

Specifying a material property

In order to specify a material we have to use the OpenGL function-glmaterial* (). We can individually specify the material properties using this function. Another way to go about this are by color tracking. This can is achieved by enabling color tracking and specifying what parameters of the material would is affected by the GL Color command. This is a optimization feature that OpenGL provides and are useful in cases where we'll be changing only particular Erties of the material and not all of them. In this tutorial we'll use Glmaterial to specify the material properties as we are individually setting each one of them.

Choosing the material properties determine how the object would look. We'll follow the following steps in choosing the material properties-

Decide on the diffuse and ambient colors.

Decide on the shininess depending on the type of material object This is being modeled such as silver, wood etc.

Decide whether the object would is giving off any light on its own.

The above values can be obtained by mere trial and error. We'll look at the how we go about doing the when we write a.

Lighting

OpenGL has two types of lighting:global lighting or ambient lighting and individual light sources which have position and Direction. The way an object are lit depends on the material of the object, all the lights and their properties, their positions and D Irection etc. This means lighting calculations are quite expensive and are hence turned out by OpenGL by default. So we have to turn on lighting before using it. Global lighting parameters can is set using the Gllightmodel function which specify the lighting model we would be using- such as a infinite viewer or a local viewer (for specular highlights), single sided or two sided lighting and the RGBA V Alue for the ambient light. In addition to, we would be specifying the individual light sources.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.