Modifying while loop

We can actually start coding stuff within the while loop:

  1. We're going to set the light's properties. So, what we're going to do is just get rid of all of the lightColor code and we're going to add glUniform3f();. To that, we'll pass glGetUniformLocation(), and to this, we'll specify lightingShader.Program and we just need to specify the first aspect that we're modifying, which is light. ambient, and we're just going to put some hardcoded values in here: 0.2f, 0.2f, and 0.2f.
  2. Let's duplicate this so we've got three instances of it and make following modifications to it:
 // Set lights properties
glUniform3f( glGetUniformLocation( lightingShader.Program, "light.ambient" ), 0.2f, 0.2f, 0.2f );
glUniform3f( glGetUniformLocation( lightingShader.Program, "light.diffuse" ), 0.5f, 0.5f, 0.5f );
glUniform3f( glGetUniformLocation( lightingShader.Program, "light.specular" ), 1.0f, 1.0f, 1.0f );
  1. So now, let's set the material properties as follows: 
 // Set material properties
glUniform1f( glGetUniformLocation( lightingShader.Program, "material.shininess"), 32.0f );
  1. Now we need to actually activate our textures, and bind them. So below  glUniformMatrix4fv(); we'll add following code:
// Bind diffuse map
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, diffuseMap );
  1. And you can copy and paste this for the binding of the specular texture map:
// Bind specular map
glActiveTexture( GL_TEXTURE1 );
glBindTexture( GL_TEXTURE_2D, specularMap );

And now we are now ready to run it. You might observe the following output on your screen: 

Move around the cube; you will see that as we're moving, the lighting affects the shape in a different way because when we were looking at it head on, there wasn't much of a shine. There's a bit towards the top right; that's when we're moving. It's realistically affecting our object. As you move the light around you can see that only the metal part of it is shining:

Obviously, it depends on what sort of angle you're looking at the object from, because that's how it is in real life. So, that's it for lighting maps.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset