programs in folder learnOpenGL2_p2B

version 'D3Q: 0.40'; author: 'Drikus Kleefsman'; date: june 2020.

This project has the translation of a number of C++ programs found in Part 2 (chapters 12 - 18) of the offline book that can be down loaded from

In the programs we will use the KeyInput, the Mouse and the Shader class that were also used at the end of Part 1. Our programs start with a number of includes of these classes. Also at the end of the programs we have akways similar code, used for the KeyInput and Mouse.

Chapter 14


The translation poses no problems. We added two functions at the end for the setting of uniforms, one for setting 3d-vectors and the other for setting matrices.

We use Materials and Lights for the calculation of the color output. In the fragment shader fs_materials we find:

struct Material {
    vec3 ambient;
    vec3 diffuse;
    vec3 specular;    
    float shininess;

struct Light {
    vec3 position;

    vec3 ambient;
    vec3 diffuse;
    vec3 specular;

So, we use structs in our shader. In the program we set elements of the struct element by element e.g. lightingShader.setFloat3(gl, "light.ambient", 0.2, 0.2, 0.2);

After calculating diff = max((N.L), 0.0) and spec = (max((V.R), 0.0)^material.shininess; the resulting FragColor is found using:

ambient = light.ambient * material.ambient;
diffuse = light.diffuse * (diff * material.diffuse);
specular = light.specular * (spec * material.specular);
FragColor = ambient + diffuse + specular;

This is Phong shading. In Part 5, chapter 33 the Blinn-Phong shading is treated. It uses a different formula for the specular component.

Chapter 15


The translation poses no problems. The two used textures are normal PNG RGBA files.