Initialise Shaders, Light and View Positions

main.cpp

setLightPosition()

Add initLightPosition() after initShader()

GLuint initShader(std::string pathVert, std::string pathFrag) 
{
    ...
}

void setLightPosition(glm::vec3 lightPos)
{
    GLuint lightpos_loc = glGetUniformLocation(shader.program, "lightPos" );
    glUniform3fv(lightpos_loc, 1, glm::value_ptr(lightPos));
}

void setViewPosition(glm::vec3 eyePos)
{
    GLuint viewpos_loc = glGetUniformLocation(shader.program, "viewPos" );
    glUniform3fv(viewpos_loc, 1, glm::value_ptr(eyePos));
}

As you are using glm::value_ptr(), you need to add its header file in the headers list.

Initialise shaders in main()

in main(), comment out the original initShader() call.

Add initialisation of Phong and Blinn-Phong shader variables after loading GLAD.

As the light position uniform needs to be set for each shader, setLightPosition() is called after the initialisation of each shader.

Last updated