void PhongLightTechnique::addSpotLight(SpotLight& spotLight) { // Add light source to point light vector list m_vSpotLights.push_back(spotLight); ++m_uiSpotLightCount; // Enable shader program enable(); // Get the location for the current light uniform GLuint lightCount = (GLuint)(m_vSpotLights.size() - 1); GLuint lightIndex = lightCount + 1; std::string sLightIndex = std::to_string(lightCount); std::string sTemp = "spotLight[" + sLightIndex + "]."; std::string sShaderLocation; // Init dir light location structure SpotLightLocation spotLightLocation; memset(&spotLightLocation, 0, sizeof(SpotLightLocation)); sShaderLocation = sTemp + "lightPosition"; spotLightLocation.PositionLocation = getUniformLocation(sShaderLocation.c_str()); sShaderLocation = sTemp + "ambientLight"; spotLightLocation.AmbientColorLocation = getUniformLocation(sShaderLocation.c_str()); sShaderLocation = sTemp + "diffuseLight"; spotLightLocation.DiffuseColorLocation = getUniformLocation(sShaderLocation.c_str()); sShaderLocation = sTemp + "specularLight"; spotLightLocation.SpecularColorLocation = getUniformLocation(sShaderLocation.c_str()); sShaderLocation = sTemp + "spotLightDirection"; spotLightLocation.SpotLightDirectionLocation = getUniformLocation(sShaderLocation.c_str()); sShaderLocation = sTemp + "spotLightExponent"; spotLightLocation.SpotLightExponentLocation = getUniformLocation(sShaderLocation.c_str()); sShaderLocation = sTemp + "spotLightCutoff"; spotLightLocation.SpotLightCutoffLocation = getUniformLocation(sShaderLocation.c_str()); sShaderLocation = sTemp + "spotLightCosCutoff"; spotLightLocation.SpotLightCosCutoffLocation = getUniformLocation(sShaderLocation.c_str()); // Store spot light uniform location m_vSpotLightsLoc.push_back(spotLightLocation); // Update spot light count glUniform1i(m_uiSpotLightCountLoc, m_uiSpotLightCount); // Set light index spotLight.lightIndex = lightIndex; // Set uniform spot light setSpotLight(spotLight); }
GLLight::GLLight(const Vector3& position,const Vector3& direction) :att2(0),att1(0),att0(1) { setSpotLight(position,direction); }